extract reusable function 'buildTextAndClear' (but need to be careful since some functions have specialised build functionality and shouldn't use this function)
This commit is contained in:
@@ -27,6 +27,31 @@ struct
|
|||||||
(newApp, drawMsg)
|
(newApp, drawMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun buildTextAndClear (app: app_type, buffer, cursorIdx) =
|
||||||
|
let
|
||||||
|
val {windowWidth, windowHeight, startLine, ...} = app
|
||||||
|
|
||||||
|
(* move LineGap to first line displayed on screen *)
|
||||||
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
|
||||||
|
(* get new startLine which may move screen depending on cursor movements *)
|
||||||
|
val startLine = TextWindow.getStartLine
|
||||||
|
(buffer, startLine, cursorIdx, windowWidth, windowHeight)
|
||||||
|
|
||||||
|
(* move buffer to new startLine as required by TextBuilder.build *)
|
||||||
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
|
||||||
|
val drawMsg =
|
||||||
|
TextBuilder.build
|
||||||
|
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||||
|
|
||||||
|
val mode = NORMAL_MODE ""
|
||||||
|
val newApp = AppWith.bufferAndCursorIdx
|
||||||
|
(app, buffer, cursorIdx, mode, startLine)
|
||||||
|
in
|
||||||
|
(newApp, drawMsg)
|
||||||
|
end
|
||||||
|
|
||||||
fun centreToCursor (app: app_type) =
|
fun centreToCursor (app: app_type) =
|
||||||
let
|
let
|
||||||
val {buffer, windowWidth, windowHeight, startLine = origLine, cursorIdx, ...} = app
|
val {buffer, windowWidth, windowHeight, startLine = origLine, cursorIdx, ...} = app
|
||||||
@@ -126,29 +151,7 @@ struct
|
|||||||
|
|
||||||
fun helpMove (app: app_type, buffer, cursorIdx, count, fMove) =
|
fun helpMove (app: app_type, buffer, cursorIdx, count, fMove) =
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
let
|
buildTextAndClear (app, buffer, cursorIdx)
|
||||||
val {windowWidth, windowHeight, startLine, ...} = app
|
|
||||||
|
|
||||||
(* move LineGap to first line displayed on screen *)
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
|
||||||
|
|
||||||
(* get new startLine which may move screen depending on cursor movements *)
|
|
||||||
val startLine = TextWindow.getStartLine
|
|
||||||
(buffer, startLine, cursorIdx, windowWidth, windowHeight)
|
|
||||||
|
|
||||||
(* move buffer to new startLine as required by TextBuilder.build *)
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
|
||||||
|
|
||||||
val drawMsg =
|
|
||||||
TextBuilder.build
|
|
||||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
|
||||||
val newApp = AppWith.bufferAndCursorIdx
|
|
||||||
(app, buffer, cursorIdx, mode, startLine)
|
|
||||||
in
|
|
||||||
(newApp, drawMsg)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
(* move LineGap to cursorIdx, which is necessary for finding newCursorIdx *)
|
||||||
let
|
let
|
||||||
@@ -219,35 +222,14 @@ struct
|
|||||||
(* move cursorIdx to first character on line *)
|
(* move cursorIdx to first character on line *)
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val cursorIdx = Cursor.firstNonSpaceChr (buffer, cursorIdx)
|
val cursorIdx = Cursor.firstNonSpaceChr (buffer, cursorIdx)
|
||||||
|
|
||||||
(* move LineGap to first line displayed on screen, and build new text *)
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
|
||||||
val drawMsg = TextBuilder.build
|
|
||||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
||||||
|
|
||||||
val mode = NORMAL_MODE ""
|
|
||||||
val newApp = AppWith.bufferAndCursorIdx
|
|
||||||
(app, buffer, cursorIdx, mode, startLine)
|
|
||||||
in
|
in
|
||||||
(newApp, drawMsg)
|
buildTextAndClear (app, buffer, cursorIdx)
|
||||||
end
|
end
|
||||||
|
|
||||||
(* equivalent of vi's 'x' command *)
|
(* equivalent of vi's 'x' command *)
|
||||||
fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) =
|
fun helpRemoveChr (app: app_type, buffer, cursorIdx, count) =
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
let
|
buildTextAndClear (app, buffer, cursorIdx)
|
||||||
val {startLine, windowWidth, windowHeight, ...} = app
|
|
||||||
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
|
||||||
val newApp = AppWith.bufferAndCursorIdx
|
|
||||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
|
|
||||||
|
|
||||||
val drawMsg =
|
|
||||||
TextBuilder.build
|
|
||||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
|
||||||
in
|
|
||||||
(newApp, drawMsg)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
|||||||
Reference in New Issue
Block a user