pass 'maxLength' value to TextScroll function so that we can prevent scrolling past the bottom of the file (unless we want to od so by centtering the screen)
This commit is contained in:
@@ -29,7 +29,8 @@ struct
|
||||
|
||||
val cursorLine = LineGap.idxToLineNumber (cursorIdx, buffer)
|
||||
val startLine =
|
||||
TextScroll.getStartLine (prevLineNumber, cursorLine, windowHeight)
|
||||
TextScroll.getStartLine
|
||||
(prevLineNumber, cursorLine, windowHeight, #lineLength buffer)
|
||||
|
||||
(* move buffer to new startLine as required by TextBuilder.build *)
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
|
||||
@@ -74,7 +74,8 @@ struct
|
||||
(buffer, bufferIdx, windowWidth, prevScrollColumn)
|
||||
|
||||
val bufferLine =
|
||||
TextScroll.getStartLine (prevLineNumber, bufferLine, windowHeight)
|
||||
TextScroll.getStartLine
|
||||
(prevLineNumber, bufferLine, windowHeight, #lineLength buffer)
|
||||
val buffer = LineGap.goToLine (bufferLine, buffer)
|
||||
|
||||
val drawMsg = NormalModeTextBuilder.build
|
||||
@@ -129,6 +130,11 @@ struct
|
||||
|
||||
val buffer = LineGap.goToIdx (lineIdx, buffer)
|
||||
val endOfLineIdx = Cursor.viDlr (buffer, lineIdx, 1)
|
||||
val endOfLineIdx =
|
||||
if endOfLineIdx >= #textLength buffer - 2 then
|
||||
Int.max (0, #textLength buffer - 2)
|
||||
else
|
||||
endOfLineIdx
|
||||
|
||||
val cursorIdx = Int.min (endOfLineIdx, lineIdx + column)
|
||||
|
||||
@@ -141,7 +147,11 @@ struct
|
||||
|
||||
val startLine =
|
||||
TextScroll.getStartLine
|
||||
(prevLineNumber, newCursorLineNumber, windowHeight)
|
||||
( prevLineNumber
|
||||
, newCursorLineNumber
|
||||
, windowHeight
|
||||
, #lineLength buffer
|
||||
)
|
||||
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
|
||||
@@ -223,7 +233,7 @@ struct
|
||||
val newCursorLineNumber = cursorLineNumber + count
|
||||
val newCursorLineNumber =
|
||||
if cursorLineNumber >= #lineLength buffer - 2 then
|
||||
Int.max (0, #lineLength buffer - 2)
|
||||
Int.max (0, #lineLength buffer - 1)
|
||||
else
|
||||
newCursorLineNumber
|
||||
in
|
||||
@@ -270,7 +280,8 @@ struct
|
||||
|
||||
val cursorLine = LineGap.idxToLineNumber (cursorIdx, buffer)
|
||||
val startLine =
|
||||
TextScroll.getStartLine (prevLineNumber, cursorLine, windowHeight)
|
||||
TextScroll.getStartLine
|
||||
(prevLineNumber, cursorLine, windowHeight, #lineLength buffer)
|
||||
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
|
||||
@@ -331,7 +342,8 @@ struct
|
||||
|
||||
val cursorLine = LineGap.idxToLineNumber (cursorIdx, buffer)
|
||||
val startLine =
|
||||
TextScroll.getStartLine (prevLineNumber, cursorLine, windowHeight)
|
||||
TextScroll.getStartLine
|
||||
(prevLineNumber, cursorLine, windowHeight, #lineLength buffer)
|
||||
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
|
||||
|
||||
@@ -52,7 +52,8 @@ struct
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
val cursorLine = LineGap.idxToLineNumber (cursorIdx, buffer)
|
||||
val startLine =
|
||||
TextScroll.getStartLine (prevLineNumber, cursorLine, windowHeight)
|
||||
TextScroll.getStartLine
|
||||
(prevLineNumber, cursorLine, windowHeight, #lineLength buffer)
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
|
||||
val remainingWindowHeight = windowHeight - (TextConstants.ySpace * 2)
|
||||
@@ -122,7 +123,8 @@ struct
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
val cursorLine = LineGap.idxToLineNumber (cursorIdx, buffer)
|
||||
val startLine =
|
||||
TextScroll.getStartLine (prevLineNumber, cursorLine, newWindowHeight)
|
||||
TextScroll.getStartLine
|
||||
(prevLineNumber, cursorLine, newWindowHeight, #lineLength buffer)
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
|
||||
val remainingWindowHeight = newWindowHeight - (TextConstants.ySpace * 2)
|
||||
|
||||
@@ -37,7 +37,7 @@ struct
|
||||
fun getScrollColumnFromString (cursorIdx, windowWidth, prevScrollColumn) =
|
||||
calculateScrollColumn (0, cursorIdx, windowWidth, prevScrollColumn)
|
||||
|
||||
fun getStartLine (prevLineNumber, cursorLine, windowHeight) =
|
||||
fun getStartLine (prevLineNumber, cursorLine, windowHeight, totalLines) =
|
||||
if cursorLine <= (prevLineNumber + 3) then
|
||||
(* cursorLine is prior to or same as prevLineNumber,
|
||||
* so use cursorLine to calculate the start line we want. *)
|
||||
@@ -50,7 +50,10 @@ struct
|
||||
if cursorLine > prevLineNumber + (howManyLinesWeCanFit - 3) then
|
||||
(* cursorLine is after the visible part of the screen
|
||||
* so return the mimimum line where cursorLine is visible *)
|
||||
cursorLine - howManyLinesWeCanFit + 3
|
||||
if cursorLine >= totalLines - 3 then
|
||||
Int.max (totalLines - howManyLinesWeCanFit, 0)
|
||||
else
|
||||
cursorLine - howManyLinesWeCanFit + 3
|
||||
else
|
||||
prevLineNumber
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user