public LineTransform GetLineTransform(ITextViewLine line, double yPosition, Microsoft.VisualStudio.Text.Editor.ViewRelativePosition placement) { string lineText = line.Extent.GetText().Trim(); if (lineText == "{" || lineText == "}" || lineText == "};") { return(new LineTransform(BraceLineScale)); } else { return(line.DefaultLineTransform); } }
public override VSTF.LineTransform GetLineTransform(HexViewLine line, double yPosition, VSTE.ViewRelativePosition placement) { var transform = removeExtraTextLineVerticalPixels ? new VSTF.LineTransform(0, 0, line.DefaultLineTransform.VerticalScale, line.DefaultLineTransform.Right) : line.DefaultLineTransform; foreach (var source in lineTransformSources) { transform = VSTF.LineTransform.Combine(transform, source.GetLineTransform(line, yPosition, placement)); } return(transform); }
/// <summary> /// Calculates the line transform for a given line of formatted text /// </summary> /// <param name="line">Line</param> /// <param name="yPosition">Y position</param> /// <param name="placement">Placement</param> /// <returns></returns> public abstract VSTF.LineTransform GetLineTransform(HexViewLine line, double yPosition, VSTE.ViewRelativePosition placement);
/// <summary> /// Displays a line in the view /// </summary> /// <param name="bufferPosition">Position</param> /// <param name="verticalDistance">Distance relative to the top or bottom of the view</param> /// <param name="relativeTo">The <see cref="VSTE.ViewRelativePosition"/></param> /// <param name="viewportWidthOverride">Overrides viewport width</param> /// <param name="viewportHeightOverride">Overrides viewport height</param> /// <param name="options">Options</param> public abstract void DisplayHexLineContainingBufferPosition(HexBufferPoint bufferPosition, double verticalDistance, VSTE.ViewRelativePosition relativeTo, double?viewportWidthOverride, double?viewportHeightOverride, DisplayHexLineOptions options);
/// <summary> /// Displays a line in the view /// </summary> /// <param name="bufferPosition">Position</param> /// <param name="verticalDistance">Distance relative to the top or bottom of the view</param> /// <param name="relativeTo">The <see cref="VSTE.ViewRelativePosition"/></param> /// <param name="viewportWidthOverride">Overrides viewport width</param> /// <param name="viewportHeightOverride">Overrides viewport height</param> public void DisplayHexLineContainingBufferPosition(HexBufferPoint bufferPosition, double verticalDistance, VSTE.ViewRelativePosition relativeTo, double?viewportWidthOverride, double?viewportHeightOverride) => DisplayHexLineContainingBufferPosition(bufferPosition, verticalDistance, relativeTo, viewportWidthOverride, viewportHeightOverride, DisplayHexLineOptions.None);
/// <summary> /// Displays a line in the view /// </summary> /// <param name="bufferPosition">Position</param> /// <param name="verticalDistance">Distance relative to the top or bottom of the view</param> /// <param name="relativeTo">The <see cref="VSTE.ViewRelativePosition"/></param> public void DisplayHexLineContainingBufferPosition(HexBufferPoint bufferPosition, double verticalDistance, VSTE.ViewRelativePosition relativeTo) => DisplayHexLineContainingBufferPosition(bufferPosition, verticalDistance, relativeTo, null, null, DisplayHexLineOptions.None);
HexFormattedLine AddLineTransform(HexFormattedLine line, double yPosition, VSTE.ViewRelativePosition placement) { if (line != null) { var lineTransform = lineTransformProvider.GetLineTransform(line, yPosition, placement); if (lineTransform != line.LineTransform) { line.SetLineTransform(lineTransform); line.SetChange(VSTF.TextViewLineChange.NewOrReformatted); } } return(line); }
List <LineInfo> CreateLineInfos(HexBufferPoint bufferPosition, VSTE.ViewRelativePosition relativeTo, double verticalDistance, double viewportHeightOverride) { var lineInfos = new List <LineInfo>(); var startLine = GetLine(bufferPosition); double newViewportBottom = NewViewportTop + viewportHeightOverride; double lineStartY; if (relativeTo == VSTE.ViewRelativePosition.Top) { lineStartY = NewViewportTop + verticalDistance; AddLineTransform(startLine, lineStartY, VSTE.ViewRelativePosition.Top); } else { Debug.Assert(relativeTo == VSTE.ViewRelativePosition.Bottom); lineStartY = NewViewportTop + viewportHeightOverride - verticalDistance; AddLineTransform(startLine, lineStartY, VSTE.ViewRelativePosition.Bottom); lineStartY -= startLine.Height; } var currentLine = startLine; double y = lineStartY; if (y + currentLine.Height > NewViewportTop) { for (;;) { lineInfos.Add(new LineInfo(currentLine, y)); if (y <= NewViewportTop) { break; } currentLine = AddLineTransform(GetLineBefore(currentLine), y, VSTE.ViewRelativePosition.Bottom); if (currentLine == null) { break; } y -= currentLine.Height; } lineInfos.Reverse(); } currentLine = startLine; for (y = lineStartY + currentLine.Height; y < newViewportBottom;) { currentLine = AddLineTransform(GetLineAfter(currentLine), y, VSTE.ViewRelativePosition.Top); if (currentLine == null) { break; } lineInfos.Add(new LineInfo(currentLine, y)); y += currentLine.Height; } Debug.Assert(new HashSet <WpfHexViewLine>(lineInfos.Select(a => a.Line)).Count == lineInfos.Count); // At least one line must be included if (lineInfos.Count == 0) { lineInfos.Add(new LineInfo(startLine, NewViewportTop)); } // Make sure that at least one line is shown var last = lineInfos[lineInfos.Count - 1]; if (last.Y + last.Line.Height <= NewViewportTop) { NewViewportTop = last.Y; } var first = lineInfos[0]; if (first.Y >= newViewportBottom) { NewViewportTop = first.Y; } return(lineInfos); }
public void LayoutLines(HexBufferPoint bufferPosition, VSTE.ViewRelativePosition relativeTo, double verticalDistance, double viewportLeft, double viewportWidthOverride, double viewportHeightOverride) { NewViewportTop = requestedViewportTop; var infos = CreateLineInfos(bufferPosition, relativeTo, verticalDistance, viewportHeightOverride); // The first line of the file must always be shown at the top of the view if (infos[0].Y > NewViewportTop) { infos = CreateLineInfos(bufferLines.BufferSpan.Start, VSTE.ViewRelativePosition.Top, 0, viewportHeightOverride); Debug.Assert(infos[0].Y == NewViewportTop); } // Include a hidden line before the first line and one after the last line, // just like in VS' WpfHexViewLine collection. var firstInfo = infos[0]; var prevLine = AddLineTransform(GetLineBefore(firstInfo.Line), firstInfo.Y, VSTE.ViewRelativePosition.Bottom); if (prevLine != null) { infos.Insert(0, new LineInfo(prevLine, firstInfo.Y - prevLine.Height)); } var lastInfo = infos[infos.Count - 1]; var nextLine = AddLineTransform(GetLineAfter(lastInfo.Line), lastInfo.Y + lastInfo.Line.Height, VSTE.ViewRelativePosition.Top); if (nextLine != null) { infos.Add(new LineInfo(nextLine, lastInfo.Y + lastInfo.Line.Height)); } var keptLines = new HashSet <PhysicalLine>(); foreach (var info in infos) { keptLines.Add(toPhysicalLine[info.Line]); } foreach (var physLine in toPhysicalLine.Values) { if (!keptLines.Contains(physLine)) { physLine.Dispose(); } } var newTop = GetNewViewportTop(infos, NewViewportTop); var delta = -NewViewportTop + newTop; NewViewportTop = newTop; var visibleLines = new HashSet <WpfHexViewLine>(); var visibleArea = new Rect(viewportLeft, NewViewportTop, viewportWidthOverride, viewportHeightOverride); NewOrReformattedLines = new List <WpfHexViewLine>(); TranslatedLines = new List <WpfHexViewLine>(); AllVisibleLines = new List <WpfHexViewLine>(); foreach (var info in infos) { var line = info.Line; visibleLines.Add(line); AllVisibleLines.Add(line); double newLineTop = delta + info.Y; if (!oldVisibleLines.Contains(line)) { line.SetChange(VSTF.TextViewLineChange.NewOrReformatted); line.SetDeltaY(0); } else { var deltaY = newLineTop - line.Top; line.SetDeltaY(deltaY); // If it got a new line transform, it will have Change == NewOrReformatted, // and that change has priority over Translated. if (deltaY != 0 && line.Change == VSTF.TextViewLineChange.None) { line.SetChange(VSTF.TextViewLineChange.Translated); } } line.SetTop(newLineTop); line.SetVisibleArea(visibleArea); if (line.Change == VSTF.TextViewLineChange.Translated) { TranslatedLines.Add(line); } else if (line.Change == VSTF.TextViewLineChange.NewOrReformatted) { NewOrReformattedLines.Add(line); } } bool foundVisibleLine = false; foreach (var info in infos) { if (visibleLines.Contains(info.Line)) { foundVisibleLine = true; continue; } info.Line.SetChange(VSTF.TextViewLineChange.None); info.Line.SetDeltaY(0); info.Line.SetTop(foundVisibleLine ? double.PositiveInfinity : double.NegativeInfinity); info.Line.SetVisibleArea(visibleArea); } Debug.Assert(NewOrReformattedLines.Count + TranslatedLines.Count <= AllVisibleLines.Count); Debug.Assert(AllVisibleLines.Count >= 1); if (AllVisibleLines.Count == 0) { throw new InvalidOperationException(); } AllVisiblePhysicalLines = new List <PhysicalLine>(keptLines); }
void VSTE.ITextView.DisplayTextLineContainingBufferPosition(VST.SnapshotPoint bufferPosition, double verticalDistance, VSTE.ViewRelativePosition relativeTo, double?viewportWidthOverride, double?viewportHeightOverride) { throw new NotImplementedException(); }