Commit Graph

322 Commits

Author SHA1 Message Date
Maxime Coste
699c70ac91 Add some missing ScopedEdition and fix redo
tabs <-> space conversion functions did not create a ScopedEdition
leading to uncommited modifications. Fixing this did fix the
interactive error, but that error still existed in non interactive
context so redo now considers there there is no redo child if there
are uncommited modifiations (which is correct as this means we are
currently creating a new leaf in the undo tree)

Fixes #5124
2024-03-23 20:07:41 +11:00
Maxime Coste
dbda8d6dc8 Ensure ReadOnly buffer flag get reflected to readonly option
Fixes #5110
2024-03-04 09:01:19 +11:00
Maxime Coste
3d5a0c672e Templatize StringData::create
This improves performance by letting the compiler optimize most use
cases where string count and length are known are compile time.
2024-02-28 19:02:29 +11:00
Maxime Coste
5ea5c99c58 Fix using invalid strings for undo content strings
The code was wrongly using the write_it instead of the read_it to
access the removed lines content.

Fixes #5088
2024-01-21 10:24:08 +11:00
Maxime Coste
43e8aadcaa Fix performance of diff-based reloading of buffers
It turns out diffing was pretty fast, but applying the diff was
sub-optimal as it was constantly inserting/erasing lines which
led to lots of unnecessary shifting. Fix this by manually tracking
a read/write iterator and only shifting when necessary (on keeps,
and inserts).
2023-12-26 21:21:01 +11:00
Maxime Coste
e06e409dc1 Another small structured binding conversion 2023-06-21 17:36:33 +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
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
potatoalienof13
293d46837d Fix Buffer::advance out of bounds access.
This commit fixes a bug in Buffer::advance where it would first access
m_lines[-1], and then check whether or not that access would have
segfaulted.  This commit moves the check to before the segfault would
occur.
2022-12-22 17:34:42 -05:00
Maxime Coste
20278ed52b Support adding ByteCount to void/char pointers without casting 2022-12-15 13:29:45 +11:00
Maxime Coste
df79d0c245 Distinguish between non-eol max column target and plain max column 2022-07-05 08:43:40 +10:00
Maxime Coste
4c7c4a1454 Simplify Buffer::do_insert and Buffer::do_erase 2022-05-20 08:30:43 +10:00
Maxime Coste
30c05e83f8 Remove unnecessary workaround in Buffer::insert 2022-02-22 08:28:33 +11:00
Maxime Coste
e4a23a64fa Support opening files bigger than 2 GiB
The real technical limit is with lines bigger than 2 GiB and buffers
with more than 2 Gi lines, refactor buffer loading to make it possible
to load those files.

Fix an overflow with the hash_data function at the same time
2021-05-28 17:03:41 +10:00
Maxime Coste
f75d49e9ef Do not include non-primitive option value in *SetOption hook filter
Only include the value for int/str/bool options, for the rest just
write '<option name>=...'.

This should reduce the cost of some patterns such as repeatedly adding
a value inside a list option.

It seems very unlikely that the actual value would be matched by
a hook regex string for non primitive types.
2020-06-09 21:38:47 +10:00
Maxime Coste
3c265acd6c Remove posB from information given by the diff algorithm
posB is always the sum of previous add len and previous keep len,
so very easy to keep track of.
2020-03-20 20:27:50 +11:00
Jason Felice
b03b51d27a Add 'history' and 'uncommitted_modifications' expansions 2020-01-01 19:47:29 -05:00
Maxime Coste
a3445232a4 Update fs status post buffer write 2019-12-19 13:39:30 +11:00
Maxime Coste
b68490ef11 Cleanup replaced range selection logic
Do not access Buffer::m_changes to find the inserted range, return
it directly from Buffer::insert and Buffer::replace. This fixes a
wrong behaviour where replacing at eof would lose the selected end
of line (as the implementation does not actually replace that end
of line)
2019-12-18 11:36:17 +11:00
Maxime Coste
42094209fd Update New flag and last save timestamp on buffer rename
Fxies #3244
2019-12-07 15:40:55 +11:00
Maxime Coste
5c5d881c11 Merge remote-tracking branch 'lenormf/reload-buffer-hash' 2019-12-04 21:14:15 +11:00
Frank LENORMAND
e1bd076f5e src: Reload buffers when their contents' hash changes
Instead of triggering a reload event when the timestamp of a buffer's
underlying file changes, do so when its contents are actually modified.
2019-12-03 17:05:24 +01:00
Maxime Coste
4fdbf21ff8 Refactor diff to make allocating a diff vector optional
The diff interface now goes through a for_each_diff function that
uses a callback for each found diff.
2019-11-30 11:29:36 +11:00
Frank LENORMAND
7512f5eae6 src: Use begin() to get iterators
When compiling the code with `-Wp,-D_GLIBCXX_ASSERTIONS`, the process
gets aborted, likely because iterators to standard containers are
not obtained in a safe way.

