Skip to content

Commit

Permalink
fixed cursor location when undoing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Mar 14, 2024
1 parent 4be42b8 commit f88653c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
Binary file modified config/absytree_config_wasm.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions scripting/absytree_internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ proc editor_text_indent_void_TextDocumentEditor_impl*(self: TextDocumentEditor)
proc editor_text_unindent_void_TextDocumentEditor_impl*(self: TextDocumentEditor) =
discard
proc editor_text_undo_void_TextDocumentEditor_string_impl*(
self: TextDocumentEditor; checkpoint: string = "move") =
self: TextDocumentEditor; checkpoint: string = "word") =
discard
proc editor_text_redo_void_TextDocumentEditor_string_impl*(
self: TextDocumentEditor; checkpoint: string = "move") =
self: TextDocumentEditor; checkpoint: string = "word") =
discard
proc editor_text_addNextCheckpoint_void_TextDocumentEditor_string_impl*(
self: TextDocumentEditor; checkpoint: string) =
Expand Down
4 changes: 2 additions & 2 deletions scripting/absytree_internal_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ proc editor_text_insertText_void_TextDocumentEditor_string_bool_impl(
proc editor_text_indent_void_TextDocumentEditor_impl(self: TextDocumentEditor) {.importc.}
proc editor_text_unindent_void_TextDocumentEditor_impl(self: TextDocumentEditor) {.importc.}
proc editor_text_undo_void_TextDocumentEditor_string_impl(
self: TextDocumentEditor; checkpoint: string = "move") {.importc.}
self: TextDocumentEditor; checkpoint: string = "word") {.importc.}
proc editor_text_redo_void_TextDocumentEditor_string_impl(
self: TextDocumentEditor; checkpoint: string = "move") {.importc.}
self: TextDocumentEditor; checkpoint: string = "word") {.importc.}
proc editor_text_addNextCheckpoint_void_TextDocumentEditor_string_impl(
self: TextDocumentEditor; checkpoint: string) {.importc.}
proc editor_text_printUndoHistory_void_TextDocumentEditor_int_impl(
Expand Down
4 changes: 2 additions & 2 deletions scripting/editor_text_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ proc indent*(self: TextDocumentEditor) =
editor_text_indent_void_TextDocumentEditor_impl(self)
proc unindent*(self: TextDocumentEditor) =
editor_text_unindent_void_TextDocumentEditor_impl(self)
proc undo*(self: TextDocumentEditor; checkpoint: string = "move") =
proc undo*(self: TextDocumentEditor; checkpoint: string = "word") =
editor_text_undo_void_TextDocumentEditor_string_impl(self, checkpoint)
proc redo*(self: TextDocumentEditor; checkpoint: string = "move") =
proc redo*(self: TextDocumentEditor; checkpoint: string = "word") =
editor_text_redo_void_TextDocumentEditor_string_impl(self, checkpoint)
proc addNextCheckpoint*(self: TextDocumentEditor; checkpoint: string) =
editor_text_addNextCheckpoint_void_TextDocumentEditor_string_impl(self,
Expand Down
4 changes: 2 additions & 2 deletions scripting/editor_text_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ proc unindent*(self: TextDocumentEditor) =

proc editor_text_undo_void_TextDocumentEditor_string_wasm(arg: cstring): cstring {.
importc.}
proc undo*(self: TextDocumentEditor; checkpoint: string = "move") =
proc undo*(self: TextDocumentEditor; checkpoint: string = "word") =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
Expand All @@ -552,7 +552,7 @@ proc undo*(self: TextDocumentEditor; checkpoint: string = "move") =

proc editor_text_redo_void_TextDocumentEditor_string_wasm(arg: cstring): cstring {.
importc.}
proc redo*(self: TextDocumentEditor; checkpoint: string = "move") =
proc redo*(self: TextDocumentEditor; checkpoint: string = "word") =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
Expand Down
8 changes: 6 additions & 2 deletions src/text/text_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,11 @@ proc undo*(self: TextDocument, oldSelection: openArray[Selection], useOldSelecti
if self.undoOps.len == 0:
return

result = some @oldSelection

while self.undoOps.len > 0:
let op = self.undoOps.pop
result = self.doUndo(op, oldSelection, useOldSelection, self.redoOps).some
result = self.doUndo(op, result.get, useOldSelection, self.redoOps).some
if untilCheckpoint.len == 0 or untilCheckpoint in op.checkpoints:
break

Expand Down Expand Up @@ -1041,9 +1043,11 @@ proc redo*(self: TextDocument, oldSelection: openArray[Selection], useOldSelecti
if self.redoOps.len == 0:
return

result = some @oldSelection

while self.redoOps.len > 0:
let op = self.redoOps.pop
result = self.doRedo(op, oldSelection, useOldSelection, self.undoOps).some
result = self.doRedo(op, result.get, useOldSelection, self.undoOps).some
if untilCheckpoint.len == 0 or (self.redoOps.len > 0 and untilCheckpoint in self.redoOps.last.checkpoints):
break

Expand Down

0 comments on commit f88653c

Please sign in to comment.