private void mnuAccept_Click(object sender, EventArgs e) { // Remove all lines associated with strikethrough int startOffset = syntaxEditorExternal.Document.Lines[OrigianlLineSpan.StartLine].StartOffset; int endOffset = syntaxEditorExternal.Document.Lines[OrigianlLineSpan.EndLine].EndOffset; int originalStartLine = OrigianlLineSpan.StartLine; int originalEndLine = OrigianlLineSpan.EndLine; SpanIndicator[] spans = syntaxEditorExternal.Document.SpanIndicatorLayers.GetIndicatorsForTextRange(new TextRange(startOffset, endOffset), false); int numLinesDeleted = 0; foreach (SpanIndicator span in spans) { var ss = (HighlightingStyleSpanIndicator)span; int firstLineToDelete = syntaxEditorExternal.Views[0].OffsetToPosition(ss.TextRange.StartOffset).Line; int lastLineToDelete = syntaxEditorExternal.Views[0].OffsetToPosition(ss.TextRange.EndOffset).Line; for (int i = lastLineToDelete; i >= firstLineToDelete; i--) { syntaxEditorExternal.Document.Lines.RemoveAt(i); numLinesDeleted++; } } OrigianlLineSpan = null; DeselectLines(originalStartLine, originalEndLine - numLinesDeleted + 1); }
private void syntaxEditor1_DocumentTextChanged(object sender, DocumentModificationEventArgs e) { // Colour lines correctly when new lines inserted or existing lines deleted if (e.Modification.LinesInserted + e.Modification.LinesDeleted > 0) { int lineNum = e.Modification.StartLineIndex; // -1; if (e.Modification.LinesInserted > 0 && syntaxEditorExternal.Document.Lines[lineNum].BackColor == Color.Red && syntaxEditorExternal.Document.Lines[lineNum + 1].BackColor != Color.Red) { DeselectLines(); } if (e.Modification.LinesDeleted > 0 && OrigianlLineSpan != null) { if (OrigianlLineSpan.EndLine - OrigianlLineSpan.StartLine > 0) { OrigianlLineSpan.EndLine -= 1; } if (OrigianlLineSpan.EndLine == OrigianlLineSpan.StartLine) { DeselectLines(OrigianlLineSpan.StartLine, OrigianlLineSpan.EndLine); OrigianlLineSpan = null; } if (lineNum + 1 < syntaxEditorExternal.Document.Lines.Count && (syntaxEditorExternal.Document.Lines[lineNum].BackColor == Color.White && syntaxEditorExternal.Document.Lines[lineNum + 1].BackColor == Color.Red)) { DeselectLines(); } } } }
/// <summary> /// Determines whether the location is part of a special region, and highlights the special region /// if it is. /// </summary> /// <param name="lineNumber"></param> private void SelectLines(int lineNumber) { DeselectLines(); int spanStartLine = lineNumber; int spanEndLine = lineNumber; Color selectedColor = syntaxEditorExternal.Document.Lines[lineNumber].BackColor; bool newColourFound = false; for (int i = lineNumber; i >= 0; i--) { if (syntaxEditorExternal.Document.Lines[i].BackColor != selectedColor) // && //syntaxEditor1.Document.Lines[i].BackColor.ToArgb() != 0) { newColourFound = true; break; } spanStartLine = i; } if (!newColourFound && spanStartLine != 0) { spanStartLine = lineNumber; } newColourFound = false; for (int i = lineNumber; i < syntaxEditorExternal.Document.Lines.Count; i++) { if (syntaxEditorExternal.Document.Lines[i].BackColor != selectedColor) // && //syntaxEditor1.Document.Lines[i].BackColor.ToArgb() != 0) { newColourFound = true; break; } spanEndLine = i; } if (!newColourFound) { spanEndLine = lineNumber; } for (int i = spanStartLine; i <= spanEndLine; i++) { int startOffset = syntaxEditorExternal.Document.Lines[i].StartOffset; int endOffset = syntaxEditorExternal.Document.Lines[i].EndOffset; SpanIndicator[] spans = syntaxEditorExternal.Document.SpanIndicatorLayers.GetIndicatorsForTextRange(new TextRange(startOffset, endOffset), false); if (spans.Length > 0) { ((HighlightingStyleSpanIndicator)spans[0]).HighlightingStyle.BackColor = Color.Red; } syntaxEditorExternal.Document.Lines[i].BackColor = Color.Red; } OrigianlLineSpan = new Slyce.IntelliMerge.SlyceMerge.LineSpan(spanStartLine, spanEndLine); //, selectedColor); }
private void mnuDelete_Click(object sender, EventArgs e) { // Remove all lines associated with strikethrough int startOffset = syntaxEditorExternal.Document.Lines[OrigianlLineSpan.StartLine].StartOffset; int endOffset = syntaxEditorExternal.Document.Lines[OrigianlLineSpan.EndLine].EndOffset; SpanIndicator[] spans = syntaxEditorExternal.Document.SpanIndicatorLayers.GetIndicatorsForTextRange(new TextRange(startOffset, endOffset), false); var linesToKeep = new List <int>(); foreach (SpanIndicator span in spans) { var ss = (HighlightingStyleSpanIndicator)span; int firstLineToKeep = syntaxEditorExternal.Views[0].OffsetToPosition(ss.TextRange.StartOffset).Line; int lastLineToKeep = syntaxEditorExternal.Views[0].OffsetToPosition(ss.TextRange.EndOffset).Line; for (int line = firstLineToKeep; line <= lastLineToKeep; line++) { linesToKeep.Add(line); } } linesToKeep.Sort(); // Remove any remaining lines before the first strikethrough int originalStartLine = OrigianlLineSpan.StartLine; int originalEndLine = OrigianlLineSpan.EndLine; int numLinesRemoved = 0; for (int i = originalEndLine; i >= originalStartLine; i--) { if (linesToKeep.BinarySearch(i) < 0) { syntaxEditorExternal.Document.Lines.RemoveAt(i); numLinesRemoved++; } } // Remove strikethrough from all spans in the block for (int spanCounter = spans.Length - 1; spanCounter >= 0; spanCounter--) { SpanIndicator span = spans[spanCounter]; span.Layer.Remove(span); } OrigianlLineSpan = null; DeselectLines(originalStartLine, originalEndLine - numLinesRemoved); }
/// <summary> /// Removes highlighting of special regions. /// </summary> private void DeselectLines(int startLine, int endLine) { Color color = Color.White; for (int i = startLine; i <= endLine; i++) { if (i >= syntaxEditorExternal.Document.Lines.Count) { break; } int startOffset = syntaxEditorExternal.Document.Lines[i].StartOffset; int endOffset = syntaxEditorExternal.Document.Lines[i].EndOffset; SpanIndicator[] spans = syntaxEditorExternal.Document.SpanIndicatorLayers.GetIndicatorsForTextRange(new TextRange(startOffset, endOffset), false); if (spans.Length > 0) { ((HighlightingStyleSpanIndicator)spans[0]).HighlightingStyle.BackColor = color; } syntaxEditorExternal.Document.Lines[i].BackColor = color; } OrigianlLineSpan = null; }