summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
AgeCommit message (Collapse)Author
2025-07-08Replace on_scope_end with CTAD with OnScopeEnd directlyMaxime Coste
2025-07-08Replace std::unique_ptr with a custom implementationMaxime Coste
<memory> is a costly header we can avoid by just implementing UniquePtr ourselves, which is a pretty straightforward in modern C++, this saves around 10% of the compilation time here.
2025-03-24Fix prompt history recording when using mapped keysJohannes Altmanninger
Commit e3122ab2c (Refactor prompt history handling, 2023-07-05) was a nice simplification but it breaks a rare edge case. It suppresses history recording if all keys the prompt receives were synthesized. That's not quite the right criteria: it means that if prompt is created, edited and and executed, all via mapped keys, we fail to add to history. The criteria should rather be something like "if all keys the prompt receives came from synthesized events". Make it so. This allows us to get rid of the "noninteractive" nested bool that was only used for disabling history.
2025-03-24Default InputHandler::handle_key() synthesized argumentJohannes Altmanninger
We have only one place where we handle actual keys typed by the user.
2025-03-22Improve info box clearing behaviourMaxime Coste
Schedule clearing of the info box from normal mode even if mode was disabled, clear on insert idle as well. Fixes #5300
2025-02-05Make Control modifier quote inserted registers in prompt modeMaxime Coste
It is often usefull to quote the inserted register, like when doing `:grep <c-r>/`, or when pulling selected filenames with `<c-r><a-.>`.
2024-10-22Remove now unused CompletionFlagsMaxime Coste
Since shell-script-completions now runs the script asynchronously and unconditionally, there is no use for the CompletionFlags::Fast anymore which means we can remove that type altogether.
2024-09-16Rename Window::display_position to display_coordMaxime Coste
2024-09-16Do not return beginning of buffer whenever display to buffer coord failsMaxime Coste
Use an empty Optional to show that resolution failed and just do not do anything in the mouse event handler in that case.
2024-09-02Explicitely call try_accept on InsertCompleterMaxime Coste
Calling it as part of the insert method was error prone and often led to slightly surprising behaviour, such as the <c-r><esc> hiding the menu on <esc>.
2024-09-02Fix <c-r> use-after-free InsertCompletionHide touches used registerJohannes Altmanninger
Before performing the insertion, InsertCompleter::insert calls try_accept() to accept any selected completion candidate. If there is one, we fire InsertCompletionHide. If that one modifies the register used by <c-r>, the inserted StringViews will be dangling. Fix this by running try_insert first, and read from the register later. Note that we call try_accept() twice but that's fine. It would probably make more sense to copy the register before calling insert() but I don't think it matters. Closes #5220
2024-08-16include headers cleanupAdrià Arrufat
2024-08-14Merge remote-tracking branch 'enricozb/enricozb/scroll-coordinates'Maxime Coste
2024-08-12Move debug utils to debug.hh/debug.ccMaxime Coste
Lots of code includes buffer_utils.hh just for write_to_debug_buffer which pulls many unnecessary dependencies. Reorganise to reduce compile times.
2024-08-12Move most info/status clear logic to clientMaxime Coste
This makes it possible to remove the pending clears whenever an info/status line is explicitely added, removing a class of race conditions introduced by the previous implementation.
2024-08-08Delay NormalMode clearing of status line and info box to next idleMaxime Coste
A common pattern is for info/echo messages to be generated by idle hooks but the clearing of previous info/echo was done immediately on normal mode events. This led to flickering of the info box especially when a hook was repeatidly generating the same info (like moving a cursor in the same word where the hook reacts to the word under the cursor).
2024-08-06fix mouse scrollingEnrico Zandomeni Borba
2024-07-22Handle word completion when recording macrosMaxime Coste
Make last insert and macro recording closer together, paving the way towards moving last insert to a register. Use a FunctionRef for insert completer key insertion support.
2024-07-19Record macros in repeat last insertMaxime Coste
This fixes an issue with the following hooks: hook global InsertCompletionShow .* %{ map window insert <tab> <c-n> } hook global InsertCompletionHide .* %{ unmap window insert <tab> <c-n> } When repeating a last insert using <tab> to select a completion, it inserts a <tab> instead of selecting, then the insert completion tries to erase the inserted text with backspaces but fails to totally do that as it erases the tab character first.
2024-07-17Clear info box and prompt on pasteMaxime Coste
2024-04-27Don't capture local-scoped faces in promptJohannes Altmanninger
ASan shows that we resolve a face spec owned by a freed stack variable. ================================================================= ==2263300==ERROR: AddressSanitizer: stack-use-after-return on address 0x7a9316c33918 at pc 0x633ea421d8ea bp 0x7ffca001e980 sp 0x7ffca001e970 READ of size 8 at 0x7a9316c33918 thread T0 ... #6 0x633ea421d8e9 in Kakoune::FaceRegistry::resolve_spec(Kakoune::FaceSpec const&) const src/face_registry.cc:128 ... Address 0x7a9316c33918 is located in stack of thread T0 at offset 2328 in frame #0 0x633ea427a095 in operator() src/commands.cc:2267 This frame has 26 object(s): [32, 36) '<unknown>' ... [544, 560) 'disable_hooks' (line 2269) ... [928, 2432) 'local_scope' (line 2271) <== Memory access at offset 2328 is inside this variable
2024-04-01Change mode_info to contain an optional NormalParamsMaxime Coste
As @topisani pointed out in #5131, it is more user friendly to always provide a %val{register} and %val{count} regardless of the mode.
2024-03-31Support exposing some env vars as part of the mode informationMaxime Coste
This should implement what #5131 proposed in a different way. Closes #5131
2024-03-27Do not make cursor visible when not draggingMaxime Coste
Fixes #5130
2024-03-23Refactor last insert recording logicMaxime Coste
Only record non-synthetized insertions, removing the need to re-record on replay and fixing the last replay getting dropped by macro execution. Fixes #5122
2024-03-22Fix invalid access when recording keysMaxime Coste
<c-n>/<c-p> handling in insert was always dropping the last key in the last_insert() vector (in order to replace it with the actual completion text inserted), this was not valid for synthetized keys that are not added to that vector in the first place. Take the opportunity to merge insert completion handling code between <c-n>/<c-p> and direct menu selection. Fixes #5120
2024-02-24Make insert repeat (.) more consistentTobias Pisani
Insert repeat will now only record non-synthesized keys, and when played back execute mappings as well. Constructing some tests, and with the specific goal of fixing https://github.com/alexherbo2/auto-pairs.kak/issues/38, this appeared to be the best approach. Other options could be evaluating the maps only when recording, but this gave other issues (see tests/normal/repeat-insert/repeat-insert-mapped) At this point, repeat-insert may be essentially just a hardcoded macro, at least I haven't identified the difference. If this really is the case, it may make sense to give it a dedicated register, and implement it as a macro. Fixes #3600
2023-12-10Mark refresh_ifn() implementation as an override in input_handler.ccChris Webb
This was spotted by clang's -Winconsistent-missing-override in -Wall.
2023-12-02Merge remote-tracking branch 'krobelus/fuzzy-menu'Maxime Coste
2023-11-21Fix completion menu not getting hidden on no matchesMaxime Coste
2023-11-20rc tools menu: replace menu builtin with a prompt-based implementationJohannes Altmanninger
prompt has fuzzy filtering which is more discoverable than the menu mode's regex filtering (because that one needs / to trigger it). There are no important differences left, so replace the menu builtin with a prompt-based command. prompt does not support markup in the completion menu, so drop that feature for now.
2023-11-14Make shell-script-candidates completer run in the backgroundMaxime Coste
Read output from the script as it comes and update the candidate list progressively. Disable updating of the list when a completion has been explicitely selected.
2023-11-14Fix completion pager not rendering after <a-semicolon> in promptJohannes Altmanninger
Usually, the prompt resets "m_line_changed" after invoking the change handler: if (m_line_changed) { m_callback(m_line_editor.line(), PromptEvent::Change, context()); m_line_changed = false; } but with prompt '' '' -on-change %{ execute-keys <a-semicolon>vl } -shell-script-candidates %{ seq 100 } the change handler pushes a normal mode with "<a-semicolon>" and then hands back control to the event loop. Later when the normal mode is popped we run "Prompt::on_enabled()" but don't actually redraw the completion pager. Since the <a-semicolon> excursion by definition did not change our prompt state, we don't need to recompute completions, only render them. Do that. This helps commands that use preview the selected completion via a "prompt -on-change" handler.
2023-11-13Avoid unnecessary copy of completion candidatesJohannes Altmanninger
2023-11-13Change window_range to emit each element as a separate stringMaxime Coste
2023-09-19Trigger auto completion refresh when necessary on completion selectMaxime Coste
This removes the timing dependent behaviour where `Tab` would only display the completion menu if pressed before the prompt idle timeout This means `exec :dc<tab>` now expands 'dc' to 'define-command' instead of just showing the completion menu a few millis early.
2023-09-02Do not make cursor visible after mouse scrolling and view commandsMaxime Coste
ensure cursor is visible after user input except if the command implementation opted-out. Hooks and timers should not enforce visible cursor. PageUp/PageDown and `<c-f>` / `<c-b>` commands still move the cursor as this seemed a desired behaviour.
2023-08-23Revert "Only make cursor visible after buffer or selection change"Maxime Coste
This is currently broken on various corner cases and breaks the "master branch should be good for day to day work" implicit rule, ongoing work to stabilize this feature will take place on the no-cursor-move-on-scroll branch until its deemed ready. This reverts commit 1e38045d702ec6eb2425016d9b02636270ab1b1e. Closes #4963
2023-08-16Only make cursor visible after buffer or selection changeMaxime Coste
Kakoune now does not touch cursors when scrolling. It checks if either the buffer or selections has been modified since last redraw. Fixes #4124 Fixes #2844
2023-07-05Refactor prompt history handlingMaxime Coste
Share incremental regex logic, pass the synthetized nature of keys through to input handlers.
2023-07-05Merge remote-tracking branch 'krobelus/allow-history-in-mappings'Maxime Coste
2023-07-04Only auto-insert completion when at the end of the lineMaxime Coste
Auto inserting in the middle is annoying more often than not.
2023-06-17Disable history only for prompts that are never shown in the UIJohannes Altmanninger
My terminal allows to map <c-[> and <esc> independently. I like to use <c-[> as escape key so I have this mapping: map global prompt <c-[> <esc> Unfortunately, this is not equivalent to <esc>. Since mappings are run with history disabled, <c-[> will not add the command to the prompt history. So disabling command history inside mappings is wrong in case the command prompt was created before mapping execution. The behavior should be: "a prompt that is both created and closed inside a noninteractive context does not add to prompt history", where "noninteractive" means inside a mapping, hook, command, execute-keys or evaluate-commands. Implement this behavior, it should better meet user expectations. Scripts can always use "set-register" to add to history. Here are my test cases: 1. Basic regression test (needs above mapping): :nop should be added to history<c-[> --- 2. Create the prompt in a noninteractive context: :exec %{:} now we're back in the interactive context, so we can type: nop should be added to history<ret> --- 3. To check if it works for nested prompts, first set up this mapping. map global prompt <c-j> '<a-semicolon>:nop should NOT be added to history<ret>' map global prompt <c-h> '<a-semicolon>:nop should be added to history first' Then type :nop should be added to history second<c-j><c-h><ret><ret> the inner command run by <c-j> should not be added to history because it only existed in a noninteractive context. --- See also the discussion https://github.com/mawww/kakoune/pull/4692 We could automate the tests if we had a test setup that allowed feeding interactive key input into Kakoune instead of using "execute-commands". Some projects use tmux, or maybe we can mock the terminal.
2023-06-17Use auto to avoid repeating type of dynamic castJohannes Altmanninger
I think the clang-tidy lint is called modernize-use-auto
2023-06-17Rename "disable_history" stack state to "noninteractive"Johannes Altmanninger
The commit after next will fix a bug where we wrongly disable prompt history in some scenarios. The root cause is that life span of "disable_history" does not model when we actually want to disable history. Let's rename the state variable to "noninteractive". It's set whenever we are executing a hook, mapping or command. Note that it's also active inside ":prompt"'s callback, which doesn't play well with the new name :(
2023-05-29Refactor KeymapManager to enfore setting is_executing on key iterationMaxime Coste
Add an iterator based remove to HashMap as that was missing. Make KeymapManager responsible for throwing on unmap an executing mapping.
2023-05-25unmap: fail if the mapping is currently executingJohannes Altmanninger
When unmapping a key sequence that is currently executing, we continue executing freed memory which can have weird effects. Let's instead throw an error if that happens. In future we can support unmap in this scenario. Closes #4896
2023-04-22Fix compile error: Compiler refuses to deduce alias template arguments on ↵Sidharth Kshatriya
Darwin (clang 14.0.3) input_handler.cc:1476:16: error: alias template 'ConstArrayView' requires template arguments; argument deduction only allowed for class templates insert(ConstArrayView{content}); ^ input_handler.cc:1522:16: error: alias template 'ConstArrayView' requires template arguments; argument deduction only allowed for class templates insert(ConstArrayView{str}); ^
2023-03-13Slight refactoring of bracketed paste featureMaxime Coste
Handle begin/end paste directly in paste csi, manage paste buffer out of get_char, filter Key::Invalid earlier. get_next_key returning Key::Invalid means there was some input but it could not be represented as a Key. An empty optional means there was no input at all.
2023-03-11Make linewise bracketed paste match P behaviorJohannes Altmanninger
This is experimental. Testing will reveal if this is the desired behavior.