summaryrefslogtreecommitdiff
path: root/src/buffer.cc
AgeCommit message (Collapse)Author
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-05-23Disable BufSetOption hook during buffer registrationMaxime Coste
The hook is manually triggred at the end of registration, by disabling it we avoid the hook being potentially called multiple times due to interaction with other hooks. Fixes #5324
2025-02-04Revert "WIP linked list shared strings"Maxime Coste
This got pushed by accident This reverts commit 2856b99e0914cc7a659977f2b33308cb5b4c9bb7.
2025-01-22WIP linked list shared stringsMaxime Coste
2024-12-03Do not store buffer pointer in BufferIteratorMaxime Coste
This makes BufferIterator smaller and trivially move/copyable
2024-03-23Add some missing ScopedEdition and fix redoMaxime Coste
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-04Ensure ReadOnly buffer flag get reflected to readonly optionMaxime Coste
Fixes #5110
2024-02-28Templatize StringData::createMaxime Coste
This improves performance by letting the compiler optimize most use cases where string count and length are known are compile time.
2024-01-21Fix using invalid strings for undo content stringsMaxime Coste
The code was wrongly using the write_it instead of the read_it to access the removed lines content. Fixes #5088
2023-12-26Fix performance of diff-based reloading of buffersMaxime Coste
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-06-21Another small structured binding conversionMaxime Coste
2023-06-17Revert "Switch undo storage from a tree to a plain list"Maxime Coste
Moving across history moved to <c-j>/<c-k> to keep <a-u>/<a-U> for selection undo/redo This reverts commit e0d33f51b36c9f0be7ae2467dab455d211bbf561.
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
2022-12-22Fix Buffer::advance out of bounds access.potatoalienof13
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-15Support adding ByteCount to void/char pointers without castingMaxime Coste
2022-07-05Distinguish between non-eol max column target and plain max columnMaxime Coste
2022-05-20Simplify Buffer::do_insert and Buffer::do_eraseMaxime Coste
2022-02-22Remove unnecessary workaround in Buffer::insertMaxime Coste
2021-05-28Support opening files bigger than 2 GiBMaxime Coste
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
2020-06-09Do not include non-primitive option value in *SetOption hook filterMaxime Coste
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-03-20Remove posB from information given by the diff algorithmMaxime Coste
posB is always the sum of previous add len and previous keep len, so very easy to keep track of.
2020-01-01Add 'history' and 'uncommitted_modifications' expansionsJason Felice
2019-12-19Update fs status post buffer writeMaxime Coste
2019-12-18Cleanup replaced range selection logicMaxime Coste
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-07Update New flag and last save timestamp on buffer renameMaxime Coste
Fxies #3244
2019-12-04Merge remote-tracking branch 'lenormf/reload-buffer-hash'Maxime Coste
2019-12-03src: Reload buffers when their contents' hash changesFrank LENORMAND
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-11-30Refactor diff to make allocating a diff vector optionalMaxime Coste
The diff interface now goes through a for_each_diff function that uses a callback for each found diff.
2019-11-25src: Use `begin()` to get iteratorsFrank LENORMAND
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-09Add static or const where usefulJason Felice
2019-06-19Refactor option_to_string quoting support, introduce Quoting::RawMaxime Coste
2019-04-27Let parse_lines ensure that there's at least 1 line with \nDelapouite
2019-03-27Add missing flags to debug buffers outputDelapouite
2019-01-23Always select inserted text after pipingMaxime Coste
Relying on general selection update code is error prone due to diffing. Fixes #2394
2018-10-23Refactor Hook management to have a well defined list of hooksMaxime Coste
Hooks are now an enum class instead of passing strings around.
2018-08-29Use shell specific quoting for env varsMaxime Coste
Add a test case to validate roundtrips between Kakoune and the shell.
2018-05-21Gather options in a vector when running Buffer::on_option_changedMaxime Coste
on_option_changed might trigger hooks that will mutate the option managers, invalidating the iterators we use.
2018-05-14Rename Context::Flags::Transient to Context::Flags::DraftMaxime Coste
Draft is well establish and all draft context are transient.
2018-05-02Refactor buffer undo treeMaxime Coste
Store the undo tree as an array of undo nodes, instead of as a pointer based tree.
2018-04-06Make error messages more consistentDelapouite
2018-03-13Do not jump to buffer start on `g.` with no previous modificationsMaxime Coste
2018-03-09Detect no-op replaces and do not act on themMaxime Coste
This avoids recording no-op undo groups.
2018-02-24Allow l/h to cross line boundariesMaxime Coste
l and h are now respectively "next character" and "previous character"
2018-02-18Buffer: avoid expensive option flattening in on_registred with NoHooksMaxime Coste
2018-02-11Refuse modification of ReadOnly buffers and make Debug buffer readonlyMaxime Coste
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-01-18Use the _str and _sv string literals more oftenMaxime Coste
2017-11-07Buffer: change clamp logic to preserve orderingMaxime Coste
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-09-01Make Buffer::Modification an aggregateMaxime Coste
2017-08-29Rename containers.hh to ranges.hh (and Container to Range)Maxime Coste
2017-08-04Purge history on buffer reload when NoUndo flag is onMaxime Coste
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