[Bug] Exiting Visual mode at end of line leaves the Normal-mode cursor past the final character
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 65/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, vim
- Ambito
- devtools
Direzione di ricerca
The bug is in the exitVisualMode function in packages/codemirror-vim-core/vim.js. Start by reading the reproduction steps and the provided code snippet to understand the cursor behavior. Examine the clipCursorToContent helper and how visual mode flags are cleared. The candidate fix shows the necessary reordering of operations. Test the fix with the provided minimal setup and check edge cases like empty lines and supplementary characters.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Related: #38 reports entering an invalid end-of-line cursor position by clicking with the mouse. This report reproduces a similar symptom entirely through Vim keys and identifies a separate path in exitVisualMode.
Versions and environment
@replit/codemirror-vim: 6.4.0@replit/codemirror-vim-core: 0.1.0@codemirror/state: 6.7.5@codemirror/view: 6.43.12- Reproduced in native macOS WebKit, both with a bare CodeMirror editor and in an application integration.
Reproduction
- Start with a single line containing
alpha, with the cursor onain Normal mode. - Press
v, then presslfive times to reach the position after the final character. - Press Escape.
- Press
lonce more.
After step 3, the Normal-mode cursor remains at zero-based column 5, after the final a. Step 4 moves it backward to column 4 despite being a rightward motion.
Expected: Escape should leave the Normal-mode cursor at column 4 immediately, and the following l should not move it. Unconfigured Vim behaves this way.
Minimal setup and programmatic reproduction:
import { EditorView, drawSelection } from '@codemirror/view';
import { vim, Vim, getCM } from '@replit/codemirror-vim';
const view = new EditorView({
doc: 'alpha',
extensions: [vim(), drawSelection()],
parent: document.body,
});
const cm = getCM(view);
for (const key of ['v', 'l', 'l', 'l', 'l', 'l', '<Esc>']) {
Vim.handleKey(cm, key, 'user');
}
console.log(cm.getCursor()); // Actual: { line: 0, ch: 5 }; expected ch: 4
Vim.handleKey(cm, 'l', 'user');
console.log(cm.getCursor()); // { line: 0, ch: 4 }
Apparent cause and candidate fix
In packages/codemirror-vim-core/vim.js, exitVisualMode calls clipCursorToContent before clearing vim.visualMode. That helper permits the line-break position while Visual mode is active, so it uses Visual-mode bounds for the resulting Normal-mode cursor.
Moving the cursor-clipping block after clearing the Visual-mode flags corrects this reproduction. updateLastSelection must still run before clearing the flags so gv retains the previous selection:
function exitVisualMode(cm, moveHead) {
var vim = cm.state.vim;
updateLastSelection(cm, vim);
vim.visualMode = false;
vim.visualLine = false;
vim.visualBlock = false;
if (moveHead !== false) {
cm.setCursor(clipCursorToContent(cm, vim.sel.head));
}
if (!vim.insertMode) CM.signal(cm, "vim-mode-change", {mode: "normal"});
}
Local checks with that change covered nonempty and empty lines, a supplementary-plane emoji, gv, visual yank, linewise put, and undo.
- Lingua principale
- JavaScript
- Stelle
- 479
- Fork
- 57
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di replit/codemirror-vim
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 50/100
replit/codemirror-vim#276 ·
-
Curly Brace deletion behaving unexpectedlyForse già presa @deepanshupal l’ha presa 19 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
replit/codemirror-vim#264 ·
-
`vim-mode-change` not fired on command mode enter/exitForse già presa @oller l’ha presa 5 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
replit/codemirror-vim#251 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
replit/codemirror-vim#243 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
replit/codemirror-vim#239 ·
Tutte le issue di replit/codemirror-vim
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
uoftblueprint/canada-basketball#67 ·
I maintainer di solito rispondono entro 1 giorno
-
打开群聊的设置同时打开侧边栏会出现侧边只出现一半Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
Fei2411/DeepSeek-Bot#456 ·
I maintainer di solito rispondono entro 1 giorno
-
área:app área:produto sem-fase tipo:decisão
Difficoltà 2/5 1-3 ore Idoneità per principianti 63/100
Varanda-org/varanda#91 ·
-
0️⃣ phase/new
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
auth0/express-openid-connect#901 ·
I maintainer di solito rispondono entro 1 giorno