Skip to content

Commit

Permalink
refactored double/triple click handling and improved dragging
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jan 7, 2024
1 parent dd72328 commit 5a03d5f
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 68 deletions.
8 changes: 8 additions & 0 deletions config/absytree_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,11 @@ when defined(wasm):
loadDefaultOptions()
loadDefaultKeybindings()
loadVimLikeKeybindings()

# Triple click to selects a line
setOption("editor.text.triple-click-command", "extend-select-move")
setOption("editor.text.triple-click-command-args", %[%"line", %true])

# Triple click selects a vim paragraph
# setOption("editor.text.triple-click-command", "extend-select-move")
# setOption("editor.text.triple-click-command-args", %[%"vim-paragraph-inner", %true])
Binary file modified config/absytree_config_wasm.wasm
Binary file not shown.
18 changes: 10 additions & 8 deletions config/keybindings_vim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ proc vimMotionParagraphInner*(editor: TextDocumentEditor, cursor: Cursor, count:
dec result.first.line
while result.last.line + 1 < editor.lineCount and editor.lineLength(result.last.line + 1) > 0:
inc result.last.line
result.last.column = editor.lineLength(result.last.line)

result.last.column = editor.lineLength(result.last.line)

proc vimMotionParagraphOuter*(editor: TextDocumentEditor, cursor: Cursor, count: int): Selection =
if editor.lineLength(cursor.line) == 0:
Expand All @@ -73,7 +74,8 @@ proc vimMotionParagraphOuter*(editor: TextDocumentEditor, cursor: Cursor, count:
dec result.first.line
while result.last.line + 1 < editor.lineCount and editor.lineLength(result.last.line) > 0:
inc result.last.line
result.last.column = editor.lineLength(result.last.line)

result.last.column = editor.lineLength(result.last.line)

iterator iterateTextObjects(editor: TextDocumentEditor, cursor: Cursor, move: string, backwards: bool = false): Selection =
var selection = editor.getSelectionForMove(cursor, move, 0)
Expand Down Expand Up @@ -152,6 +154,12 @@ proc moveSelectionEnd(editor: TextDocumentEditor, move: string, backwards: bool

editor.scrollToCursor(Last)

# todo
addCustomTextMove "vim-word", vimMotionWord
addCustomTextMove "vim-WORD", vimMotionWordBig
addCustomTextMove "vim-paragraph-inner", vimMotionParagraphInner
addCustomTextMove "vim-paragraph-outer", vimMotionParagraphOuter

proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
let t = startTimer()
defer:
Expand Down Expand Up @@ -372,12 +380,6 @@ proc loadVimKeybindings*() {.scriptActionWasmNims("load-vim-keybindings").} =
addTextCommand "", "<ESCAPE>", "set-mode", ""
addTextCommand "", "<C-c>", "set-mode", ""

# todo
addCustomTextMove "vim-word", vimMotionWord
addCustomTextMove "vim-WORD", vimMotionWordBig
addCustomTextMove "vim-paragraph-inner", vimMotionParagraphInner
addCustomTextMove "vim-paragraph-outer", vimMotionParagraphOuter

# Text object motions
addTextCommandBlock "", "w": editor.moveSelectionNext("vim-word", allowEmpty=true)
addTextCommandBlock "", "W": editor.moveSelectionNext("vim-WORD", allowEmpty=true)
Expand Down
19 changes: 19 additions & 0 deletions scripting/absytree_internal.nim
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ proc editor_text_getSelectionInPair_Selection_TextDocumentEditor_Cursor_char_imp
proc editor_text_getSelectionInPairNested_Selection_TextDocumentEditor_Cursor_char_char_impl*(
self: TextDocumentEditor; cursor: Cursor; open: char; close: char): Selection =
discard
proc editor_text_extendSelectionWithMove_Selection_TextDocumentEditor_Selection_string_int_impl*(
self: TextDocumentEditor; selection: Selection; move: string; count: int = 0): Selection =
discard
proc editor_text_getSelectionForMove_Selection_TextDocumentEditor_Cursor_string_int_impl*(
self: TextDocumentEditor; cursor: Cursor; move: string; count: int = 0): Selection =
discard
Expand All @@ -218,6 +221,10 @@ proc editor_text_selectMove_void_TextDocumentEditor_string_bool_SelectionCursor_
self: TextDocumentEditor; move: string; inside: bool = false;
which: SelectionCursor = SelectionCursor.Config; all: bool = true) =
discard
proc editor_text_extendSelectMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl*(
self: TextDocumentEditor; move: string; inside: bool = false;
which: SelectionCursor = SelectionCursor.Config; all: bool = true) =
discard
proc editor_text_copyMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl*(
self: TextDocumentEditor; move: string; inside: bool = false;
which: SelectionCursor = SelectionCursor.Config; all: bool = true) =
Expand Down Expand Up @@ -284,6 +291,18 @@ proc editor_text_setSelection_void_TextDocumentEditor_Cursor_string_impl*(
proc editor_text_enterChooseCursorMode_void_TextDocumentEditor_string_impl*(
self: TextDocumentEditor; action: string) =
discard
proc editor_text_runSingleClickCommand_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
discard
proc editor_text_runDoubleClickCommand_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
discard
proc editor_text_runTripleClickCommand_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
discard
proc editor_text_runDragCommand_void_TextDocumentEditor_impl*(
self: TextDocumentEditor) =
discard
proc popup_selector_accept_void_SelectorPopup_impl*(self: SelectorPopup) =
discard
proc popup_selector_cancel_void_SelectorPopup_impl*(self: SelectorPopup) =
Expand Down
13 changes: 13 additions & 0 deletions scripting/absytree_internal_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ proc editor_text_getSelectionInPair_Selection_TextDocumentEditor_Cursor_char_imp
self: TextDocumentEditor; cursor: Cursor; delimiter: char): Selection {.importc.}
proc editor_text_getSelectionInPairNested_Selection_TextDocumentEditor_Cursor_char_char_impl(
self: TextDocumentEditor; cursor: Cursor; open: char; close: char): Selection {.importc.}
proc editor_text_extendSelectionWithMove_Selection_TextDocumentEditor_Selection_string_int_impl(
self: TextDocumentEditor; selection: Selection; move: string; count: int = 0): Selection {.importc.}
proc editor_text_getSelectionForMove_Selection_TextDocumentEditor_Cursor_string_int_impl(
self: TextDocumentEditor; cursor: Cursor; move: string; count: int = 0): Selection {.importc.}
proc editor_text_applyMove_void_TextDocumentEditor_JsonNode_impl(
Expand All @@ -148,6 +150,9 @@ proc editor_text_deleteMove_void_TextDocumentEditor_string_bool_SelectionCursor_
proc editor_text_selectMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl(
self: TextDocumentEditor; move: string; inside: bool = false;
which: SelectionCursor = SelectionCursor.Config; all: bool = true) {.importc.}
proc editor_text_extendSelectMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl(
self: TextDocumentEditor; move: string; inside: bool = false;
which: SelectionCursor = SelectionCursor.Config; all: bool = true) {.importc.}
proc editor_text_copyMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl(
self: TextDocumentEditor; move: string; inside: bool = false;
which: SelectionCursor = SelectionCursor.Config; all: bool = true) {.importc.}
Expand Down Expand Up @@ -194,6 +199,14 @@ proc editor_text_setSelection_void_TextDocumentEditor_Cursor_string_impl(
self: TextDocumentEditor; cursor: Cursor; nextMode: string) {.importc.}
proc editor_text_enterChooseCursorMode_void_TextDocumentEditor_string_impl(
self: TextDocumentEditor; action: string) {.importc.}
proc editor_text_runSingleClickCommand_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_runDoubleClickCommand_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_runTripleClickCommand_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc editor_text_runDragCommand_void_TextDocumentEditor_impl(
self: TextDocumentEditor) {.importc.}
proc popup_selector_accept_void_SelectorPopup_impl(self: SelectorPopup) {.importc.}
proc popup_selector_cancel_void_SelectorPopup_impl(self: SelectorPopup) {.importc.}
proc popup_selector_prev_void_SelectorPopup_impl(self: SelectorPopup) {.importc.}
Expand Down
18 changes: 18 additions & 0 deletions scripting/editor_text_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ proc getSelectionInPairNested*(self: TextDocumentEditor; cursor: Cursor;
open: char; close: char): Selection =
editor_text_getSelectionInPairNested_Selection_TextDocumentEditor_Cursor_char_char_impl(
self, cursor, open, close)
proc extendSelectionWithMove*(self: TextDocumentEditor; selection: Selection;
move: string; count: int = 0): Selection =
editor_text_extendSelectionWithMove_Selection_TextDocumentEditor_Selection_string_int_impl(
self, selection, move, count)
proc getSelectionForMove*(self: TextDocumentEditor; cursor: Cursor;
move: string; count: int = 0): Selection =
editor_text_getSelectionForMove_Selection_TextDocumentEditor_Cursor_string_int_impl(
Expand All @@ -218,6 +222,12 @@ proc selectMove*(self: TextDocumentEditor; move: string; inside: bool = false;
all: bool = true) =
editor_text_selectMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl(
self, move, inside, which, all)
proc extendSelectMove*(self: TextDocumentEditor; move: string;
inside: bool = false;
which: SelectionCursor = SelectionCursor.Config;
all: bool = true) =
editor_text_extendSelectMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl(
self, move, inside, which, all)
proc copyMove*(self: TextDocumentEditor; move: string; inside: bool = false;
which: SelectionCursor = SelectionCursor.Config; all: bool = true) =
editor_text_copyMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_impl(
Expand Down Expand Up @@ -275,3 +285,11 @@ proc setSelection*(self: TextDocumentEditor; cursor: Cursor; nextMode: string) =
proc enterChooseCursorMode*(self: TextDocumentEditor; action: string) =
editor_text_enterChooseCursorMode_void_TextDocumentEditor_string_impl(self,
action)
proc runSingleClickCommand*(self: TextDocumentEditor) =
editor_text_runSingleClickCommand_void_TextDocumentEditor_impl(self)
proc runDoubleClickCommand*(self: TextDocumentEditor) =
editor_text_runDoubleClickCommand_void_TextDocumentEditor_impl(self)
proc runTripleClickCommand*(self: TextDocumentEditor) =
editor_text_runTripleClickCommand_void_TextDocumentEditor_impl(self)
proc runDragCommand*(self: TextDocumentEditor) =
editor_text_runDragCommand_void_TextDocumentEditor_impl(self)
124 changes: 124 additions & 0 deletions scripting/editor_text_api_wasm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,37 @@ proc getSelectionInPairNested*(self: TextDocumentEditor; cursor: Cursor;
result = parseJson($res).jsonTo(typeof(result))


proc editor_text_extendSelectionWithMove_Selection_TextDocumentEditor_Selection_string_int_wasm(
arg: cstring): cstring {.importc.}
proc extendSelectionWithMove*(self: TextDocumentEditor; selection: Selection;
move: string; count: int = 0): Selection =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
argsJson.add block:
when Selection is JsonNode:
selection
else:
selection.toJson()
argsJson.add block:
when string is JsonNode:
move
else:
move.toJson()
argsJson.add block:
when int is JsonNode:
count
else:
count.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_extendSelectionWithMove_Selection_TextDocumentEditor_Selection_string_int_wasm(
argsJsonString.cstring)
result = parseJson($res).jsonTo(typeof(result))


proc editor_text_getSelectionForMove_Selection_TextDocumentEditor_Cursor_string_int_wasm(
arg: cstring): cstring {.importc.}
proc getSelectionForMove*(self: TextDocumentEditor; cursor: Cursor;
Expand Down Expand Up @@ -1401,6 +1432,43 @@ proc selectMove*(self: TextDocumentEditor; move: string; inside: bool = false;
argsJsonString.cstring)


proc editor_text_extendSelectMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_wasm(
arg: cstring): cstring {.importc.}
proc extendSelectMove*(self: TextDocumentEditor; move: string;
inside: bool = false;
which: SelectionCursor = SelectionCursor.Config;
all: bool = true) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
argsJson.add block:
when string is JsonNode:
move
else:
move.toJson()
argsJson.add block:
when bool is JsonNode:
inside
else:
inside.toJson()
argsJson.add block:
when SelectionCursor is JsonNode:
which
else:
which.toJson()
argsJson.add block:
when bool is JsonNode:
all
else:
all.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_extendSelectMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_wasm(
argsJsonString.cstring)


proc editor_text_copyMove_void_TextDocumentEditor_string_bool_SelectionCursor_bool_wasm(
arg: cstring): cstring {.importc.}
proc copyMove*(self: TextDocumentEditor; move: string; inside: bool = false;
Expand Down Expand Up @@ -1805,3 +1873,59 @@ proc enterChooseCursorMode*(self: TextDocumentEditor; action: string) =
let res {.used.} = editor_text_enterChooseCursorMode_void_TextDocumentEditor_string_wasm(
argsJsonString.cstring)


proc editor_text_runSingleClickCommand_void_TextDocumentEditor_wasm(arg: cstring): cstring {.
importc.}
proc runSingleClickCommand*(self: TextDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_runSingleClickCommand_void_TextDocumentEditor_wasm(
argsJsonString.cstring)


proc editor_text_runDoubleClickCommand_void_TextDocumentEditor_wasm(arg: cstring): cstring {.
importc.}
proc runDoubleClickCommand*(self: TextDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_runDoubleClickCommand_void_TextDocumentEditor_wasm(
argsJsonString.cstring)


proc editor_text_runTripleClickCommand_void_TextDocumentEditor_wasm(arg: cstring): cstring {.
importc.}
proc runTripleClickCommand*(self: TextDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_runTripleClickCommand_void_TextDocumentEditor_wasm(
argsJsonString.cstring)


proc editor_text_runDragCommand_void_TextDocumentEditor_wasm(arg: cstring): cstring {.
importc.}
proc runDragCommand*(self: TextDocumentEditor) =
var argsJson = newJArray()
argsJson.add block:
when TextDocumentEditor is JsonNode:
self
else:
self.toJson()
let argsJsonString = $argsJson
let res {.used.} = editor_text_runDragCommand_void_TextDocumentEditor_wasm(
argsJsonString.cstring)

Loading

0 comments on commit 5a03d5f

Please sign in to comment.