summaryrefslogtreecommitdiff
path: root/src/normal.cc
AgeCommit message (Collapse)Author
2023-05-21Add <c-g> to cancel current operationMaxime Coste
The current implementation only does this during regex operations, but should be extensible to other operations that might take a long time by regularly calling EventManager::handle_urgent_events().
2023-05-10Merge remote-tracking branch 'krobelus/fix-_-at_multibyte_chars'Maxime Coste
2023-05-09Stop _ from tearing multibyte UTF-8 sequencesChris Webb
Fixes #4887 [ja: add test]
2023-05-09Map undo selection change to <a-u>/<a-U>Johannes Altmanninger
Change the initial <c-h>/<c-k> bindings to the recently freed-up <a-u></a-U>. Pros: - easier to remember - the redo binding is logical. - works on legacy terminals, unlike <c-h> Cons: - It's less convenient to toggle between selection undo and redo keys. I think this is okay since this scenario does not happen that often in practice.
2023-04-17Switch undo storage from a tree to a plain listOlivier Perret
Whenever a new history node is committed after some undo steps, instead of creating a new branch in the undo graph, we first append the inverse modifications starting from the end of the undo list up to the current position before adding the new node. For example let's assume that the undo history is A-B-C, that a single undo has been done (bringing us to state B) and that a new change D is committed. Instead of creating a new branch starting at B, we add the inverse of C (noted ^C) at the end, and D afterwards. This results in the undo history A-B-C-^C-D. Since C-^C collapses to a null change, this is equivalent to A-B-D but without having lost the C branch of the history. If a new change is committed while no undo has been done, the new history node is simply appended to the list, as was the case previously. This results in a simplification of the user interaction, as two bindings are now sufficient to walk the entire undo history, as opposed to needing extra bindings to switch branches whenever they occur. The <a-u> and <a-U> bindings are now free. It also simplifies the implementation, as the graph traversal and branching code are not needed anymore. The parent and child of a node are now respectively the previous and the next elements in the list, so there is no need to store their ID as part of the node. Only the committing of an undo group is slightly more complex, as inverse history nodes need to be added depending on the current position in the undo list. The following article was the initial motivation for this change: https://github.com/zaboople/klonk/blob/master/TheGURQ.md
2023-03-13Fix crash when pasting at buffer endMaxime Coste
Fixes #4844
2023-03-11Make linewise bracketed paste match P behaviorJohannes Altmanninger
This is experimental. Testing will reveal if this is the desired behavior.
2022-12-27Share logic for undo/redo selection changesJohannes Altmanninger
I will suggest a few changes to this code. No functional change.
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-10-19Refactor insert_output command to avoid intermediate vectorMaxime Coste
This is like a paste with a different source, so the same logic should work. This means we now correctly fix overflowing selections. Fixes #4750
2022-10-11Correct and unify descriptions of normal mode C key behaviorJakub Wasilewski
Fixes #4747
2022-09-09Merge remote-tracking branch 'krobelus/to-string'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-29Pass entire context to select_coordJohannes Altmanninger
This allows a following commit to record selection history inside select_coord() instead of at every call site.
2022-08-29Make parameter constJohannes Altmanninger
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-08-05uniquify selection contents before generating regex for '*'Maxime Coste
Avoid generating regex with the same alternative repeated multiple times.
2022-08-01Do not record prompt history when executing user mode mappingsJohannes Altmanninger
Commit 217dd6a1d (Disable history when executing maps, 2015-11-10) made it so with map global normal X %{:echo 123<ret>} X does not add to prompt history (%reg{:}). Unfortunately this behavior was not extended to mappings in the "user" keymap, nor to mappings in custom user modes. In my experience, not adding to history is almost always the expected behavior for mappings. Most users achieve this by adding a leading space: map global user X %{: echo 123<ret>} but that's awkward. We should have good defaults (no nnoremap) and map should work the same way across all modes. Fix this by also disabling history when executing user mappings. This is a breaking change but I think it only breaks hypothetical scenarios. I found some uses where user mappings add to history but none of them looks intentional. https://github.com/Delapouite/dot-in-the-sky/blob/f702a641d119fba558c06b24e5aba0ac73269076/.config/kak/kakrc#L169 https://github.com/mawww/config/blob/604ef1c1c2f4722505d3d29a4fc95e763a1fddbb/kakrc#L96 https://github.com/SolitudeSF/dot/blob/d22e7d6f681091fc3737fe460802f6d818bb7d18/kak/kakrc#L71 https://grep.app/search?q=map%20%28global%7Cbuffer%7Cwindow%29%20user%20.%2A%5B%21%3A/%5D%5B%5E%20%5D.%2A%3Cret%3E&regexp=true
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-07-05Move user mappings to <space> and keep/remove selection to ,Maxime Coste
2022-07-05Select pasted text on pasteMaxime Coste
This is more consistent with the recently changed ! and <a-!> behaviour
2022-07-05Make `x` just select the full linesMaxime Coste
`x` is often criticized as hard to predict due to its slightly complex behaviour of selecting next line if the current one is fully selected. Change `x` to use the previous `<a-x>` behaviour, and change `<a-x>` to trim to fully selected lines as `<a-X>` did. Adapt existing indentation script to the new behaviour
2022-05-26Fix indent commands not being committed as an undo groupMaxime Coste
2edabde9193d301ed0db14ac967d8b5503af7d8c removed the ScopedEdition that took care of committing the undo group after indenting operations.
2022-04-11Code style cleanups around object selection codeMaxime Coste
2022-03-06src: Select the data inserted by `!` and `<a-!>`Frank LENORMAND
Closes #1468
2022-01-24Do not insert any end-of-line when piping data outMaxime Coste
This will unfortunately break some use case which will require using wrapper scripts to add the necessary newline. It is however harder to do the contrary, and it makes a lot of other use case possible, such as checksuming. Fixes #3669
2022-01-23Restore goto case insensitiveness, refuse to map upper caseMaxime Coste
After a while it seems clear changing this is much more ergonomic and restoring it with pure config is impractical as we need to map all lower case keys.
2021-12-20Fix invalid line joining logic with multiple selection per lineMaxime Coste
Fixes #4476
2021-12-11Make space a named key to correctly handle shift modifierMaxime Coste
2021-11-11Recognize both <tab> and <c-i> as forward jumpMaxime Coste
Now that Kakoune opts into extended key reporting, <c-i> is correctly reported and hence needs to be mapped to forward jump. We still need to keep <tab> mapped to it for legacy terminals. Should fix #4333
2021-11-01Fix pasting all from empty registerMaxime Coste
Raise an error if the register is empty for paste-all Fixes #4414
2021-10-24src: Make `gf` open all selected pathsFrank LENORMAND
The buffer whose path is under the main selection will be focused after all others have been opened. Closes #2164
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-10-09Merge remote-tracking branch 'lenormf/fix-1840'Maxime Coste
2021-10-06src: Remove spurious `break`Frank LENORMAND
2021-10-06Merge remote-tracking branch 'lenormf/fix-3976'Maxime Coste
2021-09-30Merge remote-tracking branch 'lenormf/fix-4353'Maxime Coste
2021-09-30rework selection insert/replace using a for_each methodMaxime Coste
expose that method so that various commands can take advantage of it for performance or simplicity purposes.
2021-09-15src: Error out on unmapped key in `g` and `v`Frank LENORMAND
Fixes #4353.
2021-09-14src: Make `g` and `v` case sensitiveFrank LENORMAND
The current implementation allows users to declare mappings in the `goto` and `view` modes with uppercase letters, but doesn't consider case to be meaningful. This quirk is also inconsistent as hitting an unmapped key will quit the mode menu without complaints, but hitting a key that isn't in it will work if it has a lowercase mapping equivalent. Fixes #3976
2021-08-30Do not go through some temporary selections for indent/deindentMaxime Coste
This does not seem necessary and simplifies the logic
2021-08-30Take a function SelectionList::insert to get string to insertMaxime Coste
This makes it unnecessary to allocate Vector<String> to insert and allows to remove the insert_pos pointer hack by passing it to the callback.
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-06-13Fix typosTaupiqueur
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
2020-12-03Throw no_selections_remaining when using <a-space>Olivier Perret
This makes it possible to use the mechanism introduced by 91386a53