Fixes #3226.
2019-11-25 11:34:39 +01:00
Jason Felice
d26bb0ce2b Add static or const where useful 2019-11-09 12:53:45 -05:00
Maxime Coste
8b2906a14d Refactor option_to_string quoting support, introduce Quoting::Raw 2019-06-19 23:04:16 +10:00
Delapouite
947e071066 Let parse_lines ensure that there's at least 1 line with \n 2019-04-27 19:29:16 +02:00
Delapouite
0fe8e59abc Add missing flags to debug buffers output 2019-03-27 19:30:41 +01:00
Maxime Coste
370d10ccc7 Always select inserted text after piping
Relying on general selection update code is error prone due to
diffing.

Fixes #2394
2019-01-23 20:14:08 +11:00
Maxime Coste
dfc11d1c43 Refactor Hook management to have a well defined list of hooks
Hooks are now an enum class instead of passing strings around.
2018-10-23 08:15:53 +11:00
Maxime Coste
68aba9e353 Use shell specific quoting for env vars
Add a test case to validate roundtrips between Kakoune and the
shell.
2018-08-29 07:53:59 +10:00
Maxime Coste
d4e36958f8 Gather options in a vector when running Buffer::on_option_changed
on_option_changed might trigger hooks that will mutate the option
managers, invalidating the iterators we use.
2018-05-21 20:07:25 +10:00
Maxime Coste
75eb293f98 Rename Context::Flags::Transient to Context::Flags::Draft
Draft is well establish and all draft context are transient.
2018-05-14 08:23:00 +10:00
Maxime Coste
74f90c1fc5 Refactor buffer undo tree
Store the undo tree as an array of undo nodes, instead of as a
pointer based tree.
2018-05-02 22:34:55 +10:00
Delapouite
cb02186c77 Make error messages more consistent 2018-04-06 16:56:53 +02:00
Maxime Coste
bfaf52f8c0 Do not jump to buffer start on g. with no previous modifications 2018-03-13 14:00:57 +11:00
Maxime Coste
9125b01fa8 Detect no-op replaces and do not act on them
This avoids recording no-op undo groups.
2018-03-09 23:07:05 +11:00
Maxime Coste
2a60af25dc Allow l/h to cross line boundaries
l and h are now respectively "next character" and "previous character"
2018-02-24 23:16:39 +11:00
Maxime Coste
10c6c59a26 Buffer: avoid expensive option flattening in on_registred with NoHooks 2018-02-18 14:48:24 +11:00
Maxime Coste
66fe2d84da Refuse modification of ReadOnly buffers and make Debug buffer readonly
The debug buffer is a bit special as lots of events might mutate it,
permitting it to be modified leads to some buggy behaviour:

For example, `pipe` uses a ForwardChangeTracker to track buffer
changes, but when applied on a debug buffer with the profile flag
on, each shell execution will trigger an additional modification
of the buffer while applying the changes, leading to an assertion
failing as changes might not be happening in a forward way anymore.

Trying to modify a debug buffer will now raise an error immediatly.
2018-02-11 13:06:19 +11:00
Maxime Coste
eeacb8b5a8 Use the _str and _sv string literals more often 2018-01-18 09:00:54 +11:00
Maxime Coste
d45f16b6c8 Buffer: change clamp logic to preserve ordering
clamp could change ordering between a coordinate past the end.

Say in a buffer with 1 line of 2 char:
{0, 1} was clamped to {0, 1}
{1, 0} was clamped to {0, 0}

That was reversing their ordering, and might be the root cause
of the bug lurking in undo range computation.
2017-11-07 23:56:24 +08:00
Maxime Coste
e66a5c78ad Make Buffer::Modification an aggregate 2017-09-01 17:32:03 +07:00
Maxime Coste
ab6a999431 Rename containers.hh to ranges.hh (and Container to Range) 2017-08-29 15:23:03 +07:00
Maxime Coste
fc64369f9d Purge history on buffer reload when NoUndo flag is on
We were preserving the history in that case, so on fifo buffers
(that set the NoUndo flag until the fifo is closed), we still had
the history from the "previous life" of the buffer, leading crashes
when trying to apply it.

Fixes #1518
2017-08-04 11:39:28 +07:00
Maxime Coste
53e1d2f0de Slight formatting tweak 2017-08-01 14:48:45 +07:00
Maxime Coste
cc946764ed Consider non-files buffers as never modified 2017-06-28 06:48:24 +01:00
Maxime Coste
475e8849a1 Fix replacing last eol with a single eol 2017-06-26 16:16:46 +01:00
Maxime Coste
fa4b88c2f8 Move tolerance for one past end of line coordinates to highlighter code
The rest of Kakoune's code now requires coord passed to Buffer::iterator_at
to be valid.
2017-06-15 17:43:18 +01:00
Maxime Coste
e6c4bed42b Go back to window lines ending at one past the end of the buffer line
Change Buffer::iterator_at so that this case is tolerated, and fixes
the coord to next line start instead of clamping to last line char.
2017-06-15 17:25:37 +01:00