summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
AgeCommit message (Collapse)Author
2023-03-11Implement bracketed pasteJohannes Altmanninger
Text pasted into Kakoune's normal mode is interpreted as command sequence, which is probably never what the user wants. Text pasted during insert mode will be inserted fine but may trigger auto-indentation hooks which is likely not what users want. Bracketed paste is pair of escape codes sent by terminals that allow applications to distinguish between pasted text and typed text. Let's use this feature to always insert pasted text verbatim, skipping keymap lookup and the InsertChar hook. In future, we could add a dedicated Paste hook. We need to make a decision on whether to paste before or after the selection. I chose "before" because that's what I'm used to. TerminalUI::set_on_key has EventManager::instance().force_signal(0); I'm not sure if we want the same for TerminalUI::set_on_paste? I assume it doesn't matter because they are always called in tandem. Closes #2465
2023-02-17Complete arguments to "echo -to-file"Johannes Altmanninger
Including this here because grandparent parent commit broke completions for "edit -fifo".
2023-02-14Fix scroll_window not ensuring cursor lies on a codepoint startMaxime Coste
Fixes #4839
2023-01-08Remove bogus assertions preventing mouse clicks in insert modeJohannes Altmanninger
Recent changes for selection-undo added an assertion that triggers when a mouse-drag overlaps with an insert mode, because both events record selection history. However this is actually fine. The one that finishes last concludes the selection edition, while the other one will be a nop. The test could be simpler (i.e. not require sleeps) but I figured it doesn't hurt add this since we don't have any comparable tests.
2022-11-28Fix pasting after when selections are overlappingMaxime Coste
With overlapping selections, pasting after breaks assumption of SelectionList::for_each as our changes are no longer happening in increasing locations. We hence cannot rely on the ForwardChangeTracker in that case and have to rely on the more general (and more costly) ranges update logic. This interacts poorly with paste linewise pastes and we try to preserve the current behaviour by tracking the last paste position. Overall, this change really begs for overlapping selections to be removed, but we will fix them like that for now. Fixes #4779
2022-11-10Merge remote-tracking branch 'krobelus/undo-selection-change'Maxime Coste
2022-09-02Allow to undo and redo selection changesJohannes Altmanninger
From the issue: > It often happens to me that I carefully craft a selection with multiple > cursors, ready to make changes elegantly, only to completely mess it > up by pressing a wrong key (by merging the cursors for example). Being > able to undo the last selection change (even if only until the previous > buffer change) would make this much less painful. Fix this by recording selection changes and allowing simple linear undo/redo of selection changes. The preliminary key bindings are <c-h> and <c-k>. Here are some other vacant normal mode keys I considered X Y <backspace> <minus> # ^ = <plus> ' unfortunately none of them is super convenient to type. Maybe we can kick out some other normal mode command? --- This feature has some overlap with the jump list (<c-o>/<c-i>) and with undo (u) but each of the three features have their moment. Currently there's no special integration with either peer feature; the three histories are completely independent. In future we might want to synchronize them so we can implement Sublime Text's "Soft undo" feature. Note that it is possible to restore selections that predate a buffer modification. Depending on the buffer modification, the selections might look different of course. (When trying to apply an old buffer's selection to the new buffer, Kakoune computes a diff of the buffers and updates the selection accordingly. This works quite well for many practical examples.) This makes us record the full history of all selections for each client. This seems wasteful, we could set a limit. I don't expect excessive memory usage in practice (we also keep the full history of buffer changes) but I could be wrong. Closes #898
2022-09-02Prepare to record selection changes as perceived by the userJohannes Altmanninger
To be able to undo selection changes, we want to record selections from all commands that modify selections. Each such command will get its own private copy of the selections object. This copy will live until the command is finished executing. All child commands that are run while the command is executing, will also use the same copy, because to the user it's all just one selection change anyway. Add an RAII object in all places where we might modify selections. The next commit will use this to create the private selections copy in the constructor (if there is none) and remove redundant history items in the destructor. We could avoid the RAII object in some places but that seems worse. For lifetimes that don't correspond to a lexical scope, we use a std::unique_ptr. For lambdas that require conversion to std::function, we use std::shared_ptr because we need something that's copyable.
2022-08-17Rename key_to_str() to the more idiomatic to_string()Johannes Altmanninger
This makes the function easier to find for newcomers because to_string() is the obvious name. It enables format() to do the conversion automatically which seems like good idea (since there is no other obvious representation). Of course this change makes it a bit harder to grep but that's not a problem with clang tooling. We need to cast the function in one place when calling transform() but that's acceptable.
2022-07-28Merge remote-tracking branch 'krobelus/support-shift-backspace'Maxime Coste
2022-07-21Remove redundant check for menu bitJohannes Altmanninger
can_auto_insert_completion already requires the menu bit.
2022-07-10Make Shift+Backspace erase a character in insert modeJohannes Altmanninger
Terminals that support CSI u escape codes (like iTerm2, Kitty and foot) allow us to map <s-backspace> independently of <backspace>. Users expect that <s-backspace> does the same as <backspace>, especially when typing ALL_CAPS. Make it so. The first version of 0cf719103 (Make Shift+Space insert a space in insert mode, 2022-02-09) did that already but I later dropped it because I wasn't sure if it's right.
2022-07-05Remove <esc> as end macro recording, Q should be enoughMaxime Coste
Besides being redundant, it is easy to press esc by mistake/habit while recording a macro.
2022-07-05Distinguish between non-eol max column target and plain max columnMaxime Coste
2022-07-05Store HistoryRegisters with most recent entry in frontMaxime Coste
Closes #3105
2022-06-30Insert all register values in prompt after <c-r> when Alt-modifiedMaxime Coste
`<c-r><a-.>` will insert all selections joined by space instead of only the main one as `<c-r>.` would.
2022-06-04Merge remote-tracking branch 'krobelus/shift-space'Maxime Coste
2022-06-04Code style cleanups around insert completerMaxime Coste
2022-05-29Run InsertCompletionHide hook before insertions that close completion menuJohannes Altmanninger
Insert mode completions are accepted by typing any key. For example, if there is a completion "somefunction()", then typing some<c-n>; will insert somefunction(); and then the InsertCompletionHide hook will fire. The hook parameter is a range that contains the entire thing: the actual completion plus the trailing semicolon that closed the completion menu. The [original motivation] for the hook parameter was to support removing text inserted by completion, so we can apply text edits or expand snippets instead. One problem is that we don't want to remove the semicolon. Another problem came up in a discussion about [snippets]: let's say we have a snippet "add" that expands to add(?, ?) where ? are placeholders. After snippet expansion the cursor replaces the first placeholder. If I type "ad<c-n>1" I expect to get "add(1, ?)". If the InsertCompletionHide hook only runs after processing the "1" keystroke, this is not possible without evil hacks. Fix these problems by running InsertCompletionHide when a completion is accepted _before_ inserting anything else into the buffer. This should make it much easier to fully implement [LSP text edits]. I doubt that anyone besides kak-lsp is using the hook parameter today so this should be a low-risk fix. [original motivation]: https://github.com/mawww/kakoune/issues/2898 [snippets]: https://github.com/kak-lsp/kak-lsp/pull/616#discussion_r883208858 [LSP text edits]: https://github.com/kak-lsp/kak-lsp/issues/40
2022-05-01Remove invalid assert in ScopedForceNormal destructorMaxime Coste
commit 90db664635013f6e857ec696403f2164032410a8 introduced logic to handle the case where the mode had been removed, but did not get rid of the assert.
2022-04-16Make Shift+Space insert a space in insert modeJohannes Altmanninger
Terminals that support CSI u escape codes (like iTerm2, Kitty and foot) allow us to map <s-space> independently of <space>. Users expect that <s-space> inputs a space character; make it so. Fixes #4534 Also reported in https://discuss.kakoune.com/t/shift-space-doesnt-send-space-character/2004
2022-04-12Fix crash when deleting a buffer from a user mappingMaxime Coste
Deleting a buffer resets normal mode on all clients that were displaing that buffer, but ScopedForceNormalMode that are used from user mode do not take this possiblity into account on destruction, which leads to deleting the last normal mode from the context, ending up with an empty mode stack. Fixes #3909
2021-12-11Fix mode line inconsistency between normal and insert modesChris Webb
In normal mode, the mode line contains "1 sel" or "n sels (k)" when n > 1, whereas in insert mode, it contains "n sels (k)" even for n == 1. Change the contents in insert mode to match normal mode.
2021-12-11Make space a named key to correctly handle shift modifierMaxime Coste
2021-10-10Split InsertMode into InsertMode and PasteModeMaxime Coste
They are quite different use cases, and this allow moving InsertMode to input_handler.hh which is what uses it. This also cleans up the code as we can get rid of get_insert_pos and rely more on SelectionList::for_each.
2021-08-17Move control character escaping responsibility to the terminal UIMaxime Coste
Fix atom text at display time, allow tabs/eol/etc... in display atoms and escape them just-in-time Fixes #4293
2021-04-30Improve prompt handlingMarkus F.X.J. Oberhumer
As a long time vi user I find it highly irritating that you cannot backspace out of the command prompt.
2021-02-15Add + key to duplicate selections and <a-+> to merge overlapping onesMaxime Coste
This is an experiment and might get reverted if overlapping selections prove too cumbersome. Fixes #4041
2021-01-03Add missing limits includesMaxime Coste
Fixes #4003
2020-12-20Add Timer::disable() to be more explicit than set_next_date(TimePoint::max())Maxime Coste
2020-12-01Avoid potential use after free of the mode nameMaxime Coste
This can be an issue with NextKey that now does not have a static mode name.
2020-12-01Ensure InputModes are kept alive during their idle logicMaxime Coste
Various paths can run arbitrary commands (callbacks, hooks) which could lead to the InputMode being popped off the mode stack, but contrarily to the on_key method, we had no guarantees to be kept alive. Add a keep_alive RefPtr to this to ensure the mode survives till the end. Fixes #3915
2020-11-18Restore auto-select on return, add a flag to disable that for commandsMaxime Coste
Fixes #3849 Again
2020-11-17Revert "Auto-insert prompt menu completions on <ret> if any text was entered"Maxime Coste
Unfortunately this breaks some pretty useful use cases, such as inserting a command ending with a new-line (as it now leads to an addtional command being auto-completed on validation) This reverts commit aab0be529f77f3a8e86185a030838e6d547d0286.
2020-11-01Auto-insert prompt menu completions on <ret> if any text was enteredMaxime Coste
Previously we would only auto-insert if the current token had some text, but this breaks auto-selection of the first match. Fixes #3849
2020-10-20Disable auto-insertion of menu completion when no text was enteredMaxime Coste
This avoids a frustrating behaviour where Kakoune autoinserts the first command name when hitting <space> after a ; in a command line. It also fixes the empty prompt case that was auto-completed instead of executing the default command.
2020-10-19Auto-insert best completion on space for menu completionsMaxime Coste
The menu flag signifies that only the completions are valid arguments, hence it makes sense to auto insert the best one on space. Because full match is always considered the best match in completion ranking, this should always have a reasonable behaviour. This makes it harder to enter a hidden command, but completion can always be disabled via <c-o> or by quoting in those rare cases.
2020-10-19Add support for explicit completion in prompt modeMaxime Coste
2020-07-05Fix selections getting unsorted on scrollMaxime Coste
Fixes #3478
2020-06-28Refactor mouse press/release handling to support 3 buttonsMaxime Coste
Change button to be an additional parameter instead of having separate events for left/right buttons. Fixes #3471
2020-03-15Merge remote-tracking branch 'Anfid/scroll-test'Maxime Coste
2020-02-27Make `on_next_key_with_autoinfo()` respect `idle_timeout`Nicolas Ouellet-Payeur
The prompt and autocomplete normally wait for `idle_timeout` before showing suggestions, however commands like `g`, `v`, or the lead-key show Clippy instantly. This fixes the issue by making `on_next_key_with_autoinfo()` wait for `idle_timeout` before displaying suggestions. Fixes mawww/kakoune#3365 Fixes mawww/kakoune#2066
2019-11-28Update scroll behaviorMikhail Pogretskiy
2019-11-11Add mode information to next-key mode nameMaxime Coste
Currently expose an additional name, the format is up for discussion. Fixes #1855 Fixes #2569 Fixes #2672
2019-10-16Replace ModeChange hooks by ModePush and ModePopMaxime Coste
Remove deprecated InsertBegin, InsertEnd, NormalBegin, NormalEnd hooks. Closes #2545
2019-09-15Allow scrolling while dragging mouseMaxime Coste
Closes #2052
2019-09-07Fix modifiers support with mouse eventsMaxime Coste
2019-08-19Make scrolling speed configurableMaxime Coste
The UI now can send a 'Scroll' key, whose value is the scrolling amount encoded as a signed integer. This replaces the MouseWheelUp and MouseWheelDown keys. The NCursesUI now has a ncurses_wheel_scroll_amount ui_option that controls that amount, it can be negative to swap scrolling direction. Fixes #3045
2019-07-21Slight code cleanup in prompt history handlingMaxime Coste
2019-07-06fix a few typosJoachim Henke