implement 'deleteInside' motions
This commit is contained in:
@@ -431,8 +431,73 @@ struct
|
||||
|
||||
val buffer = LineGap.goToIdx (low, buffer)
|
||||
in
|
||||
|
||||
Finish.buildTextAndClear (app, buffer, low, searchList, initialMsg)
|
||||
end
|
||||
end
|
||||
|
||||
fun deleteInsideChrOpen (app: app_type, chr) =
|
||||
let
|
||||
val {cursorIdx, buffer, searchString, ...} = app
|
||||
|
||||
val start = cursorIdx + 1
|
||||
val buffer = LineGap.goToIdx (start, buffer)
|
||||
|
||||
val origLow = Cursor.toPrevChr (buffer, start, chr)
|
||||
val buffer = LineGap.goToIdx (origLow, buffer)
|
||||
val high = Cursor.matchPair (buffer, origLow)
|
||||
in
|
||||
if origLow = high then
|
||||
Finish.clearMode app
|
||||
else
|
||||
let
|
||||
val low = origLow + 1
|
||||
val length = high - low
|
||||
val buffer = LineGap.delete (low, length, buffer)
|
||||
|
||||
val buffer = LineGap.goToEnd buffer
|
||||
val initialMsg = [SEARCH (buffer, searchString)]
|
||||
|
||||
val buffer = LineGap.goToIdx (low + 777, buffer)
|
||||
val searchList =
|
||||
SearchList.buildRange (buffer, searchString, low - 777)
|
||||
|
||||
val buffer = LineGap.goToIdx (origLow, buffer)
|
||||
in
|
||||
Finish.buildTextAndClear
|
||||
(app, buffer, origLow, searchList, initialMsg)
|
||||
end
|
||||
end
|
||||
|
||||
fun deleteInsideChrClose (app: app_type, chr) =
|
||||
let
|
||||
val {cursorIdx, buffer, searchString, ...} = app
|
||||
|
||||
val start = Int.max (cursorIdx - 1, 0)
|
||||
val buffer = LineGap.goToIdx (start, buffer)
|
||||
|
||||
val high = Cursor.toNextChr (buffer, start, chr)
|
||||
val buffer = LineGap.goToIdx (high, buffer)
|
||||
val origLow = Cursor.matchPair (buffer, high)
|
||||
in
|
||||
if origLow = high then
|
||||
Finish.clearMode app
|
||||
else
|
||||
let
|
||||
val low = origLow + 1
|
||||
val length = high - low
|
||||
val buffer = LineGap.delete (low, length, buffer)
|
||||
|
||||
val buffer = LineGap.goToEnd buffer
|
||||
val initialMsg = [SEARCH (buffer, searchString)]
|
||||
|
||||
val buffer = LineGap.goToIdx (low + 777, buffer)
|
||||
val searchList =
|
||||
SearchList.buildRange (buffer, searchString, low - 777)
|
||||
|
||||
val buffer = LineGap.goToIdx (origLow, buffer)
|
||||
in
|
||||
Finish.buildTextAndClear
|
||||
(app, buffer, origLow, searchList, initialMsg)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -111,6 +111,20 @@ struct
|
||||
AppWith.mode (app, mode, [])
|
||||
end
|
||||
|
||||
fun parseDeleteInside (app, chr) =
|
||||
case chr of
|
||||
#"w" => NormalDelete.deleteInsideWord app
|
||||
| #"W" => NormalDelete.deleteInsideWORD app
|
||||
| #"(" => NormalDelete.deleteInsideChrOpen (app, chr)
|
||||
| #"[" => NormalDelete.deleteInsideChrOpen (app, chr)
|
||||
| #"{" => NormalDelete.deleteInsideChrOpen (app, chr)
|
||||
| #"<" => NormalDelete.deleteInsideChrOpen (app, chr)
|
||||
| #")" => NormalDelete.deleteInsideChrClose (app, chr)
|
||||
| #"]" => NormalDelete.deleteInsideChrClose (app, chr)
|
||||
| #"}" => NormalDelete.deleteInsideChrClose (app, chr)
|
||||
| #">" => NormalDelete.deleteInsideChrClose (app, chr)
|
||||
| _ => Finish.clearMode app
|
||||
|
||||
fun parseDelete (strPos, str, count, app, newCmd) =
|
||||
if strPos = String.size str - 1 then
|
||||
(* have to check newCmd *)
|
||||
@@ -212,9 +226,7 @@ struct
|
||||
Finish.withSearchList (app, searchList))
|
||||
| #"i" =>
|
||||
(case newCmd of
|
||||
CHAR_EVENT #"w" => NormalDelete.deleteInsideWord app
|
||||
| CHAR_EVENT #"W" => NormalDelete.deleteInsideWORD app
|
||||
| CHAR_EVENT _ => Finish.clearMode app
|
||||
CHAR_EVENT chr => parseDeleteInside (app, chr)
|
||||
| KEY_ESC => Finish.clearMode app
|
||||
| RESIZE_EVENT (width, height) =>
|
||||
Finish.resizeText (app, width, height)
|
||||
|
||||
@@ -249,5 +249,4 @@ struct
|
||||
Finish.buildTextAndClearAfterChr
|
||||
(app, buffer, newCursorIdx, searchList, [])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user