bookmark checkpoint in refactoring code to call funhction which deletes from both (searchList and buffer), instead of just deleting buffer
This commit is contained in:
@@ -9,8 +9,7 @@ struct
|
|||||||
open DrawMsg
|
open DrawMsg
|
||||||
open MailboxType
|
open MailboxType
|
||||||
|
|
||||||
fun finishAfterDeletingBuffer
|
fun finishAfterDeletingBuffer (app, low, buffer, searchList, time, msgs) =
|
||||||
(app: app_type, low, buffer, searchList, time, msgs) =
|
|
||||||
let val buffer = LineGap.goToIdx (low, buffer)
|
let val buffer = LineGap.goToIdx (low, buffer)
|
||||||
in NormalFinish.buildTextAndClear (app, buffer, low, searchList, msgs, time)
|
in NormalFinish.buildTextAndClear (app, buffer, low, searchList, msgs, time)
|
||||||
end
|
end
|
||||||
@@ -939,7 +938,7 @@ struct
|
|||||||
|
|
||||||
fun deleteToEnd (app: app_type, time) =
|
fun deleteToEnd (app: app_type, time) =
|
||||||
let
|
let
|
||||||
val {buffer, cursorIdx, ...} = app
|
val {buffer, cursorIdx, searchList, dfa, ...} = app
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
val startOfLineIdx = Cursor.vi0 (buffer, cursorIdx)
|
val startOfLineIdx = Cursor.vi0 (buffer, cursorIdx)
|
||||||
@@ -948,9 +947,14 @@ struct
|
|||||||
val buffer = LineGap.goToIdx (#textLength buffer, buffer)
|
val buffer = LineGap.goToIdx (#textLength buffer, buffer)
|
||||||
val initialMsg = Fn.initMsgs (startOfLineIdx, length, buffer)
|
val initialMsg = Fn.initMsgs (startOfLineIdx, length, buffer)
|
||||||
|
|
||||||
val buffer = LineGap.delete (startOfLineIdx, length, buffer)
|
val (buffer, searchList) = SearchList.deleteBufferAndSearchList
|
||||||
|
(startOfLineIdx, length, buffer, searchList, dfa)
|
||||||
|
|
||||||
val buffer =
|
val buffer =
|
||||||
if #textLength buffer = 0 then LineGap.fromString "\n" else buffer
|
(* todo: if we are creating a new buffer from string,
|
||||||
|
* then make sure we update the searchList for it too *)
|
||||||
|
if #textLength buffer = 0 then LineGap.fromString "\n"
|
||||||
|
else buffer
|
||||||
|
|
||||||
val newLineEndIdx = Int.max (startOfLineIdx - 1, 0)
|
val newLineEndIdx = Int.max (startOfLineIdx - 1, 0)
|
||||||
val buffer = LineGap.goToIdx (newLineEndIdx, buffer)
|
val buffer = LineGap.goToIdx (newLineEndIdx, buffer)
|
||||||
@@ -1181,20 +1185,24 @@ struct
|
|||||||
|
|
||||||
fun finishDeleteAroundPair (app, buffer, chr1Idx, chr2Idx, time) =
|
fun finishDeleteAroundPair (app, buffer, chr1Idx, chr2Idx, time) =
|
||||||
let
|
let
|
||||||
|
val {searchList, dfa, ...} = app
|
||||||
|
|
||||||
val low = Int.min (chr1Idx, chr2Idx)
|
val low = Int.min (chr1Idx, chr2Idx)
|
||||||
val high = Int.max (chr1Idx, chr2Idx) + 1
|
val high = Int.max (chr1Idx, chr2Idx) + 1
|
||||||
val length = high - low
|
val length = high - low
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (high, buffer)
|
val buffer = LineGap.goToIdx (high, buffer)
|
||||||
val initialMsg = Fn.initMsgs (low, length, buffer)
|
val initialMsg = Fn.initMsgs (low, length, buffer)
|
||||||
val buffer = LineGap.delete (low, length, buffer)
|
|
||||||
|
val (buffer, searchList) = SearchList.deleteBufferAndSearchList
|
||||||
|
(low, length, buffer, searchList, dfa)
|
||||||
|
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
val low =
|
val low =
|
||||||
if Cursor.isOnNewlineAfterChr (buffer, low) then low - 1 else low
|
if Cursor.isOnNewlineAfterChr (buffer, low) then low - 1 else low
|
||||||
val buffer = LineGap.goToIdx (low, buffer)
|
val buffer = LineGap.goToIdx (low, buffer)
|
||||||
in
|
in
|
||||||
finishAfterDeletingBuffer (app, low, buffer, time, initialMsg)
|
finishAfterDeletingBuffer (app, low, buffer, searchList, time, initialMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun deleteAroundPair (app: app_type, openChr, closeChr, time) =
|
fun deleteAroundPair (app: app_type, openChr, closeChr, time) =
|
||||||
|
|||||||
@@ -33,9 +33,13 @@ struct
|
|||||||
|
|
||||||
val {cursorIdx = origCursorIdx, dfa, ...} = app
|
val {cursorIdx = origCursorIdx, dfa, ...} = app
|
||||||
val buffer = LineGap.goToStart buffer
|
val buffer = LineGap.goToStart buffer
|
||||||
|
|
||||||
|
(* todo: try updating searchList incrementally
|
||||||
|
* instead of rebuilding from scratch *)
|
||||||
|
val (buffer, searchList) = SearchList.build (buffer, dfa)
|
||||||
in
|
in
|
||||||
NormalDelete.finishAfterDeletingBuffer
|
NormalDelete.finishAfterDeletingBuffer
|
||||||
(app, origCursorIdx, buffer, time, [])
|
(app, origCursorIdx, buffer, searchList, time, [])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
@@ -59,9 +63,9 @@ struct
|
|||||||
end
|
end
|
||||||
|
|
||||||
local
|
local
|
||||||
fun loop (cursorIdx, buffer, count) =
|
fun loop (cursorIdx, buffer, searchList, dfa, count) =
|
||||||
if count = 0 then
|
if count = 0 then
|
||||||
buffer
|
(buffer, searchList)
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
@@ -71,12 +75,13 @@ struct
|
|||||||
(* delete from buffer *)
|
(* delete from buffer *)
|
||||||
val difference = firstNonSpaceChr - lineStart
|
val difference = firstNonSpaceChr - lineStart
|
||||||
val deleteLength = Int.min (difference, 2)
|
val deleteLength = Int.min (difference, 2)
|
||||||
val buffer =
|
val (buffer, searchList) =
|
||||||
if difference = 0 then
|
if difference = 0 then
|
||||||
(* can't dedent as there is no leading space *)
|
(* can't dedent as there is no leading space *)
|
||||||
buffer
|
(buffer, searchList)
|
||||||
else
|
else
|
||||||
LineGap.delete (lineStart, deleteLength, buffer)
|
SearchList.deleteBufferAndSearchList
|
||||||
|
(lineStart, deleteLength, buffer, searchList, dfa)
|
||||||
|
|
||||||
(* get next line to dedent *)
|
(* get next line to dedent *)
|
||||||
val buffer = LineGap.goToIdx (lineStart, buffer)
|
val buffer = LineGap.goToIdx (lineStart, buffer)
|
||||||
@@ -86,14 +91,14 @@ struct
|
|||||||
|
|
||||||
val count = if lineEnd = nextLine then 0 else count - 1
|
val count = if lineEnd = nextLine then 0 else count - 1
|
||||||
in
|
in
|
||||||
loop (nextLine, buffer, count)
|
loop (nextLine, buffer, searchList, dfa, count)
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
fun dedentLine (app: app_type, count, time) =
|
fun dedentLine (app: app_type, count, time) =
|
||||||
let
|
let
|
||||||
open MailboxType
|
open MailboxType
|
||||||
|
|
||||||
val {cursorIdx, buffer, dfa, ...} = app
|
val {cursorIdx, buffer, searchList, dfa, ...} = app
|
||||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||||
|
|
||||||
val lineStart = Cursor.vi0 (buffer, cursorIdx)
|
val lineStart = Cursor.vi0 (buffer, cursorIdx)
|
||||||
@@ -104,9 +109,12 @@ struct
|
|||||||
val deleteLength = Int.min (difference, 2)
|
val deleteLength = Int.min (difference, 2)
|
||||||
|
|
||||||
(* delete once *)
|
(* delete once *)
|
||||||
val buffer =
|
val (buffer, searchList) =
|
||||||
if deleteLength = 0 then buffer
|
if deleteLength = 0 then
|
||||||
else LineGap.delete (lineStart, deleteLength, buffer)
|
(buffer, searchList)
|
||||||
|
else
|
||||||
|
SearchList.deleteBufferAndSearchList
|
||||||
|
(lineStart, deleteLength, buffer, searchList, dfa)
|
||||||
|
|
||||||
(* Calculate nextLine and newCursorIdx.
|
(* Calculate nextLine and newCursorIdx.
|
||||||
* The cursorIdx might be past the current line after we dedent.
|
* The cursorIdx might be past the current line after we dedent.
|
||||||
@@ -117,18 +125,18 @@ struct
|
|||||||
val nextLine = Cursor.viL (buffer, lineEnd, 1)
|
val nextLine = Cursor.viL (buffer, lineEnd, 1)
|
||||||
val newCursorIdx = Int.min (lineEnd, cursorIdx)
|
val newCursorIdx = Int.min (lineEnd, cursorIdx)
|
||||||
|
|
||||||
val buffer =
|
val (buffer, searchList) =
|
||||||
if lineEnd = nextLine then
|
if lineEnd = nextLine then
|
||||||
(* at end of file, so we cannot dedent anymore *)
|
(* at end of file, so we cannot dedent anymore *)
|
||||||
buffer
|
(buffer, searchList)
|
||||||
else
|
else
|
||||||
(* dedent remaining lines specified by count *)
|
(* dedent remaining lines specified by count *)
|
||||||
loop (nextLine, buffer, count - 1)
|
loop (nextLine, buffer, searchList, dfa, count - 1)
|
||||||
|
|
||||||
val buffer = LineGap.goToStart buffer
|
val buffer = LineGap.goToStart buffer
|
||||||
in
|
in
|
||||||
NormalDelete.finishAfterDeletingBuffer
|
NormalDelete.finishAfterDeletingBuffer
|
||||||
(app, newCursorIdx, buffer, time, [])
|
(app, newCursorIdx, buffer, searchList, time, [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user