bug fix when yanking or deleting inside a word (we should not clip 'high' value, and we should search for end of word strictly); this handles cases like when we only have one character in the buffer, or an empty buffer

This commit is contained in:
2025-09-06 01:12:59 +01:00
parent b9332bcd94
commit 73ec4e7578
5 changed files with 249 additions and 730 deletions

View File

@@ -388,16 +388,23 @@ struct
helpDeleteToMatch (app, newCursorIdx, cursorIdx, time)
end
(* check if we are trying to delete from an empty buffer
* or a buffer which consists of only one character which is \n *)
fun canDeleteInsideOrAround (buffer, low, length) =
not (length = 1 andalso LineGap.substring (low, 1, buffer) = "\n")
fun deleteInsideWord (app: app_type, time) =
let
val {buffer, cursorIdx, searchString, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val low = Cursor.prevWordStrict (buffer, cursorIdx, 1)
val high = Cursor.endOfWordForDelete (buffer, cursorIdx, 1)
val high = Cursor.endOfWordStrict (buffer, cursorIdx, 1) + 1
val buffer = LineGap.goToIdx (high, buffer)
val length = high - low
in
if low = high then
app
else
if canDeleteInsideOrAround (buffer, low, length) then
let
val length = high - low
val buffer = LineGap.delete (low, length, buffer)
@@ -414,20 +421,23 @@ struct
NormalFinish.buildTextAndClear
(app, buffer, low, searchList, initialMsg, time)
end
else
app
end
fun deleteInsideWORD (app: app_type, time) =
let
val {buffer, cursorIdx, searchString, ...} = app
val buffer = LineGap.goToIdx (cursorIdx, buffer)
val low = Cursor.prevWORDStrict (buffer, cursorIdx, 1)
val high = Cursor.endOfWORDForDelete (buffer, cursorIdx, 1)
val low = Cursor.prevWordStrict (buffer, cursorIdx, 1)
val high = Cursor.endOfWordStrict (buffer, cursorIdx, 1) + 1
val buffer = LineGap.goToIdx (high, buffer)
val length = high - low
in
if low = high then
app
else
if canDeleteInsideOrAround (buffer, low, length) then
let
val length = high - low
val buffer = LineGap.delete (low, length, buffer)
val buffer = LineGap.goToStart buffer
@@ -442,6 +452,8 @@ struct
NormalFinish.buildTextAndClear
(app, buffer, low, searchList, initialMsg, time)
end
else
app
end
fun finishAfterDeleteInside (app: app_type, origLow, high, time) =