implement smoother horizontal scrolling. If the new column is already visible without changing the previous scroll column, then don't change. If the new scroll column is prior to the old, then scroll backwards; else, scroll forwards.
This commit is contained in:
@@ -12,12 +12,13 @@ struct
|
|||||||
fun buildTextAndClear
|
fun buildTextAndClear
|
||||||
(app: app_type, buffer, cursorIdx, searchList, msgs, bufferModifyTime) =
|
(app: app_type, buffer, cursorIdx, searchList, msgs, bufferModifyTime) =
|
||||||
let
|
let
|
||||||
val {windowWidth, windowHeight, startLine, searchString, ...} = app
|
val {windowWidth, windowHeight, startLine, searchString,
|
||||||
|
visualScrollColumn = prevScrollColumn, ...} = app
|
||||||
|
|
||||||
(* calculate scroll column *)
|
(* calculate scroll column *)
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val visualScrollColumn =
|
val visualScrollColumn =
|
||||||
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth)
|
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn)
|
||||||
|
|
||||||
(* move LineGap to first line displayed on screen *)
|
(* move LineGap to first line displayed on screen *)
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
@@ -86,12 +87,13 @@ struct
|
|||||||
, searchList
|
, searchList
|
||||||
, searchString
|
, searchString
|
||||||
, bufferModifyTime
|
, bufferModifyTime
|
||||||
|
, visualScrollColumn = prevScrollColumn
|
||||||
, ...
|
, ...
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
val newBuffer = LineGap.goToIdx (cursorIdx, buffer)
|
val newBuffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val visualScrollColumn =
|
val visualScrollColumn =
|
||||||
TextScroll.getScrollColumn (buffer, cursorIdx, newWidth)
|
TextScroll.getScrollColumn (buffer, cursorIdx, newWidth, prevScrollColumn)
|
||||||
val newBuffer = LineGap.goToLine (startLine, newBuffer)
|
val newBuffer = LineGap.goToLine (startLine, newBuffer)
|
||||||
val lineIdx = TextBuilderUtils.getLineAbsIdxFromBuffer (startLine, buffer)
|
val lineIdx = TextBuilderUtils.getLineAbsIdxFromBuffer (startLine, buffer)
|
||||||
|
|
||||||
@@ -130,11 +132,12 @@ struct
|
|||||||
(app: app_type, buffer, cursorIdx, searchList, initialMsg, bufferModifyTime) :
|
(app: app_type, buffer, cursorIdx, searchList, initialMsg, bufferModifyTime) :
|
||||||
AppType.app_type =
|
AppType.app_type =
|
||||||
let
|
let
|
||||||
val {windowWidth, windowHeight, startLine, searchString, ...} = app
|
val {windowWidth, windowHeight, startLine, searchString, visualScrollColumn
|
||||||
|
= prevScrollColumn, ...} = app
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val visualScrollColumn =
|
val visualScrollColumn =
|
||||||
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth)
|
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn)
|
||||||
|
|
||||||
(* move LineGap to first line displayed on screen *)
|
(* move LineGap to first line displayed on screen *)
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ struct
|
|||||||
, searchList
|
, searchList
|
||||||
, searchString
|
, searchString
|
||||||
, bufferModifyTime
|
, bufferModifyTime
|
||||||
|
, visualScrollColumn = prevScrollColumn
|
||||||
, ...
|
, ...
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (bufferIdx, buffer)
|
val buffer = LineGap.goToIdx (bufferIdx, buffer)
|
||||||
val visualScrollColumn =
|
val visualScrollColumn =
|
||||||
TextScroll.getScrollColumn (buffer, bufferIdx, windowWidth)
|
TextScroll.getScrollColumn (buffer, bufferIdx, windowWidth, prevScrollColumn)
|
||||||
val bufferLine =
|
val bufferLine =
|
||||||
let
|
let
|
||||||
val maxHeight = windowHeight - TextConstants.ySpace
|
val maxHeight = windowHeight - TextConstants.ySpace
|
||||||
@@ -124,6 +125,7 @@ struct
|
|||||||
, searchList
|
, searchList
|
||||||
, searchString
|
, searchString
|
||||||
, bufferModifyTime
|
, bufferModifyTime
|
||||||
|
, visualScrollColumn = prevScrollColumn
|
||||||
, ...
|
, ...
|
||||||
} = app
|
} = app
|
||||||
val buffer = LineGap.goToLine (reqLine, buffer)
|
val buffer = LineGap.goToLine (reqLine, buffer)
|
||||||
@@ -133,7 +135,7 @@ struct
|
|||||||
|
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val visualScrollColumn =
|
val visualScrollColumn =
|
||||||
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth)
|
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn)
|
||||||
val startLine = TextWindow.getStartLineWithCursorCentered
|
val startLine = TextWindow.getStartLineWithCursorCentered
|
||||||
(buffer, cursorIdx, origLine, windowWidth, windowHeight div 2)
|
(buffer, cursorIdx, origLine, windowWidth, windowHeight div 2)
|
||||||
|
|
||||||
@@ -179,7 +181,7 @@ struct
|
|||||||
, searchList
|
, searchList
|
||||||
, searchString
|
, searchString
|
||||||
, bufferModifyTime
|
, bufferModifyTime
|
||||||
, visualScrollColumn
|
, visualScrollColumn = prevScrollColumn
|
||||||
, ...
|
, ...
|
||||||
} = app
|
} = app
|
||||||
|
|
||||||
@@ -193,7 +195,7 @@ struct
|
|||||||
let
|
let
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val visualScrollColumn =
|
val visualScrollColumn =
|
||||||
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth)
|
TextScroll.getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn)
|
||||||
val startLine = TextWindow.getStartLineWithCursorCentered
|
val startLine = TextWindow.getStartLineWithCursorCentered
|
||||||
(buffer, cursorIdx, startLine, windowWidth, windowHeight div 2)
|
(buffer, cursorIdx, startLine, windowWidth, windowHeight div 2)
|
||||||
|
|
||||||
|
|||||||
@@ -3,23 +3,26 @@ struct
|
|||||||
structure TC = TextConstants
|
structure TC = TextConstants
|
||||||
|
|
||||||
(* Preqreuisite: move buffer to cursorIdx *)
|
(* Preqreuisite: move buffer to cursorIdx *)
|
||||||
fun getScrollColumn (buffer, cursorIdx, windowWidth) =
|
fun getScrollColumn (buffer, cursorIdx, windowWidth, prevScrollColumn) =
|
||||||
let
|
let
|
||||||
val startOfLine = Cursor.vi0 (buffer, cursorIdx)
|
val startOfLine = Cursor.vi0 (buffer, cursorIdx)
|
||||||
val columnDifference = cursorIdx - startOfLine
|
val newColumn = cursorIdx - startOfLine
|
||||||
in
|
|
||||||
if columnDifference = 0 then
|
|
||||||
0
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val howManyColumnsCanWeFit =
|
val howManyColumnsCanWeFit =
|
||||||
if windowWidth >= TC.textLineWidth then TC.textLineCount
|
if windowWidth >= TC.textLineWidth then TC.textLineCount
|
||||||
else windowWidth div TC.xSpace
|
else windowWidth div TC.xSpace
|
||||||
val howManyColumnsCanWeFit = howManyColumnsCanWeFit - 1
|
val howManyColumnsCanWeFit = howManyColumnsCanWeFit - 1
|
||||||
in
|
in
|
||||||
if columnDifference < howManyColumnsCanWeFit then 0
|
if newColumn < prevScrollColumn then
|
||||||
else columnDifference - howManyColumnsCanWeFit
|
(* we are moving the cursor backwards
|
||||||
end
|
* so make sure that newColumn is on the left side *)
|
||||||
|
newColumn
|
||||||
|
else if newColumn > prevScrollColumn + howManyColumnsCanWeFit then
|
||||||
|
(* we are scrolling forwards *)
|
||||||
|
newColumn - howManyColumnsCanWeFit
|
||||||
|
else
|
||||||
|
(* we can display the current column without moving the scroll column
|
||||||
|
* so we do that *)
|
||||||
|
prevScrollColumn
|
||||||
end
|
end
|
||||||
|
|
||||||
fun getStartLine (prevLineNumber, cursorLine, windowHeight) =
|
fun getStartLine (prevLineNumber, cursorLine, windowHeight) =
|
||||||
|
|||||||
Reference in New Issue
Block a user