Skip to content

Fix db, dB and cb deleting the character under the cursor - #182

Merged
ernestrc merged 3 commits into
unstablebuild:mainfrom
drakeo338:claude/181-fix
Oct 7, 2026
Merged

ernestrc merged 3 commits into
unstablebuild:mainfrom
drakeo338:claude/181-fix

Conversation

@drakeo338

Copy link
Copy Markdown
Contributor

db, dB and cb removed the character under the cursor along with the word before
it. In Vim b and B are exclusive motions, so that character should stay. The vi
handler's operator selections are right-inclusive, so after the extra MoveLeftStartWord
in handleMetaNormal I now refresh the end position and select the range with
SelectRange(after, before), which leaves the cursor character out.

The gu, gU and g~ backward-word tests (Wgub, WguB, WgUb, WgUB, Wg~b)
encoded the old behavior, so I corrected their expectations. I also added a test for
db, dB and cb on a single line. I checked the same-line results against Vim 9.
I did not add cases for b across a line break.

Fixes #181


Authorship

  • Written by hand. I would like a human review.
  • Mostly or partially generated by an AI agent, which I reviewed and understand.

The b and B motions are exclusive in Vim, but the operator selection was
right-inclusive, so the character under the cursor was removed along with the
word before it. Select the range right-exclusively instead, and correct the
gu, gU and g~ backward-word tests that encoded the old behavior.

Fixes unstablebuild#181

Signed-off-by: drakeo338 <[email protected]>
@codecov-commenter

codecov-commenter commented Oct 6, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/text/vi/handler.go 60.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread internal/text/vi/handler.go Outdated
after = vi.cursor.CursorAtScroll()
}
// b is exclusive, so the character under the cursor survives.
vi.cursor.SelectRange(after, before)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After f/t/F/T, the b key is the character to find, not a word motion. The w/W
case already checks for this (if prevMode == moveNone), but the b/B
case doesn't.

@ernestrc ernestrc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this! Just a small amend.

With an operator pending, the b/B operator selection ran even when the key
was the target of f, t, F or T, so dfb and dtb were handled as a backward
word motion. Skip it in that case, as the w/W case already does, and add
tests for fb, tb, Fb, Tb and fB.

Signed-off-by: drakeo338 <[email protected]>
@drakeo338

Copy link
Copy Markdown
Contributor Author

Pushed a follow-up: b/B now has the same prevMode guard as w/W, with tests for dfb, dtb, dFb, dTb and dfB.

@ernestrc
ernestrc enabled auto-merge (rebase) October 7, 2026 12:53
@ernestrc
ernestrc disabled auto-merge October 7, 2026 12:53
@ernestrc
ernestrc enabled auto-merge (squash) October 7, 2026 12:55
@ernestrc
ernestrc merged commit 9f7bed2 into unstablebuild:main Oct 7, 2026
8 checks passed
ernestrc added a commit that referenced this pull request Oct 11, 2026
After #182 and #185, a differential run against Vim 9.1 still showed 109
operator mismatches. handleMetaNormal anchored every operator at the cursor and
treated every motion end as inclusive, so Vim's :h exclusive and :h linewise
rules, its register semantics and where it leaves the cursor were not modelled:
dh deleted the character under the cursor, db joined lines, and gU overwrote
the unnamed register.

Signed-off-by: ernestrc <[email protected]>
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.

Vim 'db' action deletes the character under the cursor

3 participants