From f712643885ec2bbf377e1de2cbc898523e056802 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Sat, 13 Feb 2010 15:11:41 +0100 Subject: [PATCH] Place scrollbars correctly for positive inset Make sure that the scrollbar stretches to the top of the window even if the text inset is > 0 (and similarly for the horizontal scrollbar). This applies to the Core Text and ATSUI renderers only. --- src/MacVim/MMAtsuiTextView.m | 35 +++++++++++++++++++++++++++++------ src/MacVim/MMCoreTextView.m | 31 +++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m index fca5011f..8b396ed9 100644 --- a/src/MacVim/MMAtsuiTextView.m +++ b/src/MacVim/MMAtsuiTextView.m @@ -207,30 +207,53 @@ defaultLineHeightForFont(NSFont *font) - (NSRect)rectForRowsInRange:(NSRange)range { - NSRect rect = { 0, 0, 0, 0 }; + // Compute rect whose vertical dimensions cover the rows in the given + // range. + // NOTE: The rect should be in _flipped_ coordinates and the first row must + // include the top inset as well. (This method is only used to place the + // scrollbars inside MMVimView.) + + NSRect rect = { {0, 0}, {0, 0} }; unsigned start = range.location > maxRows ? maxRows : range.location; unsigned length = range.length; if (start + length > maxRows) length = maxRows - start; - rect.origin.y = cellSize.height * start + insetSize.height; - rect.size.height = cellSize.height * length; + if (start > 0) { + rect.origin.y = cellSize.height * start + insetSize.height; + rect.size.height = cellSize.height * length; + } else { + // Include top inset + rect.origin.y = 0; + rect.size.height = cellSize.height * length + insetSize.height; + } return rect; } - (NSRect)rectForColumnsInRange:(NSRange)range { - NSRect rect = { 0, 0, 0, 0 }; + // Compute rect whose horizontal dimensions cover the columns in the given + // range. + // NOTE: The first column must include the left inset. (This method is + // only used to place the scrollbars inside MMVimView.) + + NSRect rect = { {0, 0}, {0, 0} }; unsigned start = range.location > maxColumns ? maxColumns : range.location; unsigned length = range.length; if (start+length > maxColumns) length = maxColumns - start; - rect.origin.x = cellSize.width * start + insetSize.width; - rect.size.width = cellSize.width * length; + if (start > 0) { + rect.origin.x = cellSize.width * start + insetSize.width; + rect.size.width = cellSize.width * length; + } else { + // Include left inset + rect.origin.x = 0; + rect.size.width = cellSize.width * length + insetSize.width; + } return rect; } diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index 1cb5e345..2c16ae6e 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -229,6 +229,12 @@ defaultAdvanceForFont(CTFontRef fontRef) - (NSRect)rectForRowsInRange:(NSRange)range { + // Compute rect whose vertical dimensions cover the rows in the given + // range. + // NOTE: The rect should be in _flipped_ coordinates and the first row must + // include the top inset as well. (This method is only used to place the + // scrollbars inside MMVimView.) + NSRect rect = { {0, 0}, {0, 0} }; unsigned start = range.location > maxRows ? maxRows : range.location; unsigned length = range.length; @@ -236,14 +242,25 @@ defaultAdvanceForFont(CTFontRef fontRef) if (start + length > maxRows) length = maxRows - start; - rect.origin.y = cellSize.height * start + insetSize.height; - rect.size.height = cellSize.height * length; + if (start > 0) { + rect.origin.y = cellSize.height * start + insetSize.height; + rect.size.height = cellSize.height * length; + } else { + // Include top inset + rect.origin.y = 0; + rect.size.height = cellSize.height * length + insetSize.height; + } return rect; } - (NSRect)rectForColumnsInRange:(NSRange)range { + // Compute rect whose horizontal dimensions cover the columns in the given + // range. + // NOTE: The first column must include the left inset. (This method is + // only used to place the scrollbars inside MMVimView.) + NSRect rect = { {0, 0}, {0, 0} }; unsigned start = range.location > maxColumns ? maxColumns : range.location; unsigned length = range.length; @@ -251,8 +268,14 @@ defaultAdvanceForFont(CTFontRef fontRef) if (start+length > maxColumns) length = maxColumns - start; - rect.origin.x = cellSize.width * start + insetSize.width; - rect.size.width = cellSize.width * length; + if (start > 0) { + rect.origin.x = cellSize.width * start + insetSize.width; + rect.size.width = cellSize.width * length; + } else { + // Include left inset + rect.origin.x = 0; + rect.size.width = cellSize.width * length + insetSize.width; + } return rect; } -- 2.11.4.GIT