fix(widget): system Cmd+V paste no longer lands at cursor+1 in vim mode - #27
Merged
Merged
Conversation
`@replit/codemirror-vim` 6.3.0 attaches a bubble-phase paste DOM listener
on contentDOM that, when vim is in normal/visual mode, advances the
cursor by +1 and forces insert mode (collapsing the visual selection)
before the native paste insert runs. Result: Cmd+V inserts the clipboard
at cursor+1 in normal mode and never replaces visual selections.
Add `systemPasteExtension` — a capture-phase paste listener on the child
editor's contentDOM that reads `clipboardData.getData('text/plain')`,
dispatches `replaceSelection(text)` with `userEvent: 'input.paste'`,
calls `preventDefault() + stopImmediatePropagation()` to pre-empt vim's
bubble handler, and routes to insert mode via the public `Vim.handleKey`
API. Wired into `buildExtensions` immediately after `vimCompartment.of`.
Vim's register-based `p`/`P`/`yy`/`]p` etc. go through vim's internal
command dispatcher (not the DOM paste event) and are untouched.
Debug session: .planning/debug/vim-cmd-v-paste-offset.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@replit/codemirror-vim6.3.0 attaches a bubble-phasepastelistener onview.contentDOMthat, in normal/visual mode, advances the cursor by +1 and forces insert mode (collapsing visual selection) before the native paste insert runs — so Cmd+V/Ctrl+V land at cursor+1 in normal mode and never replace a visual selection.src/widget/systemPasteExtension.ts(createSystemPasteExtension()) — aViewPluginthat attaches a capture-phase paste listener oncontentDOM, readsclipboardData.getData('text/plain'), dispatchesreplaceSelection(text)withuserEvent: 'input.paste', and callspreventDefault() + stopImmediatePropagation()to pre-empt vim's bubble handler. After insert it routes to insert mode via the publicVim.handleKeyAPI.buildExtensionsimmediately aftervimCompartment.of(...)so it's always-on (vim ON or OFF — when vim is off the capture handler produces the same result as the native default).p/P/yy/]ppaste keys go through vim's internal command dispatcher (not the DOM paste event) and are untouched.Root-cause artifacts:
.planning/debug/vim-cmd-v-paste-offset.md.Test plan
Automated (CI):
npm run build— cleannpm run lint— 0 errorsnpm test— 2965 passed / 8 skipped / 0 failuresManual UAT (cannot be unit-tested without a live Obsidian instance, per CLAUDE.md):
v+ extend, Cmd+V → selection replaced, editor in insert mode.yythenp→ line duplicates after-cursor (unchanged).