refactor app-update.sml to pass additional parameters to TextBuilder.build
This commit is contained in:
@@ -16,11 +16,23 @@ struct
|
||||
|
||||
fun resizeText (app: app_type, newWidth, newHeight) =
|
||||
let
|
||||
val {buffer, windowWidth, windowHeight, startLine, cursorIdx, ...} = app
|
||||
val
|
||||
{ buffer
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, startLine
|
||||
, cursorIdx
|
||||
, searchList
|
||||
, searchString
|
||||
, ...
|
||||
} = app
|
||||
|
||||
val newBuffer = LineGap.goToLine (startLine, buffer)
|
||||
val drawMsg = TextBuilder.build
|
||||
(startLine, cursorIdx, newBuffer, newWidth, newHeight)
|
||||
( startLine, cursorIdx, newBuffer
|
||||
, newWidth, newHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
|
||||
val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight)
|
||||
in
|
||||
@@ -29,7 +41,8 @@ struct
|
||||
|
||||
fun buildTextAndClear (app: app_type, buffer, cursorIdx) =
|
||||
let
|
||||
val {windowWidth, windowHeight, startLine, ...} = app
|
||||
val {windowWidth, windowHeight, startLine, searchList, searchString, ...} =
|
||||
app
|
||||
|
||||
(* move LineGap to first line displayed on screen *)
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
@@ -41,9 +54,11 @@ struct
|
||||
(* 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 drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
@@ -59,7 +74,8 @@ struct
|
||||
* *)
|
||||
fun buildTextAndClearAfterChr (app: app_type, buffer, cursorIdx) =
|
||||
let
|
||||
val {windowWidth, windowHeight, startLine, ...} = app
|
||||
val {windowWidth, windowHeight, startLine, searchList, searchString, ...} =
|
||||
app
|
||||
|
||||
(* move LineGap to first line displayed on screen *)
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
@@ -71,9 +87,11 @@ struct
|
||||
(* 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 drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
@@ -84,7 +102,16 @@ struct
|
||||
|
||||
fun centreToCursor (app: app_type) =
|
||||
let
|
||||
val {buffer, windowWidth, windowHeight, startLine = origLine, cursorIdx, ...} = app
|
||||
val
|
||||
{ buffer
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, startLine = origLine
|
||||
, cursorIdx
|
||||
, searchList
|
||||
, searchString
|
||||
, ...
|
||||
} = app
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
|
||||
val startLine = TextWindow.getStartLineWithCursorCentered
|
||||
@@ -95,9 +122,11 @@ struct
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
|
||||
|
||||
val drawMsg =
|
||||
TextBuilder.build
|
||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
end
|
||||
@@ -106,15 +135,18 @@ struct
|
||||
|
||||
fun moveToStart (app: app_type) =
|
||||
let
|
||||
val {buffer, windowWidth, windowHeight, ...} = app
|
||||
val {buffer, windowWidth, windowHeight, searchList, searchString, ...} =
|
||||
app
|
||||
|
||||
val cursorIdx = 0
|
||||
val startLine = 0
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
|
||||
val drawMsg =
|
||||
TextBuilder.build
|
||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
@@ -125,7 +157,8 @@ struct
|
||||
|
||||
fun moveToEnd (app: app_type) =
|
||||
let
|
||||
val {buffer, windowWidth, windowHeight, ...} = app
|
||||
val {buffer, windowWidth, windowHeight, searchList, searchString, ...} =
|
||||
app
|
||||
|
||||
val buffer = LineGap.goToEnd buffer
|
||||
val {line = bufferLine, idx = bufferIdx, ...} = buffer
|
||||
@@ -144,9 +177,11 @@ struct
|
||||
end
|
||||
|
||||
val buffer = LineGap.goToLine (bufferLine, buffer)
|
||||
val drawMsg =
|
||||
TextBuilder.build
|
||||
(bufferLine, bufferIdx, buffer, windowWidth, windowHeight)
|
||||
val drawMsg = TextBuilder.build
|
||||
( bufferLine, bufferIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
@@ -160,7 +195,15 @@ struct
|
||||
moveToStart app
|
||||
else
|
||||
let
|
||||
val {windowWidth, windowHeight, buffer, startLine = origLine, ...} = app
|
||||
val
|
||||
{ windowWidth
|
||||
, windowHeight
|
||||
, buffer
|
||||
, startLine = origLine
|
||||
, searchList
|
||||
, searchString
|
||||
, ...
|
||||
} = app
|
||||
val buffer = LineGap.goToLine (reqLine, buffer)
|
||||
|
||||
(* get idx of first chr after linebreak *)
|
||||
@@ -175,9 +218,11 @@ struct
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
|
||||
|
||||
val drawMsg =
|
||||
TextBuilder.build
|
||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
end
|
||||
@@ -197,8 +242,7 @@ struct
|
||||
* regardless of the data structure used.
|
||||
* If this happens, and the newCursorIdx is the same as the old one,
|
||||
* then skip to end of loop by going to base case. *)
|
||||
if cursorIdx = newCursorIdx
|
||||
then 0
|
||||
if cursorIdx = newCursorIdx then 0
|
||||
else count - 1
|
||||
in
|
||||
helpMove (app, buffer, newCursorIdx, newCount, fMove)
|
||||
@@ -211,7 +255,16 @@ struct
|
||||
|
||||
fun moveToMatchingPair (app: app_type) =
|
||||
let
|
||||
val {buffer, cursorIdx, windowWidth, windowHeight, startLine, ...} = app
|
||||
val
|
||||
{ buffer
|
||||
, cursorIdx
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, startLine
|
||||
, searchList
|
||||
, searchString
|
||||
, ...
|
||||
} = app
|
||||
|
||||
(* move LineGap and buffer to start of line *)
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
@@ -219,7 +272,8 @@ struct
|
||||
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
in
|
||||
if TextWindow.isCursorVisible
|
||||
if
|
||||
TextWindow.isCursorVisible
|
||||
(buffer, cursorIdx, startLine, windowWidth, windowHeight)
|
||||
then
|
||||
(* if visible, just need to redraw; no need to get line *)
|
||||
@@ -227,9 +281,11 @@ struct
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
|
||||
|
||||
val drawMsg =
|
||||
TextBuilder.build
|
||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
end
|
||||
@@ -237,8 +293,7 @@ struct
|
||||
(* not visible, so need to get startLine where cursor is visible *)
|
||||
let
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
val startLine =
|
||||
TextWindow.getStartLineWithCursorCentered
|
||||
val startLine = TextWindow.getStartLineWithCursorCentered
|
||||
(buffer, cursorIdx, startLine, windowWidth, windowHeight div 2)
|
||||
|
||||
val buffer = LineGap.goToLine (startLine, buffer)
|
||||
@@ -246,9 +301,11 @@ struct
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine)
|
||||
|
||||
val drawMsg =
|
||||
TextBuilder.build
|
||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
in
|
||||
(newApp, drawMsg)
|
||||
end
|
||||
@@ -340,18 +397,17 @@ struct
|
||||
* if cursorIdx is not 0 *)
|
||||
val buffer = LineGap.delete (cursorIdx, 1, buffer)
|
||||
val cursorIdx =
|
||||
if Cursor.isPrevChrStartOfLine (buffer, cursorIdx)
|
||||
orelse cursorIdx = 0 then
|
||||
cursorIdx
|
||||
if
|
||||
Cursor.isPrevChrStartOfLine (buffer, cursorIdx)
|
||||
orelse cursorIdx = 0
|
||||
then cursorIdx
|
||||
else cursorIdx - 1
|
||||
in
|
||||
helpRemoveChr (app, buffer, cursorIdx, count - 1)
|
||||
end
|
||||
else
|
||||
let
|
||||
val buffer = LineGap.delete (cursorIdx, 1, buffer)
|
||||
in
|
||||
helpRemoveChr (app, buffer, cursorIdx, count - 1)
|
||||
let val buffer = LineGap.delete (cursorIdx, 1, buffer)
|
||||
in helpRemoveChr (app, buffer, cursorIdx, count - 1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -501,7 +557,8 @@ struct
|
||||
buildTextAndClear (app, buffer, low)
|
||||
end
|
||||
|
||||
fun helpDeleteToChr (app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr) =
|
||||
fun helpDeleteToChr
|
||||
(app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr) =
|
||||
if count = 0 then
|
||||
let
|
||||
val low = Int.min (cursorIdx, otherIdx)
|
||||
@@ -518,25 +575,44 @@ struct
|
||||
val newCount = if newOtherIdx = otherIdx then 0 else count - 1
|
||||
val newOtherIdx = fInc (newOtherIdx, 1)
|
||||
in
|
||||
helpDeleteToChr (app, buffer, cursorIdx, newOtherIdx, newCount, fMove, fInc, chr)
|
||||
helpDeleteToChr
|
||||
(app, buffer, cursorIdx, newOtherIdx, newCount, fMove, fInc, chr)
|
||||
end
|
||||
|
||||
fun deleteToChr (app: app_type, count, fMove, fInc, chr) =
|
||||
helpDeleteToChr
|
||||
(app, #buffer app, #cursorIdx app, #cursorIdx app, count, fMove, fInc, chr)
|
||||
( app
|
||||
, #buffer app
|
||||
, #cursorIdx app
|
||||
, #cursorIdx app
|
||||
, count
|
||||
, fMove
|
||||
, fInc
|
||||
, chr
|
||||
)
|
||||
|
||||
fun deleteToStart (app: app_type) =
|
||||
let
|
||||
val {cursorIdx, buffer, windowWidth, windowHeight, ...} = app
|
||||
val
|
||||
{ cursorIdx
|
||||
, buffer
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, searchList
|
||||
, searchString
|
||||
, ...
|
||||
} = app
|
||||
|
||||
val buffer = LineGap.delete(0, cursorIdx, buffer)
|
||||
val buffer = LineGap.delete (0, cursorIdx, buffer)
|
||||
val cursorIdx = 0
|
||||
val startLine = 0
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
|
||||
val drawMsg =
|
||||
TextBuilder.build
|
||||
(startLine, cursorIdx, buffer, windowWidth, windowHeight)
|
||||
val drawMsg = TextBuilder.build
|
||||
( startLine, cursorIdx, buffer
|
||||
, windowWidth, windowHeight
|
||||
, searchList, searchString
|
||||
)
|
||||
|
||||
val mode = NORMAL_MODE ""
|
||||
val newApp = AppWith.bufferAndCursorIdx
|
||||
@@ -610,10 +686,8 @@ struct
|
||||
(* if str has a size larger than 0,
|
||||
* interpret as "go to line" command;
|
||||
* else, interpret as a command to move to end *)
|
||||
if String.size str = 0 then
|
||||
moveToEnd app
|
||||
else
|
||||
moveToLine (app, count - 1)
|
||||
if String.size str = 0 then moveToEnd app
|
||||
else moveToLine (app, count - 1)
|
||||
| #"%" => moveToMatchingPair app
|
||||
| #"x" => removeChr (app, count)
|
||||
(* multi-char commands which can be appended *)
|
||||
@@ -678,24 +752,28 @@ struct
|
||||
#"t" =>
|
||||
(* delete till chr, forwards *)
|
||||
(case newCmd of
|
||||
CHAR_EVENT chr => deleteToChr (app, 1, Cursor.tillNextChr, op+, chr)
|
||||
CHAR_EVENT chr =>
|
||||
deleteToChr (app, 1, Cursor.tillNextChr, op+, chr)
|
||||
| KEY_ESC => clearMode app
|
||||
| RESIZE_EVENT (width, height) => resizeText (app, width, height))
|
||||
| #"T" =>
|
||||
(* delete till chr, backwards *)
|
||||
(case newCmd of
|
||||
CHAR_EVENT chr => deleteToChr (app, 1, Cursor.tillPrevChr, op-, chr)
|
||||
CHAR_EVENT chr =>
|
||||
deleteToChr (app, 1, Cursor.tillPrevChr, op-, chr)
|
||||
| KEY_ESC => clearMode app
|
||||
| RESIZE_EVENT (width, height) => resizeText (app, width, height))
|
||||
| #"f" =>
|
||||
(case newCmd of
|
||||
CHAR_EVENT chr => deleteToChr (app, count, Cursor.toNextChr, op+, chr)
|
||||
CHAR_EVENT chr =>
|
||||
deleteToChr (app, count, Cursor.toNextChr, op+, chr)
|
||||
| KEY_ESC => clearMode app
|
||||
| RESIZE_EVENT (width, height) => resizeText (app, width, height))
|
||||
| #"F" =>
|
||||
(* delete to chr, backwards *)
|
||||
(case newCmd of
|
||||
CHAR_EVENT chr => deleteToChr (app, count, Cursor.toPrevChr, op-, chr)
|
||||
CHAR_EVENT chr =>
|
||||
deleteToChr (app, count, Cursor.toPrevChr, op-, chr)
|
||||
| KEY_ESC => clearMode app
|
||||
| RESIZE_EVENT (width, height) => resizeText (app, width, height))
|
||||
| #"g" =>
|
||||
@@ -729,24 +807,16 @@ struct
|
||||
| #"T" =>
|
||||
(* to just before chr, backward *)
|
||||
handleMoveToChr (1, app, Cursor.tillPrevChr, newCmd)
|
||||
| #"y" =>
|
||||
(* yank *)
|
||||
clearMode app
|
||||
| #"d" =>
|
||||
(* delete *)
|
||||
parseDelete (strPos, str, count, app, newCmd)
|
||||
| #"y" => (* yank *) clearMode app
|
||||
| #"d" => (* delete *) parseDelete (strPos, str, count, app, newCmd)
|
||||
| #"f" =>
|
||||
(* to chr, forward *)
|
||||
handleMoveToChr (count, app, Cursor.toNextChr, newCmd)
|
||||
| #"F" =>
|
||||
(* to chr, backward *)
|
||||
handleMoveToChr (count, app, Cursor.toPrevChr, newCmd)
|
||||
| #"g" =>
|
||||
(* go *)
|
||||
handleGo (count, app, newCmd)
|
||||
| #"c" =>
|
||||
(* change *)
|
||||
clearMode app
|
||||
| #"g" => (* go *) handleGo (count, app, newCmd)
|
||||
| #"c" => (* change *) clearMode app
|
||||
| _ =>
|
||||
(* isn't a non-terminal cmd
|
||||
* this case should never happen*)
|
||||
|
||||
@@ -481,6 +481,9 @@ struct
|
||||
else
|
||||
0
|
||||
val absIdx = curIdx + startIdx
|
||||
|
||||
(* todo: make going to absIdx a prerequisite for using this
|
||||
* function *)
|
||||
val searchList = SearchList.goToNum (absIdx, searchList)
|
||||
|
||||
val windowData =
|
||||
|
||||
Reference in New Issue
Block a user