Commit Graph

527 Commits

Author SHA1 Message Date
Maxime Coste
2d9c84e363 Another try to fix blame-jump-message test flakyness 2024-02-18 19:00:33 +11:00
Maxime Coste
150ea50391 Remove unused -within-next ui_out switch 2024-02-18 15:46:24 +11:00
Johannes Altmanninger
f786fceb73 Fix flaky blame-jump-message test
This test fails occasionally[1] because the order of events and the
number of events varies across runs.

We should always call draw_status exactly 3 times:

                        [*git*][fifo]
                        [*git*]
    Commit subject etc. [*git*]

Let's check it this way.
This seems to work; this time I took the time to run it a couple
hundred times and in Cirrus CI.

[1] https://builds.sr.ht/~mawww/job/1151239
2024-02-18 15:45:03 +11:00
Johannes Altmanninger
5f0729f155 rc tools git: fix initial position of blame of deleted line
When running git blame in a "git show" buffer, we annotate the youngest
version of the file that has the line referenced by the diff line
at cursor.
In case the cursor is on an added or context line, we simply show
the version from the surrounding commit.

When the cursor is on a deleted line, we show the parent commit,
which still has the deleted line.  However there is a bug: we use
the line number in the new version of the file. Fix that.
2024-02-18 10:15:03 +11:00
Johannes Altmanninger
a85b81e08a test tools patch: disable when perl is missing
This failed on freebsd_gcc task in
Cirrus because Perl is not installed, see
https://github.com/mawww/kakoune/pull/5101/checks?check_run_id=21604156722
2024-02-18 10:05:55 +11:00
Johannes Altmanninger
7a86602ff8 Fix edit-fifo-noscroll test on BSD
This has been failing on FreeBSD sourcehut CI, for example
https://builds.sr.ht/~mawww/job/1151241
2024-02-18 09:58:53 +11:00
Johannes Altmanninger
e1fd2351e0 rc git.kak: fix blame-jump for commits with special characters
Commit 53d9b9b67 (Escaping tweak in git.kak, 2024-02-06) broke
blame-jump when the commit subject contains a single quote.
(Also on unbalanced "{" which is a rare edge case but we already have
it in our Git history.)
git.kak assumes that filenames don't contain ' or unbalanced {,
but we can't really make that assumption about people's names or
commit subjects.

Unfortunately the escaping here is very messy. We need to pass
arbitrary text to callbacks; maybe we should have closures that can
capture private temporary registers.
2024-02-13 19:24:24 +11:00
Johannes Altmanninger
582c3c56b2 Do not add trailing newline to non-scrolling fifo buffers
Internally, all lines have a trailing "\n".
Buffers created empty (like fifo buffers) start with a single line.

When reading data into fifo buffers, we insert *before* the last line's
trailing newline ("last newline").  This enables autoscrolling (enabled
with "edit -scroll") as long as the cursor is on the last newline.

When autoscrolling is disabled, we have a special case to insert
*after* the last newline.  This means that a cursor on that newline
won't be moved.  Then we transplant the newline character from the
beginning to the end of the buffer. This special case happens only on
the very first fifo read; on subsequent reads, the cursor at position
1.1 will not be moved anway because insertions happen below 1.1.

Since we always insert (effectively) before the last newline, fifo
buffers have a trailing empty line.

For autoscrolling buffers this seems correct; it gives users an
obvious way to toggle autoscrolling.

For non-scrolling buffers the newline is redundant.  Remove it.
This requires keeping track of whether the last newline comes from
the fifo, or was added by us.  The shortest fix I could find
is to always append to the buffer if not scrolling, and then delete
the added newline character if applicable.

    m_buffer.insert(m_scroll ? pos : m_buffer.next(pos), StringView(data, data+count));
    if (not m_scroll and not m_had_trailing_newline)
        m_buffer.erase(pos, m_buffer.next(pos));

maybe that's the best fix overall; but erasing at the end seems better
than erasing in the middle, so do that whenever possible.

Reported in https://lists.sr.ht/~mawww/kakoune/%3CZbTK7qit9nzvrMkx@gmail.com%3E
2024-01-30 08:24:27 +11:00
Johannes Altmanninger
fdbad4d9b2 Test to demonstrate fifo buffer blank line inconsistency
When "edit -fifo" reads data without a trailing newline, the fifo
buffer will not have a trailing blank line. But if there is a trailing
newline, we will get a trailing blank line. This is weird because the
trailing blank line exists for scrolling, it should not be determined
by the data read.

Add a test case to demonstrates the inconsistency which is fixed by
the next patch.
2024-01-30 08:23:59 +11:00
Johannes Altmanninger
11e7e2964c rc tools patch: skip patch message signature, fixing diff application
Patches as produced by "git format-patch" have a trailing signature
that is separated from the body by a line with "-- " on it.  By default
it contains the Git version.  We erroneously include this signature
in the diff we pipe to patch, which fails to apply as a result.

Add a targeted fix to suppress these signatures.
2024-01-26 09:55:52 +11:00
Johannes Altmanninger
1276e67ef7 rc tools patch: skip spurious diff header for files with no changes
Since :patch transforms its inputs into context-only lines, we can
easily get into a state where a file diff has only context lines.
git apply does not accept a "diff" without any hunk, so let's skip
that.
2024-01-22 07:02:31 +01:00
Johannes Altmanninger
20b0eadfc8 Don't modify prompt history when validating empty input
Fixes #5076
2024-01-15 15:08:10 +01:00
Johannes Altmanninger
9d8c9777a4 Await all UI events after each key press in mouse-during-insert test
This test doesn't care about testing things like "if I send the next
key before we have finished reacting to the previous ones, nothing
bad ever happens".

Hence we can until exhaustion after each input.  This should fix
bespoke flakiness. The handling of "c<esc>" should be atomic.

This reasoning probably applies to most tests; waiting for all events
seems like the safest and easiest approach overall (compared to sleep
or sleep-until). The downside is that the tests need changes when
UI code changes but it rarely does, and if it does we can automate
the updates.

Closes #5073
2024-01-15 15:08:10 +01:00
Maxime Coste
9b166e8007 Try to fix regression/0-mouse-during-insert test flakyness 2024-01-05 15:39:30 +11:00
Maxime Coste
11f0ace9b6 Make shell-script-candidates completer run in the background
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-14 21:39:03 +11:00
Johannes Altmanninger
c597a056d0 Fix spurious incremental search when incsearch=false
Regressed in a2c41593a (Fix partial regex text being pushed in history,
2023-11-02).
2023-11-11 14:37:32 +01:00
Johannes Altmanninger
8a3613e5a0 Fix "%val{selections_desc}" being joined by nul instead of space
This should fix a bug in lint.kak though I didn't check.
2023-11-03 06:45:02 +01:00
Maxime Coste
a2c41593aa Fix partial regex text being pushed in history 2023-11-02 13:00:12 +11:00
Maxime Coste
b020922e6f Fix some corner cases in c-family indentation 2023-10-25 12:51:16 +11:00
Maxime Coste
20a2bca52e Do not make cursor visible after mouse scrolling and view commands
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-09-02 12:55:57 +10:00
Maxime Coste
cd4a695f41 Add regression test for #4959
Thanks @krobelus
2023-08-27 08:12:58 +10:00
Maxime Coste
9c0c6b8fd5 Revert "Only make cursor visible after buffer or selection change"
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 1e38045d70.

Closes #4963
2023-08-23 14:13:22 +10:00
Maxime Coste
1e38045d70 Only make cursor visible after buffer or selection change
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-08-16 21:02:42 +10:00
Maxime Coste
6942a4c0c9 Change + command not to duplicate identical selections more than once
The current exponential behaviour does not seem that useful, it seems
more predictible that pressing `+` twice would end up with 3 copies
of the original selections instead of 4.

Fixes #4533
2023-08-14 22:50:22 +10:00
Maxime Coste
39be51b55c Fix regression/0-mouse-during-insert test flakyness
Do not rely on timing but wait for Kakoune to redraw which is what
we actually need: Mouse clicks rely on the current display buffer
to resolve the buffer location, so we need to wait for a redraw
to happen with `ui_out`
2023-08-05 10:58:15 +10:00
Johannes Altmanninger
12310418b0 Allow map/unmap during mapping execution
Commits e49c0fb04 (unmap: fail if the mapping is currently executing,
2023-05-14) 42be0057a (map: fail if key is currently executing,
2023-06-24) fixed potential use-after-free issues. By doing so,
it broke configurations that in practice have not triggered any
crashes [1] [2].

For example with,

	set -remove global autocomplete insert
	hook global InsertCompletionShow .* %{
	    map window insert <esc> <c-o>
	}
	hook global InsertCompletionHide .* %{
	    unmap window insert <esc> <c-o>
	}

The execution of the <esc> mapping triggers InsertCompletionHide fails
at unmapping. This seems legit and I don't see an obvious alternative
way to write it (InsertIdle would not be correct though it would work
in practice).

Fix the regression by allowing map and unmap again while keeping the
mappings alive until they have finished executing.

Applying map/unmap immediately seems like the most obvious semantics.
Alternatively, we could apply them in between key presses.

[1]: <https://github.com/kak-lsp/kak-lsp/issues/689>
[2]: <https://github.com/alexherbo2/auto-pairs.kak/issues/60>
2023-07-20 09:18:23 +02:00
Johannes Altmanninger
42be0057a6 map: fail if key is currently executing
If during execution of a mapping, that same mapping is replaced,
there is undefined behavior because we destroy a mapping that we are
still iterating over.

I have been using this mapping inside my kakrc to re-source the kakrc.

	map global user s %{:source "%val{config}/kakrc"<ret>} -docstring 'source "%val{config}/kakrc"'

Now <space>s happens to not trigger undefined behavior because the
mapping stays the same.

However it triggers an assertion added by Commit e49c0fb04 (unmap:
fail if the mapping is currently executing, 2023-05-14), specifically
the destructor of ScopedSetBool that guards mapping execution.

Fix these by banning map of a key that is executing, just like we
did for unmap.

Alternative solution: we could allow mapping (and even unmapping)
keys at any time and keep them alive by moving them into a trash can,
like we do for clients and others.
2023-07-03 19:03:11 +02:00
Maxime Coste
d43268fbeb Fix invalid access of display line end
When a line only contains non-range atoms we can end-up accessing
past the end atom.

Add a test that shows the issue when run with valgrind, it is
unfortunately quite hard to trigger a crash because the invalidly
accessed byte usually leads to the correct code path being taken
(when != DisplayAtom::Range) so we have only 1 in 255 chance of
triggerring a crash.

Fixes #4927
2023-06-20 13:09:03 +10:00
Maxime Coste
e58592f00a Fix highlighters being applied to empty display buffers
In some cases such as with folding we can end-up with regions
not having any atoms to highlight which can trigger a crash as
we assume display buffers not to be empty

Fixes #4926
2023-06-19 12:55:55 +10:00
Maxime Coste
5901d2e06b Revert "Switch undo storage from a tree to a plain list"
Moving across history moved to <c-j>/<c-k> to keep <a-u>/<a-U>
for selection undo/redo

This reverts commit e0d33f51b3.
2023-06-17 17:31:57 +10:00
Maxime Coste
18d4c40f08 Fix c-family closing brace indent behaviour on some corner cases 2023-06-15 17:42:19 +10:00
Johannes Altmanninger
e49c0fb040 unmap: fail if the mapping is currently executing
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-05-25 00:04:23 +02:00
Maxime Coste
3d989af2de Merge remote-tracking branch 'krobelus/fix-crash-connecting-monitor' 2023-05-10 20:03:22 +10:00
Maxime Coste
d39930cd10 Merge remote-tracking branch 'krobelus/fix-_-at_multibyte_chars' 2023-05-10 19:57:46 +10:00
Chris Webb
fc6f32f9ee Stop _ from tearing multibyte UTF-8 sequences
Fixes #4887

[ja: add test]
2023-05-09 23:07:07 +02:00
Johannes Altmanninger
7d2bae63b9 Map undo selection change to <a-u>/<a-U>
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-05-09 11:32:37 +02:00
Johannes Altmanninger
566eb25d7a Give mouse-during-insert more slack on CI, it failed again on macOS 2023-04-24 18:31:05 +02:00
Olivier Perret
e0d33f51b3 Switch undo storage from a tree to a plain list
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-04-17 10:25:51 +02:00
Maxime Coste
019fbc5439 Cleanup and speed up test runner
Add a -end-of-line switch to echo command to make it possible
to use `echo -end-of-line -to-file <file>` to collect env-vars
2023-03-14 09:01:13 +11:00
Maxime Coste
cb3512f01e Grow dual thread stack after pushing a thread on the next queue
The previous code was assuming it was fine to push_next without
growing, which used to be the case with the previous implementation
because we always have poped the current thread that we try to push.

However now that we use a ring-buffer, m_next_begin == m_next_end can
either mean full, or empty. We solve this by assuming it means empty
and never allowing the buffer to become full, which means we need
to grow after pushing to next if we get full.

Fixes #4859
2023-03-13 22:45:19 +11:00
Maxime Coste
81787792d0 Fix crash when pasting at buffer end
Fixes #4844
2023-03-13 21:49:45 +11:00
Maxime Coste
81526e4253 Merge remote-tracking branch 'krobelus/fix-ci' 2023-03-13 21:30:36 +11:00
Maxime Coste
38077ca826 Merge remote-tracking branch 'potatoalienof13/master' 2023-03-09 21:09:43 +11:00
Johannes Altmanninger
0f55d21970 Add sleep to prevent mouse-during-insert test failure
The macOS CI manges to trigger this race.  When it happens the
"c" inserted by the last command is not seen by the test runner.
Let's fix this by adding yet another sleep.
2023-03-05 17:42:41 +01:00
Johannes Altmanninger
45d2d350f2 Disable trim-front-split-glyph test on platforms with broken Unicode support
AKA macOS.
2023-03-05 17:42:41 +01:00
Maxime Coste
afaa47e93f Fix trimming of line front halfway through a double-width glyph
Insert a space to replace the half glyph and ensure the rest of the
line is correctly aligned.

Fixes #4843
2023-02-15 13:04:53 +11:00
Maxime Coste
0630b4f4f6 Fix scroll_window not ensuring cursor lies on a codepoint start
Fixes #4839
2023-02-14 22:00:12 +11:00
Maxime Coste
458e3ef20a Immediately execute ModuleLoaded hooks for already loaded modules
This is trickier than expected because ModuleLoaded hooks can (as
any other hooks) use arbitrary regular expressions for their filter.

Fixes #4841
2023-02-14 21:31:29 +11:00
Maxime Coste
d5ae08498c Merge remote-tracking branch 'krobelus/selection-undo-fix-standstill-after-buffer-change' 2023-01-28 08:29:41 +11:00
Maxime Coste
5097884608 Fix crash in TabulationHighlighter when wrapping just after a tab 2023-01-23 17:39:40 +11:00