Skip to content

Fix evil-ghostel multi-line dd targeting the wrong line (#218)#222

Open
dakra wants to merge 1 commit intomainfrom
fix/issue-218-multiline-dd
Open

Fix evil-ghostel multi-line dd targeting the wrong line (#218)#222
dakra wants to merge 1 commit intomainfrom
fix/issue-218-multiline-dd

Conversation

@dakra
Copy link
Copy Markdown
Owner

@dakra dakra commented May 2, 2026

Summary

Fixes #218 — in multi-line TUI input (pi, ipython, ptpython), ESC k dd deleted the wrong line. Investigation surfaced four other latent bugs in the same code paths; bundled together since the user-visible fix doesn't work without them.

  • Same-row dispatch for line-type dd / cc: keep the readline-aware Ctrl-e/Ctrl-u shortcut for the single-line shell case (where the buffer line includes the prompt prefix); use cursor-sync + backspaces only when point is on a different viewport row from the terminal cursor (the actual Evil multi-line issues in pi #218 case).
  • Snap point on next redraw after the Ctrl-u path so point lands at the start of the input area, not at column 0 on the prompt.
  • Scrollback-aware evil-ghostel--cursor-to-point — previously off by exactly the scrollback line count.
  • Padding-aware backspace count — TUIs that draw fixed-width input boxes write spaces past the user's input; those are not characters in the TUI's input model and shouldn't become PTY backspaces.
  • evil-replace count consistency — paste and delete now both go through evil-ghostel--meaningful-length so trailing whitespace stripped from one side isn't re-added by the other.

Test plan

  • make test-evil — 56/56 pass, including 7 new tests covering each fix.
  • Live verified shell dd / cc: input cleared via Ctrl-u, prompt preserved, point lands at start of input area.
  • Live verified pi AAA\nBBB\nCCC + ESC kk dd: AAA gone, BBB and CCC remain.
  • CI green on Emacs 28.2 / 29.4 / snapshot.

In multi-line TUI input (e.g. pi, ipython), ESC k dd deleted the
last line instead of the line at point.  Five changes:

1. Same-row dispatch for line-type evil-delete and evil-change.
   When point is on the same viewport row as the terminal cursor
   (single-line shell case), keep the readline-aware Ctrl-e/Ctrl-u
   shortcut — it clears the input area without us needing to know
   where the prompt ends.  When point is on a different row
   (multi-line TUI case from #218), sync the terminal cursor to the
   deleted region's end and backspace through it.

2. After the same-row Ctrl-u path, snap point to the new terminal
   cursor position on the next redraw via a one-shot flag
   (evil-ghostel--sync-point-on-next-redraw).  Otherwise point
   would be left at column 0 — on the prompt rather than at the
   start of the input area where the cursor lands.

3. evil-ghostel--cursor-to-point ignored scrollback when computing
   the buffer→viewport row diff, sending arrows off into space in
   any session with scrollback (i.e. essentially all of them).
   Mirror the math from evil-ghostel--reset-cursor-point.

4. evil-ghostel--delete-region sent (end - beg) backspaces blindly,
   counting box-padding spaces (written by TUIs with fixed-width
   input boxes) as input characters and eating far past the actual
   content.  Strip per-line trailing whitespace before counting.
   Tradeoff documented: a line of pure user-typed indentation
   collapses to zero backspaces.

5. evil-replace's paste count now matches the delete count — both
   go through evil-ghostel--meaningful-length so trailing
   whitespace stripped from one side isn't re-added by the other.

Verified live: shell `dd` / `cc` clears input via Ctrl-u with point
landing at start of input area (after the prompt); pi
`AAA\nBBB\nCCC` + ESC kk dd leaves `BBB` and `CCC` with `AAA` gone.

Fixes #218
@dakra dakra force-pushed the fix/issue-218-multiline-dd branch from ff4f984 to 85b1bd4 Compare May 2, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evil multi-line issues in pi

1 participant