protected override int?GetLineNumber(ITextViewLine viewLine, ref LineNumberState state) { if (owner == null) { return(null); } CustomLineNumberState customState; if (state == null) { state = customState = new CustomLineNumberState(); } else { customState = (CustomLineNumberState)state; } if (state.SnapshotLine == null || state.SnapshotLine.EndIncludingLineBreak != viewLine.Start) { state.SnapshotLine = viewLine.Start.GetContainingLine(); } else { state.SnapshotLine = state.SnapshotLine.Snapshot.GetLineFromLineNumber(state.SnapshotLine.LineNumber + 1); } return(owner.GetLineNumber(viewLine, state.SnapshotLine, ref customState.State)); }
Line CreateLine(ITextViewLine viewLine, LineNumberState lineNumberState, int lineNumber) { var lineNumberString = GetLineNumberString(lineNumber); var lineNumberSource = new LineNumberSource(lineNumberString, GetLineNumberTextFormattingRunProperties(viewLine, lineNumberState, lineNumber)); var textLine = textFormatter !.FormatLine(lineNumberSource, 0, 0, defaultTextParagraphProperties, null); return(new Line(lineNumber, textLine, lineNumberTextRight, viewLine.TextTop + viewLine.Baseline - textLine.TextBaseline)); }
void UpdateLines(IList <ITextViewLine> newOrReformattedLines, IList <ITextViewLine> translatedLines) { if (wpfTextViewHost.IsClosed) { return; } var textViewLines = wpfTextViewHost.TextView.TextViewLines; if (textViewLines == null) { return; } foreach (var viewLine in newOrReformattedLines) { if (identityTagToLine.TryGetValue(viewLine.IdentityTag, out var line)) { identityTagToLine.Remove(viewLine.IdentityTag); line.Dispose(); } } foreach (var viewLine in translatedLines) { if (identityTagToLine.TryGetValue(viewLine.IdentityTag, out var line)) { identityTagToLine.Remove(viewLine.IdentityTag); line.Dispose(); } } var newDict = new Dictionary <object, Line>(); LineNumberState lineNumberState = null; foreach (var viewLine in textViewLines) { var lineNumber = GetLineNumber(viewLine, ref lineNumberState); if (lineNumber == null) { continue; } if (!identityTagToLine.TryGetValue(viewLine.IdentityTag, out var line) || line.Number != lineNumber) { line = CreateLine(viewLine, lineNumberState, lineNumber.Value); } else { identityTagToLine.Remove(viewLine.IdentityTag); } newDict[viewLine.IdentityTag] = line; } foreach (var line in identityTagToLine.Values) { line.Dispose(); } identityTagToLine = newDict; textLayer.UpdateLines(identityTagToLine.Values.ToArray()); }
protected override int? GetLineNumber(ITextViewLine viewLine, ref LineNumberState state) { if (!viewLine.IsFirstTextViewLineForSnapshotLine) return null; if (state == null) state = new LineNumberState(); if (state.SnapshotLine == null || state.SnapshotLine.EndIncludingLineBreak != viewLine.Start) state.SnapshotLine = viewLine.Start.GetContainingLine(); else state.SnapshotLine = state.SnapshotLine.Snapshot.GetLineFromLineNumber(state.SnapshotLine.LineNumber + 1); return state.SnapshotLine.LineNumber + 1; }
protected override int? GetLineNumber(ITextViewLine viewLine, ref LineNumberState state) { if (owner == null) return null; CustomLineNumberState customState; if (state == null) state = customState = new CustomLineNumberState(); else customState = (CustomLineNumberState)state; if (state.SnapshotLine == null || state.SnapshotLine.EndIncludingLineBreak != viewLine.Start) state.SnapshotLine = viewLine.Start.GetContainingLine(); else state.SnapshotLine = state.SnapshotLine.Snapshot.GetLineFromLineNumber(state.SnapshotLine.LineNumber + 1); return owner.GetLineNumber(viewLine, state.SnapshotLine, ref customState.State); }
protected override int?GetLineNumber(ITextViewLine viewLine, ref LineNumberState state) { if (!viewLine.IsFirstTextViewLineForSnapshotLine) { return(null); } if (state == null) { state = new LineNumberState(); } if (state.SnapshotLine == null || state.SnapshotLine.EndIncludingLineBreak != viewLine.Start) { state.SnapshotLine = viewLine.Start.GetContainingLine(); } else { state.SnapshotLine = state.SnapshotLine.Snapshot.GetLineFromLineNumber(state.SnapshotLine.LineNumber + 1); } return(state.SnapshotLine.LineNumber + 1); }
protected override TextFormattingRunProperties GetLineNumberTextFormattingRunProperties(ITextViewLine viewLine, LineNumberState state, int lineNumber) { Debug.Assert(owner != null); Debug.Assert(state != null); if (owner == null) throw new InvalidOperationException(); var customState = (CustomLineNumberState)state; return owner.GetLineNumberTextFormattingRunProperties(viewLine, customState.SnapshotLine, lineNumber, customState.State); }
protected abstract TextFormattingRunProperties GetLineNumberTextFormattingRunProperties(ITextViewLine viewLine, LineNumberState state, int lineNumber);
Line CreateLine(ITextViewLine viewLine, LineNumberState lineNumberState, int lineNumber) { var lineNumberString = GetLineNumberString(lineNumber); var lineNumberSource = new LineNumberSource(lineNumberString, GetLineNumberTextFormattingRunProperties(viewLine, lineNumberState, lineNumber)); var textLine = textFormatter.FormatLine(lineNumberSource, 0, 0, defaultTextParagraphProperties, null); return new Line(lineNumber, textLine, lineNumberTextRight, viewLine.TextTop + viewLine.Baseline - textLine.TextBaseline); }
protected abstract int? GetLineNumber(ITextViewLine viewLine, ref LineNumberState state);
protected override TextFormattingRunProperties GetLineNumberTextFormattingRunProperties(ITextViewLine viewLine, LineNumberState state, int lineNumber) { Debug.Assert(owner != null); Debug.Assert(state != null); if (owner == null) { throw new InvalidOperationException(); } var customState = (CustomLineNumberState)state; return(owner.GetLineNumberTextFormattingRunProperties(viewLine, customState.SnapshotLine, lineNumber, customState.State)); }
protected abstract int?GetLineNumber(ITextViewLine viewLine, ref LineNumberState state);
protected override TextFormattingRunProperties GetLineNumberTextFormattingRunProperties(ITextViewLine viewLine, LineNumberState state, int lineNumber) => lineNumberTextFormattingRunProperties;