public override void PostParse(Document document, DocumentModification modification) { if (modification.HasFlag(DocumentModificationFlags.ProgrammaticTextParse)) { if (g.Config.bAutoCollapse) { document.Outlining.RootNode.CollapseDescendants("CodeRegion"); } } }
private void editorResolved_DocumentTextChanging(object sender, DocumentModificationEventArgs e) { if (e.IsProgrammaticTextReplacement || ModifyingEditorText) { return; } HasUnsavedChanges = true; DocumentModification docMod = e.Modification; int startLineIndex = docMod.StartLineIndex; if (docMod.LinesDelta == 0) // User modified some text on a single line. { // This gets handled in DocumentTextChanged. return; } if (string.IsNullOrEmpty(docMod.DeletedText)) { return; } // Handle deleted text here. // If the changed text was all on one line: // - Set the right hand line to the new text. // - Set the right hand line to UserChange. // - Set the left line to UserChange. // If the text was on multiple lines: // - Determine how many lines were removed (numLinesChanged). // - Removed numLinesChanged from the right hand side. // - Add the new text in as a UserChange. // - Add in any needed virtual lines on the right. int numLinesChanged = docMod.LinesDeleted; DocumentLine oldStartLine = editorResolved.Document.Lines[startLineIndex]; int endLineIndex = docMod.DeletionEndLineIndex; DocumentLine oldEndLine = editorResolved.Document.Lines[endLineIndex]; string newLineText = oldStartLine.Text.Substring(0, docMod.StartOffset - oldStartLine.StartOffset) + oldEndLine.Text.Substring(docMod.DeletionEndOffset - oldEndLine.StartOffset); for (int i = 0; i < numLinesChanged + 1; i++) { CurrentDiffInfo.RightLines.RemoveAt(startLineIndex); } for (int i = 0; i < numLinesChanged; i++) { CurrentDiffInfo.RightLines.Insert(startLineIndex, new DiffLine("", ChangeType.User, true)); } CurrentDiffInfo.RightLines.Insert(startLineIndex, new DiffLine(newLineText, ChangeType.User)); }
private void Document_PreTextChanging(object sender, DocumentModificationEventArgs e) { if (e.IsProgrammaticTextReplacement || ModifyingEditorText) { return; } DocumentModification docMod = e.Modification; if (CurrentDiffInfo != null && CurrentDiffInfo.RightLines[docMod.StartLineIndex].IsVirtual) { e.Cancel = true; } }
public override void PostParse(Document document, DocumentModification modification) { if (modification.HasFlag(DocumentModificationFlags.ProgrammaticTextParse)) { if (g.Config.bAutoCollapse) document.Outlining.RootNode.CollapseDescendants("CodeRegion"); } }
void editorResolved_DocumentTextChanged(object sender, DocumentModificationEventArgs e) { if (e.IsProgrammaticTextReplacement || ModifyingEditorText) { return; } if (e.Cancel) { return; } DocumentModification docMod = e.Modification; // Handled added text. // If the text was on one line. // - Set the right hand line to the new text. // - Set the right hand line to UserChange. // - Set the left line to UserChange. // If the text was on multiple lines // - Determine how many lines changed (numLinesChanged) // - Add the text of the changed lines to the right hand side. // - Set these lines to UserChange. // - Add any needed virtual lines to the left. int newCaretOffset = docMod.StartOffset; int startLineIndex = docMod.StartLineIndex; if (docMod.LinesDelta == 0) { CurrentDiffInfo.RightLines[startLineIndex].Text = editorResolved.Document.Lines[startLineIndex].Text; CurrentDiffInfo.RightLines[startLineIndex].Change = ChangeType.User; newCaretOffset = docMod.LengthDelta > 0 ? docMod.InsertionEndOffset : Math.Max(0, docMod.DeletionEndOffset - 1); } else if (string.IsNullOrEmpty(docMod.InsertedText) == false) { int numLinesChanged = docMod.LinesInserted; // Remove the original start line CurrentDiffInfo.RightLines.RemoveAt(startLineIndex); // Recreate it and add new lines from editor for (int i = 0; i < numLinesChanged + 1; i++) { string lineText = editorResolved.Document.Lines[startLineIndex + i].Text; CurrentDiffInfo.RightLines.Insert(startLineIndex + i, new DiffLine(lineText, ChangeType.User)); } // Add the virtual lines to the left side. for (int i = 0; i < numLinesChanged; i++) { CurrentDiffInfo.LeftLines.Insert(docMod.InsertionEndLineIndex, new DiffLine("", ChangeType.User, true)); } newCaretOffset = docMod.InsertionEndOffset; } CurrentDiffInfo.CleanUp(); FillEditors(); editorResolved.Caret.Offset = newCaretOffset; editorOriginal.SelectedView.FirstVisibleX = editorResolved.SelectedView.FirstVisibleX; editorOriginal.SelectedView.FirstVisibleDisplayLineIndex = editorResolved.SelectedView.FirstVisibleDisplayLineIndex; }