address todo in text-builder.sml by adding prerequisite: always call SearchList.goToNum before calling TextBuilder.build
This commit is contained in:
@@ -28,6 +28,9 @@ struct
|
|||||||
} = app
|
} = app
|
||||||
|
|
||||||
val newBuffer = LineGap.goToLine (startLine, buffer)
|
val newBuffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
|
|
||||||
val drawMsg = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
( startLine
|
( startLine
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -38,7 +41,8 @@ struct
|
|||||||
, searchString
|
, searchString
|
||||||
)
|
)
|
||||||
|
|
||||||
val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight)
|
val newApp =
|
||||||
|
AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight, searchList)
|
||||||
in
|
in
|
||||||
(newApp, drawMsg)
|
(newApp, drawMsg)
|
||||||
end
|
end
|
||||||
@@ -47,7 +51,8 @@ struct
|
|||||||
let
|
let
|
||||||
val {windowWidth, windowHeight, startLine, searchString, ...} = app
|
val {windowWidth, windowHeight, startLine, searchString, ...} = app
|
||||||
|
|
||||||
(* move LineGap to first line displayed on screen *)
|
(* move LineGap to first line displayed on screen
|
||||||
|
* and move searchList to line's start idx as well *)
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
|
||||||
(* get new startLine which may move screen depending on cursor movements *)
|
(* get new startLine which may move screen depending on cursor movements *)
|
||||||
@@ -56,6 +61,8 @@ struct
|
|||||||
|
|
||||||
(* move buffer to new startLine as required by TextBuilder.build *)
|
(* move buffer to new startLine as required by TextBuilder.build *)
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
|
|
||||||
val drawMsg = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
( startLine
|
( startLine
|
||||||
@@ -90,8 +97,11 @@ struct
|
|||||||
val startLine = TextWindow.getStartLine
|
val startLine = TextWindow.getStartLine
|
||||||
(buffer, startLine, cursorIdx, windowWidth, windowHeight)
|
(buffer, startLine, cursorIdx, windowWidth, windowHeight)
|
||||||
|
|
||||||
(* move buffer to new startLine as required by TextBuilder.build *)
|
(* move buffer to new startLine as required by TextBuilder.build
|
||||||
|
* and move searchList to idx where line starts as well *)
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
|
|
||||||
val drawMsg = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
( startLine
|
( startLine
|
||||||
@@ -128,6 +138,8 @@ struct
|
|||||||
(buffer, cursorIdx, origLine, windowWidth, windowHeight div 2)
|
(buffer, cursorIdx, origLine, windowWidth, windowHeight div 2)
|
||||||
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
|
|
||||||
val newApp = AppWith.bufferAndCursorIdx
|
val newApp = AppWith.bufferAndCursorIdx
|
||||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
||||||
@@ -155,6 +167,7 @@ struct
|
|||||||
val cursorIdx = 0
|
val cursorIdx = 0
|
||||||
val startLine = 0
|
val startLine = 0
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val searchList = SearchList.goToNum (0, searchList)
|
||||||
|
|
||||||
val drawMsg = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
( startLine
|
( startLine
|
||||||
@@ -195,6 +208,9 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
val buffer = LineGap.goToLine (bufferLine, buffer)
|
val buffer = LineGap.goToLine (bufferLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (bufferLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
|
|
||||||
val drawMsg = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
( bufferLine
|
( bufferLine
|
||||||
, bufferIdx
|
, bufferIdx
|
||||||
@@ -236,6 +252,8 @@ struct
|
|||||||
(buffer, cursorIdx, origLine, windowWidth, windowHeight div 2)
|
(buffer, cursorIdx, origLine, windowWidth, windowHeight div 2)
|
||||||
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
|
|
||||||
val newApp = AppWith.bufferAndCursorIdx
|
val newApp = AppWith.bufferAndCursorIdx
|
||||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
||||||
@@ -297,6 +315,8 @@ struct
|
|||||||
val cursorIdx = Cursor.matchPair (buffer, cursorIdx)
|
val cursorIdx = Cursor.matchPair (buffer, cursorIdx)
|
||||||
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
in
|
in
|
||||||
if
|
if
|
||||||
TextWindow.isCursorVisible
|
TextWindow.isCursorVisible
|
||||||
@@ -327,6 +347,8 @@ struct
|
|||||||
(buffer, cursorIdx, startLine, windowWidth, windowHeight div 2)
|
(buffer, cursorIdx, startLine, windowWidth, windowHeight div 2)
|
||||||
|
|
||||||
val buffer = LineGap.goToLine (startLine, buffer)
|
val buffer = LineGap.goToLine (startLine, buffer)
|
||||||
|
val lineIdx = TextBuilder.getLineAbsIdx (startLine, buffer)
|
||||||
|
val searchList = SearchList.goToNum (lineIdx, searchList)
|
||||||
|
|
||||||
val newApp = AppWith.bufferAndCursorIdx
|
val newApp = AppWith.bufferAndCursorIdx
|
||||||
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
(app, buffer, cursorIdx, NORMAL_MODE "", startLine, searchList)
|
||||||
@@ -700,6 +722,7 @@ struct
|
|||||||
val cursorIdx = 0
|
val cursorIdx = 0
|
||||||
val startLine = 0
|
val startLine = 0
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
val searchList = SearchList.goToNum (0, searchList)
|
||||||
|
|
||||||
val drawMsg = TextBuilder.build
|
val drawMsg = TextBuilder.build
|
||||||
( startLine
|
( startLine
|
||||||
|
|||||||
@@ -26,14 +26,15 @@ struct
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
fun bufferAndSize (app: app_type, newBuffer, newWidth, newHeight) =
|
fun bufferAndSize
|
||||||
|
(app: app_type, newBuffer, newWidth, newHeight, newSearchList) =
|
||||||
let
|
let
|
||||||
val
|
val
|
||||||
{ mode
|
{ mode
|
||||||
, buffer = _
|
, buffer = _
|
||||||
, windowWidth = _
|
, windowWidth = _
|
||||||
, windowHeight = _
|
, windowHeight = _
|
||||||
, searchList
|
, searchList = _
|
||||||
, searchString
|
, searchString
|
||||||
, startLine
|
, startLine
|
||||||
, cursorIdx
|
, cursorIdx
|
||||||
@@ -43,7 +44,7 @@ struct
|
|||||||
, buffer = newBuffer
|
, buffer = newBuffer
|
||||||
, windowWidth = newWidth
|
, windowWidth = newWidth
|
||||||
, windowHeight = newHeight
|
, windowHeight = newHeight
|
||||||
, searchList = searchList
|
, searchList = newSearchList
|
||||||
, searchString = searchString
|
, searchString = searchString
|
||||||
, startLine = startLine
|
, startLine = startLine
|
||||||
, cursorIdx = cursorIdx
|
, cursorIdx = cursorIdx
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
signature TEXT_BUILDER =
|
signature TEXT_BUILDER =
|
||||||
sig
|
sig
|
||||||
|
(* Prerequisites: LineGap is moved to requested line first. *)
|
||||||
|
val getLineAbsIdx: int * LineGap.t -> int
|
||||||
|
|
||||||
(* Prerequisites: LineGap is moved to requested line first. *)
|
(* Prerequisites: LineGap is moved to requested line first. *)
|
||||||
val build: int * int * LineGap.t * int * int * SearchList.t * string
|
val build: int * int * LineGap.t * int * int * SearchList.t * string
|
||||||
-> MailboxType.t list
|
-> MailboxType.t list
|
||||||
@@ -459,6 +462,45 @@ struct
|
|||||||
| [] =>
|
| [] =>
|
||||||
accToDrawMsg (acc, cursorAcc, bgAcc)
|
accToDrawMsg (acc, cursorAcc, bgAcc)
|
||||||
|
|
||||||
|
(* gets line start idx, relative to right hd *)
|
||||||
|
fun helpGetLineStartIdx (startLine, curLine, rLnHd) =
|
||||||
|
if startLine > curLine then
|
||||||
|
let
|
||||||
|
val lnPos = startLine - curLine - 1
|
||||||
|
in
|
||||||
|
Vector.sub (rLnHd, lnPos) + 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
0
|
||||||
|
|
||||||
|
(* gets line start idx, absolute *)
|
||||||
|
fun helpGetLineAbsIdx (curIdx, startLine, curLine, rLnHd) =
|
||||||
|
let
|
||||||
|
val startIdx =
|
||||||
|
if startLine > curLine then
|
||||||
|
let
|
||||||
|
val lnPos = startLine - curLine - 1
|
||||||
|
in
|
||||||
|
Vector.sub (rLnHd, lnPos) + 1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
0
|
||||||
|
in
|
||||||
|
curIdx + startIdx
|
||||||
|
end
|
||||||
|
|
||||||
|
fun getLineAbsIdx (startLine, lineGap: LineGap.t) =
|
||||||
|
let
|
||||||
|
val {rightLines, line = curLine, idx = curIdx, ...} = lineGap
|
||||||
|
in
|
||||||
|
case rightLines of
|
||||||
|
rLnHd :: _ =>
|
||||||
|
helpGetLineAbsIdx (curIdx, startLine, curLine, rLnHd)
|
||||||
|
| [] =>
|
||||||
|
(* should never happen *)
|
||||||
|
0
|
||||||
|
end
|
||||||
|
|
||||||
fun build
|
fun build
|
||||||
( startLine, cursorPos, lineGap: LineGap.t
|
( startLine, cursorPos, lineGap: LineGap.t
|
||||||
, windowWidth, windowHeight
|
, windowWidth, windowHeight
|
||||||
@@ -470,30 +512,11 @@ struct
|
|||||||
case (rightStrings, rightLines) of
|
case (rightStrings, rightLines) of
|
||||||
(rStrHd :: rStrTl, rLnHd :: _) =>
|
(rStrHd :: rStrTl, rLnHd :: _) =>
|
||||||
let
|
let
|
||||||
(* get index of line to start building from *)
|
(* get relative index of line to start building from *)
|
||||||
val startIdx =
|
val startIdx = helpGetLineStartIdx (startLine, curLine, rLnHd)
|
||||||
if startLine > curLine then
|
(* get absolute idx of line *)
|
||||||
let
|
|
||||||
val lnPos = startLine - curLine - 1
|
|
||||||
val startIdx = Vector.sub (rLnHd, lnPos)
|
|
||||||
in
|
|
||||||
if
|
|
||||||
String.sub (rStrHd, startIdx) = #"\r"
|
|
||||||
andalso startIdx < String.size rStrHd - 1
|
|
||||||
andalso String.sub (rStrHd, startIdx + 1) = #"\n"
|
|
||||||
then
|
|
||||||
(* handle \r\n pair *)
|
|
||||||
startIdx + 2
|
|
||||||
else startIdx + 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
0
|
|
||||||
val absIdx = curIdx + startIdx
|
val absIdx = curIdx + startIdx
|
||||||
|
|
||||||
(* todo: make going to absIdx a prerequisite for using this
|
|
||||||
* function *)
|
|
||||||
val searchList = SearchList.goToNum (absIdx, searchList)
|
|
||||||
|
|
||||||
val windowData =
|
val windowData =
|
||||||
{ w = windowWidth
|
{ w = windowWidth
|
||||||
, h = windowHeight
|
, h = windowHeight
|
||||||
|
|||||||
Reference in New Issue
Block a user