private void UpdateDiffDimensions(DiffViewModel diffViewModel, HunkRangeInfo hunkRangeInfo) { if (TextView.IsClosed) { return; } var startLineNumber = hunkRangeInfo.NewHunkRange.StartingLineNumber; var endLineNumber = startLineNumber + hunkRangeInfo.NewHunkRange.NumberOfLines - 1; var snapshot = TextView.TextBuffer.CurrentSnapshot; if (startLineNumber < 0 || startLineNumber >= snapshot.LineCount || endLineNumber < 0 || endLineNumber >= snapshot.LineCount) { return; } var startLine = snapshot.GetLineFromLineNumber(startLineNumber); var endLine = snapshot.GetLineFromLineNumber(endLineNumber); if (startLine == null || endLine == null) { return; } var mapTop = _scrollBar.Map.GetCoordinateAtBufferPosition(startLine.Start) - 0.5; var mapBottom = _scrollBar.Map.GetCoordinateAtBufferPosition(endLine.End) + 0.5; diffViewModel.Top = Math.Round(_scrollBar.GetYCoordinateOfScrollMapPosition(mapTop)) - 2.0; diffViewModel.Height = Math.Round(_scrollBar.GetYCoordinateOfScrollMapPosition(mapBottom)) - diffViewModel.Top + 2.0; }
/// <summary> /// Get top and bottom of a line for the scrollbar. /// </summary> /// <param name="line">A line of text from an <see cref="ITextSnapshot"/>.</param> /// <param name="top">Top coordinate for the scrollbar.</param> /// <param name="bottom">Bottom coordinate for the scrollbar.</param> /// <exception cref="ArgumentException">The supplied <see cref="ITextSnapshotLine"/> is on an incorrect snapshot.</exception> private void MapLineToPixels(ITextSnapshotLine line, out double top, out double bottom) { double mapTop = _scrollBar.Map.GetCoordinateAtBufferPosition(line.Start) - 0.5; double mapBottom = _scrollBar.Map.GetCoordinateAtBufferPosition(line.End) + 0.5; top = Math.Round(_scrollBar.GetYCoordinateOfScrollMapPosition(mapTop)) - 2.0; bottom = Math.Round(_scrollBar.GetYCoordinateOfScrollMapPosition(mapBottom)) + 2.0; }