aboutsummaryrefslogtreecommitdiff
path: root/test/functional/editor/undo_spec.lua
Commit message (Collapse)AuthorAge
* refactor(undo): redundant "forget" logic #41980Justin M. Keyes2026-09-18
| | | | | | | | | | | | | | | Problem: `u_undo_and_forget()` and `u_forget_unchanged()` do similar undo-tree surgery: unlink a header, promote the alt branch it displaced. Solution: Extract common logic to `u_forget_header()`. Bonus: - The `:undo!` copy now fixes `b_u_oldhead`, so after forgetting a root header, its alt branch is still listed by `undotree()`. - Freeing can no longer unlink the promoted branch: `uh_alt_prev` is cleared first. The old code relied on the forgotten header being the first sibling.
* feat(editor): undo restores cursor position #41520Justin M. Keyes2026-08-27
| | | | | | | | | | | | | | | | | | Problem: Undo places the cursor wherever the cursor happened to sit at "save time" (`uh_cursor` is sampled lazily on the first change). Examples: - `i` preserves, but `a` does not - `diw`, `atest<Esc>`, `d^` abandon the original position - `D`, `o` restore it (by accident). Solution: `composite` tracks the pending atom (and its `origin`) across frames. A `stuffed` continuation frame inherits the `origin` + prepped redo. Store `origin` info in the undo header, so undo can restore it. - Not for a mid-command undo break (i_CTRL-G_u). - Undoing a mapping restores where the mapping started (which technically may be different than where the "edit" started).
* fix(undo): crash on corrupted undo file #41339Justin M. Keyes2026-08-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: `:rundo` on a corrupted undo file crashes or hangs, instead of failing with E825. Patching one 4-byte field is enough: ue_size = 0xFFFFFFFF " walks a NULL ue_array ue_size = 0x7FFFFFF0 " 17 GB xmalloc + memset, then preserve_exit() ue_top = 0xFFFFFFFB " negative lnum reaches ml_delete() Analysis: Every count in the file is read with `undo_read_4c()` and then checked, differently at each site. None bounds the value by what the file can hold, so a 2 GB count reaches `xmalloc()`. Note: - Vim doesn't have `bi_fsize` because it checks `U_ALLOC_LINE` result everywhere (thus doesn't crash, but may thrash...); those checks were dropped when Nvim moved to `xmalloc()`, and the `ue_size` loop counter became unsigned. - Vim *does* have the negative line numbers bug: `u_undoredo()` checks `top > ml_line_count || top >= bot || bot > ml_line_count + 1`, which rejects none of them. Solution: - Introduce `undo_read_len()` and use it to fail early instead of continuing with nonsense. - Validate `ue_top`/`ue_bot`/ `ue_lcount`. - Use `xcalloc()`, so no site can proceed with a NULL array. - Report a truncated "U" line, distinguish EOF from a 0xFFFFFFFF field, and free the header on the extmark error path.
* test(harness): migrate away from magic globalsJustin M. Keyes2026-07-21
| | | | | | | | | | | | | | | | | | | | | Problem: The magic globals `it`, `describe`, etc., are more trouble than they are worth. - Hooking into `after_each` requires `getfenv()` hacks. - They confuse luals/emmylua, because the top-level `.luarc.json` isn't merged with `test/.luarc.json` (apparently a luals limitation?) - They totally defeat discoverability because the user just has to "know" about the various magic symbols. So they harm DX, which means they serve no purpose at all. Solution: - Expose the test API from `testutil`, so tests can call `t.it()`, `t.describe()`, etc., in the conventional way. - Drop `getfenv()` hacks. - Drop the `setfenv()` injection in `load_chunk`. - Drop `test/_meta.lua`.
* fix(undo): undefined behavior with empty entry in 'undodir' (#38849)zeertzjq2026-04-07
| | | | | Problem: Undefined behavior when 'undodir' contains empty entry. Solution: Don't try to remove trailing slashes from empty path. Also don't remove a colon on Windows while at it.
* fix(prompt): clear undo when changing/appending promptSean Dewar2026-02-17
| | | | | | | | | | | | | | | Problem: undoing after the prompt is changed breaks it (and causes init_prompt to abort it and append a new one), as the undo history contains the old prompt. Solution: like submitting, clear the undo buffer. Don't do it in init_prompt if the line was empty; that may not result in a new prompt, and causes commands like "S" to lose the history. As u_save, etc. wasn't being called by prompt_setprompt, undoing after it fixes the prompt usually gave undesirable results anyway. Remove the added undo_spec.lua test, as its approach no longer works as a repro, and finding a new one seems fiddly.
* fix(undo): u_savecommon uses wrong bufferSean Dewar2026-02-17
| | | | | | Problem: u_savecommon with reload = true wrongly uses curbuf. Solution: use buf. Fix comments.
* test: remove feed_command in undo_spec #36953glepnir2025-12-15
| | | | | Problem: feed_command is marked as deprecated. Solution: replace it with command and pcall_err.
* test: improve test conventionsdundargoc2024-04-23
| | | | | | | | | Specifically, functions that are run in the context of the test runner are put in module `test/testutil.lua` while the functions that are run in the context of the test session are put in `test/functional/testnvim.lua`. Closes https://github.com/neovim/neovim/issues/27004.
* refactor(test): inject after_each differentlyLewis Russell2024-04-10
|
* test: improve test conventionsdundargoc2024-04-08
| | | | Work on https://github.com/neovim/neovim/issues/27004.
* test: rename (meths, funcs) -> (api, fn)Lewis Russell2024-01-12
|
* refactor: format test/*Justin M. Keyes2024-01-03
|
* test(undo_spec): add more tests for writing in Insert modezeertzjq2022-12-09
|
* vim-patch:9.0.1036: undo misbehaves when writing from an insert mode mappingzeertzjq2022-12-09
| | | | | | | | | Problem: Undo misbehaves when writing from an insert mode mapping. Solution: Sync undo when writing. (closes vim/vim#11674) https://github.com/vim/vim/commit/3f8f82772313af9f2417b06651f30988b63e1c96 Co-authored-by: Bram Moolenaar <Bram@vim.org>
* feat: add `undo!`Famiu Haque2022-04-20
| | | | Allows using `undo!` to undo changes and remove them from the undo-tree. Can only be used for moving backwards in the same undo branch.
* test: reorg #15698Justin M. Keyes2021-09-17
Problem: Subdirectories like "visual", "insert", "normal" encourage people to separate *related* tests for no good reason. Typically the _mode_ is not the relevant topic of a test (and when it is, _then_ create an appropriate describe() or it()). Solution: - Delete the various `test/functional/<mode>/` subdirectories, move their tests to more meaningful topics. - Rename `…/normal/` to `…/editor/`. - Move or merge `…/visual/*` and `…/insert/*` tests into here where appropriate. - Rename `…/eval/` to `…/vimscript/`. - Move `…/viml/*` into here also. * test(reorg): insert/* => editor/mode_insert_spec.lua * test(reorg): cmdline/* => editor/mode_cmdline_spec.lua * test(reorg): eval core tests => eval_spec.lua