Skip to content

Commit

Permalink
updated preferred column when using mouse (fixes #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jan 7, 2024
1 parent 2ab9bc5 commit fcd2f99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions config/absytree_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ when defined(wasm):
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])
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])
# setOption "editor.text.triple-click-command", "extend-select-move"
# setOption "editor.text.triple-click-command-args", %[%"vim-paragraph-inner", %true]
4 changes: 2 additions & 2 deletions src/text/text_editor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ proc showCompletionWindow(self: TextDocumentEditor)
proc refilterCompletions(self: TextDocumentEditor)
proc getSelectionForMove*(self: TextDocumentEditor, cursor: Cursor, move: string, count: int = 0): Selection
proc extendSelectionWithMove*(self: TextDocumentEditor, selection: Selection, move: string, count: int = 0): Selection
proc updateTargetColumn(self: TextDocumentEditor, cursor: SelectionCursor)
proc updateTargetColumn*(self: TextDocumentEditor, cursor: SelectionCursor)

proc clampCursor*(self: TextDocumentEditor, cursor: Cursor): Cursor = self.document.clampCursor(cursor)

Expand Down Expand Up @@ -474,7 +474,7 @@ proc getContextWithMode(self: TextDocumentEditor, context: string): string {.exp
## Appends the current mode to context
return context & "." & $self.currentMode

proc updateTargetColumn(self: TextDocumentEditor, cursor: SelectionCursor) {.expose("editor.text").} =
proc updateTargetColumn*(self: TextDocumentEditor, cursor: SelectionCursor) {.expose("editor.text").} =
self.targetColumn = self.getCursor(cursor).column

proc invertSelection(self: TextDocumentEditor) {.expose("editor.text").} =
Expand Down
8 changes: 8 additions & 0 deletions src/ui/widget_builder_text_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,23 @@ proc renderLine*(
self.selection = (line.index, offset).toSelection
self.dragStartSelection = self.selection
self.runSingleClickCommand()
self.updateTargetColumn(Last)
self.app.tryActivateEditor(self)
self.markDirty()
elif btn == DoubleClick:
let offset = self.getCursorPos(textRuneLen, line.index, startRune.RuneIndex, pos)
self.selection = (line.index, offset).toSelection
self.dragStartSelection = self.selection
self.runDoubleClickCommand()
self.updateTargetColumn(Last)
self.app.tryActivateEditor(self)
self.markDirty()
elif btn == TripleClick:
let offset = self.getCursorPos(textRuneLen, line.index, startRune.RuneIndex, pos)
self.selection = (line.index, offset).toSelection
self.dragStartSelection = self.selection
self.runTripleClickCommand()
self.updateTargetColumn(Last)
self.app.tryActivateEditor(self)
self.markDirty()

Expand All @@ -175,6 +178,7 @@ proc renderLine*(
currentSelection.last
self.selection = (first, newCursor)
self.runDragCommand()
self.updateTargetColumn(Last)
self.app.tryActivateEditor(self)
self.markDirty()

Expand Down Expand Up @@ -215,17 +219,20 @@ proc renderLine*(
self.dragStartSelection = self.selection
self.app.tryActivateEditor(self)
self.runSingleClickCommand()
self.updateTargetColumn(Last)
self.markDirty()
elif btn == DoubleClick:
self.selection = (line.index, self.document.lineLength(line.index)).toSelection
self.dragStartSelection = self.selection
self.runDoubleClickCommand()
self.updateTargetColumn(Last)
self.app.tryActivateEditor(self)
self.markDirty()
elif btn == TripleClick:
self.selection = (line.index, self.document.lineLength(line.index)).toSelection
self.dragStartSelection = self.selection
self.runTripleClickCommand()
self.updateTargetColumn(Last)
self.app.tryActivateEditor(self)
self.markDirty()

Expand All @@ -239,6 +246,7 @@ proc renderLine*(
currentSelection.last
self.selection = (first, newCursor)
self.runDragCommand()
self.updateTargetColumn(Last)
self.app.tryActivateEditor(self)
self.markDirty()

Expand Down

0 comments on commit fcd2f99

Please sign in to comment.