diff --git a/config/keybindings_vim.nim b/config/keybindings_vim.nim index 686bb90b..92795efb 100644 --- a/config/keybindings_vim.nim +++ b/config/keybindings_vim.nim @@ -71,6 +71,7 @@ proc vimSelectLast(editor: TextDocumentEditor, move: string, count: int = 1) {.e for i in 0..", "select-next-completion" addTextCommand "completion", "", "apply-selected-completion" - # addTextCommand "normal", "", "vim-select-last " addTextCommand "", "d", """vim-delete-move <#count>""" addTextCommand "", "c", """vim-change-move <#count>""" @@ -837,28 +849,35 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} = addTextCommandBlock "normal", "a": editor.selections = editor.selections.mapIt(editor.doMoveCursorColumn(it.last, 1, wrap=false).toSelection) editor.setMode "insert" + editor.addNextCheckpoint "insert" addTextCommandBlock "", "A": editor.moveLast "line", Both editor.setMode "insert" + editor.addNextCheckpoint "insert" addTextCommandBlock "normal", "i": editor.setMode "insert" + editor.addNextCheckpoint "insert" addTextCommandBlock "", "I": editor.moveFirst "line-no-indent", Both editor.setMode "insert" + editor.addNextCheckpoint "insert" addTextCommandBlock "normal", "gI": editor.moveFirst "line", Both editor.setMode "insert" + editor.addNextCheckpoint "insert" addTextCommandBlock "normal", "o": editor.moveLast "line", Both editor.insertText "\n" editor.setMode "insert" + editor.addNextCheckpoint "insert" addTextCommandBlock "normal", "O": editor.moveFirst "line", Both editor.insertText "\n", autoIndent=false editor.vimMoveCursorLine -1 editor.setMode "insert" + editor.addNextCheckpoint "insert" addTextCommand "", "", "set-mode", "normal" addTextCommand "", "", "set-mode", "normal" @@ -903,13 +922,15 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} = addTextCommandBlock "", "dd": selectLines = true + let oldSelections = editor.selections editor.vimSelectLine() - editor.vimDeleteSelection(true) + editor.vimDeleteSelection(true, oldSelections=oldSelections.some) selectLines = false addTextCommandBlock "", "cc": + let oldSelections = editor.selections editor.vimSelectLine() - editor.vimChangeSelection(true) + editor.vimChangeSelection(true, oldSelections=oldSelections.some) addTextCommandBlock "", "yy": selectLines = true @@ -918,13 +939,15 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} = selectLines = false addTextCommandBlock "", "D": + let oldSelections = editor.selections editor.selections = editor.selections.mapIt (it.last, editor.vimMotionLine(it.last, 0).last) - editor.vimDeleteSelection(true) + editor.vimDeleteSelection(true, oldSelections=oldSelections.some) selectLines = false addTextCommandBlock "", "C": + let oldSelections = editor.selections editor.selections = editor.selections.mapIt (it.last, editor.vimMotionLine(it.last, 0).last) - editor.vimChangeSelection(true) + editor.vimChangeSelection(true, oldSelections=oldSelections.some) selectLines = false addTextCommandBlock "", "Y": @@ -1027,7 +1050,7 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} = addTextCommand "", "", "show-hover-for-current" addTextCommand "", "", "select-prev" addTextCommand "", "", "select-next" - addTextCommand "", "U", "redo" + addTextCommand "", "U", "vim-redo" addTextCommand "", "", "vim-undo" addTextCommand "", "", "vim-redo" addTextCommand "", "", "toggle-line-comment" diff --git a/src/text/text_document.nim b/src/text/text_document.nim index 0295d01a..9f8e95d9 100644 --- a/src/text/text_document.nim +++ b/src/text/text_document.nim @@ -1001,6 +1001,7 @@ proc doUndo(self: TextDocument, op: UndoOp, oldSelection: openArray[Selection], result = op.oldSelection proc undo*(self: TextDocument, oldSelection: openArray[Selection], useOldSelection: bool, untilCheckpoint: string = ""): Option[seq[Selection]] = + # debugf"undo {untilCheckpoint}" result = seq[Selection].none if self.undoOps.len == 0: @@ -1038,6 +1039,7 @@ proc doRedo(self: TextDocument, op: UndoOp, oldSelection: openArray[Selection], result = op.oldSelection proc redo*(self: TextDocument, oldSelection: openArray[Selection], useOldSelection: bool, untilCheckpoint: string = ""): Option[seq[Selection]] = + # debugf"redo {untilCheckpoint}" result = seq[Selection].none if self.redoOps.len == 0: diff --git a/src/text/text_editor.nim b/src/text/text_editor.nim index 36b70def..68cf58a9 100644 --- a/src/text/text_editor.nim +++ b/src/text/text_editor.nim @@ -780,6 +780,9 @@ proc addNextCheckpoint*(self: TextDocumentEditor, checkpoint: string) {.expose(" self.document.addNextCheckpoint checkpoint proc printUndoHistory*(self: TextDocumentEditor, max: int = 50) {.expose("editor.text").} = + for i in countup(0, self.document.redoOps.high): + debugf"redo: {self.document.redoOps[i]}" + debugf"-----" for i in countdown(self.document.undoOps.high, 0): debugf"undo: {self.document.undoOps[i]}"