Skip to content

Commit caf16ed

Browse files
committed
Fix vim-motion: block all letter keys in Normal mode
- Block A-Z and 0-9 keys from reaching TextEditor in Normal mode - Clear InputQueueCharacters to prevent character insertion - Update README version to v0.2.95
1 parent 7be3f95 commit caf16ed

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Built with **Dear ImGui** + **GLFW** + **ImGuiColorTextEdit** - one codebase, ru
66

77
## Version
88

9-
**pcode-editor v0.2.28** (2026-04-17)
9+
**pcode-editor v0.2.95** (2026-04-19)
1010

1111
---
1212

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.95 (3b39a8903e574d838b8746c2618de99dcaa6497b)
1+
0.2.96 (3b39a8903e574d838b8746c2618de99dcaa6497b)

src/editor_app.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,11 +1923,19 @@ void EditorApp::render() {
19231923
// Only handle vim keys when in Normal mode and editor is focused
19241924
if (vim_mode_ == VimMode::Normal && !terminal_input_active_) {
19251925
bool vim_key_handled = false;
1926+
1927+
// Block ALL letter keys (A-Z) in Normal mode - don't let them pass to TextEditor
19261928
for (int key = ImGuiKey_A; key <= ImGuiKey_Z; key++) {
1927-
if (ImGui::IsKeyPressed((ImGuiKey)key)) { handle_vim_key(key, 0); vim_key_handled = true; break; }
1929+
if (ImGui::IsKeyPressed((ImGuiKey)key)) {
1930+
handle_vim_key(key, 0);
1931+
vim_key_handled = true;
1932+
break;
1933+
}
19281934
}
1935+
1936+
// Block number keys in Normal mode (only allow count prefix 0-9)
19291937
if (!vim_key_handled) {
1930-
for (int key = ImGuiKey_0; key <= ImGuiKey_9; key++) {
1938+
for (int key = ImGuiKey_1; key <= ImGuiKey_9; key++) {
19311939
if (ImGui::IsKeyPressed((ImGuiKey)key)) { handle_vim_key(key, 0); vim_key_handled = true; break; }
19321940
}
19331941
}
@@ -1959,23 +1967,26 @@ void EditorApp::render() {
19591967
if (!io.KeyCtrl) ctrl_w_pressed = false;
19601968
}
19611969

1962-
// After vim key handling, clear keys to prevent TextEditor from receiving them
1963-
if (vim_key_handled) {
1964-
// Clear the keys we just handled so TextEditor doesn't see them
1965-
io.AddKeyEvent(ImGuiKey_J, false);
1966-
io.AddKeyEvent(ImGuiKey_K, false);
1967-
io.AddKeyEvent(ImGuiKey_H, false);
1968-
io.AddKeyEvent(ImGuiKey_L, false);
1969-
for (int key = ImGuiKey_A; key <= ImGuiKey_Z; key++) {
1970-
io.AddKeyEvent((ImGuiKey)key, false);
1971-
}
1972-
for (int key = ImGuiKey_0; key <= ImGuiKey_9; key++) {
1973-
io.AddKeyEvent((ImGuiKey)key, false);
1974-
}
1975-
io.AddKeyEvent(ImGuiKey_Space, false);
1976-
io.AddKeyEvent(ImGuiKey_Backspace, false);
1977-
io.AddKeyEvent(ImGuiKey_Tab, false);
1970+
// After vim key handling, clear ALL letter/number keys to prevent TextEditor from receiving them
1971+
// This ensures unmapped keys like 'x', 'q', 'z' don't insert text in Normal mode
1972+
for (int key = ImGuiKey_A; key <= ImGuiKey_Z; key++) {
1973+
io.AddKeyEvent((ImGuiKey)key, false);
19781974
}
1975+
for (int key = ImGuiKey_0; key <= ImGuiKey_9; key++) {
1976+
io.AddKeyEvent((ImGuiKey)key, false);
1977+
}
1978+
io.AddKeyEvent(ImGuiKey_Space, false);
1979+
io.AddKeyEvent(ImGuiKey_Backspace, false);
1980+
io.AddKeyEvent(ImGuiKey_Tab, false);
1981+
1982+
// Clear InputQueueCharacters to prevent any character input in Normal mode
1983+
io.InputQueueCharacters.resize(0);
1984+
}
1985+
1986+
// Clear InputQueueCharacters to prevent any character input in Normal mode
1987+
if (vim_mode_ == VimMode::Normal && !terminal_input_active_) {
1988+
ImGuiIO& io = ImGui::GetIO();
1989+
io.InputQueueCharacters.resize(0);
19791990
}
19801991

19811992
// Command mode - don't process vim keys or shortcuts, let status bar handle input
@@ -3179,7 +3190,7 @@ void EditorApp::render_status_bar() {
31793190
}
31803191
}
31813192

3182-
// Exact format: | MODE | filename | * | Ln,Col | Git:branch | encoding | CRLF | Tab:n | v0.2.95 |
3193+
// Exact format: | MODE | filename | * | Ln,Col | Git:branch | encoding | CRLF | Tab:n | v0.2.96 |
31833194
ImGui::Text("%s", mode_str);
31843195
ImGui::SameLine();
31853196
ImGui::Text("%s", sep);

0 commit comments

Comments
 (0)