[Bug] Exiting Visual mode at end of line leaves the Normal-mode cursor past the final character
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- javascript, vim
- Lĩnh vực
- devtools
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- JavaScript
- Star
- 479
- Fork
- 57
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của replit/codemirror-vim
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 50/100
replit/codemirror-vim#276 ·
-
Curly Brace deletion behaving unexpectedlyCó thể đã có người làm @deepanshupal đã nhận 18 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
replit/codemirror-vim#264 ·
-
`vim-mode-change` not fired on command mode enter/exitCó thể đã có người làm @oller đã nhận 4 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
replit/codemirror-vim#251 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
replit/codemirror-vim#243 ·
-
[Feature] Implement Select modeĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
replit/codemirror-vim#239 ·
Tất cả issue của replit/codemirror-vim
Issue tương tự
-
Correction: IMOU Cruiser 4MPĐang mởcorrection via-web
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
ch-bas/cctv-camera-database#416 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug effort:medium model:light tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
piskyRpapalo/preceptoros-web#231 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
type/bug type/docs type/enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
Redo-San/RedoSan-Authenticity#574 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Place search spins forever when nominatim failsCó thể đã có người làm @jgt87 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
anvaka/city-roads#213 ·