Skip to content

layout-agnostic key bindings for non-Latin keyboards - #64

Closed
sanchesfree wants to merge 173 commits into
umputun:masterfrom
sanchesfree:feature/layout-agnostic-keys
Closed

sanchesfree wants to merge 173 commits into
umputun:masterfrom
sanchesfree:feature/layout-agnostic-keys

Conversation

@sanchesfree

Copy link
Copy Markdown
Contributor

Summary

Hotkeys now work regardless of the active keyboard layout. Pressing г (Cyrillic) triggers the same action as u, ξ (Greek) as j, ח (Hebrew) as j — all based on physical key position.

How it works

A transparent fallback in Keymap.Resolve(): when a pressed key has no direct binding and is a known non-Latin character, it is translated to its Latin QWERTY equivalent and looked up again. This is purely additive — existing behavior is completely unchanged.

Design decisions:

  • Only non-ASCII characters are mapped. ASCII characters like ; or , exist at different physical positions across layouts, so mapping them would be ambiguous and could break existing behavior.
  • No interface changes, no new flags, no config. The feature is invisible to users who don't need it.
  • Help overlay, --dump-keys, and KeysFor() are unaffected — they show canonical Latin bindings only.

Supported layouts

Layout Script Users Entries
Russian ЙЦУКЕН Cyrillic ~150M 60 (lowercase + uppercase)
Ukrainian Cyrillic ~40M 6 extras on top of Russian
Belarusian, Kazakh, Serbian Cyrillic Cyrillic ~25M covered by Russian table
Greek Greek ~13M 50
Hebrew Hebrew ~10M 28

CJK layouts (Chinese, Japanese, Korean) don't need this — they use IME and send Latin characters for key events. Latin-script layouts (Spanish, French, German, etc.) already send the correct letters.

Files changed

  • app/keymap/layout.go (new) — static map[rune]rune with per-layout mappings + layoutResolve() helper
  • app/keymap/keymap.go — Resolve() tries layout alias as fallback when direct lookup misses (3 extra lines)
  • app/keymap/layout_test.go (new) — unit tests for all 3 layouts + integration tests for Resolve() fallback, precedence, and non-pollution of KeysFor/HelpSections

Extensibility

Adding a new layout requires only appending entries to the map in layout.go — no other code changes. Arabic, Thai, and other non-Latin layouts can be added the same way.

umputun added 30 commits March 31, 2026 01:14
TUI git diff reviewer with inline annotations, built with Go + bubbletea.
Two-pane layout with file tree and full-file colorized diff view.
Extract diff rendering into ui/diffview.go with cursor-based navigation
that skips divider lines and auto-scrolls viewport. Add context-sensitive
status bar hints per focused pane and DiffCursorLine style.
Remove version banner from stdout to keep it clean for annotation
output. Add tests verifying annotations survive quit and empty
output when no annotations exist.
TUI git diff reviewer with inline annotations.
Two-pane layout: file tree + full-file colorized diff.
Annotation store, structured stdout output on quit.
re-render viewport content after each keystroke in handleAnnotateKey
so typed characters appear immediately in the annotation input field
Add --tree-width CLI flag (env: TREE_WIDTH) to control file tree panel
width as a ratio of 1-10 units out of total terminal width, default 3.
…fied view

- add cursorOnAnnotation state for stepping onto annotation lines with j/k
- add Store.Has() for checking annotation existence without full lookup
- rename chunk→hunk throughout (methods, tests, status bar)
- remove simplified/unified diff view (v toggle) and all related code
- center viewport on cursor when navigating between hunks with [/]
- fix file annotation cursor positioning and viewport scroll on save
remove stale simplified-view references from README and comments,
convert buildEntries to fileTree method, flatten nested if/else in
tab handler, drop redundant dl parameter from renderAnnotationOrInput.
umputun and others added 18 commits April 6, 2026 20:41
* docs: add hunk keyword expansion plan

* feat: add EndLine field to Annotation and update FormatOutput for hunk range display

* feat: detect hunk keywords in annotations and populate EndLine

* feat: document hunk keyword expansion in output format

* fix: remove "block" from hunk keywords to avoid false positives

* fix: address Copilot review findings for hunk keyword expansion
…x restriction

all mktemp calls now use ${TMPDIR:-/tmp} via a shared TMPBASE variable,
fixing "Operation not permitted" error in sandboxed environments.

Related to umputun#48
detect fresh repos (git init, no commits) and suggest --all-files mode
so the plugin can browse staged files instead of showing empty diff.

Related to umputun#48
move all Go packages (annotation, diff, highlight, keymap, theme, ui)
and entry point (cmd/revdiff) into app/. update all internal import
paths, build configs, and documentation. drop go install instructions,
keep brew and binary releases only. remove root llms.txt duplicate.
move logo size variants to site/assets/, update README to reference
site/assets/ for images. root assets/ was duplicating site/assets/.
…mputun#54)

* feat: add reviewed file marks and A/M/D status indicators in file tree

Add space bar toggle to mark files as reviewed (green ✓ checkmark in tree),
with progress shown in status bar (✓ N/M) and mode icon strip.

Change Renderer.ChangedFiles to return []FileEntry with git status info,
enabling A/M/D indicators in the tree sidebar with semantic colors
(green=added, red=deleted, muted=modified).

* refactor: simplify reviewed marks and file status code

- Add FileStatus type with constants (FileAdded, FileModified, etc.)
  replacing raw string literals
- Pre-compute status styles (StatusAdded, StatusDeleted, StatusDefault)
  on styles struct instead of allocating per render
- Remove dead indent parameter from renderFileEntry
- Move status styling to styles.fileStatusStyle() method
- Build []FileEntry directly in DirectoryReader without intermediate
  []string allocation
- Remove WHAT comments that restated the code

* refactor: use NUL-terminated git output and streamline file tree construction

Switch ChangedFiles to git diff --name-status -z for robust parsing of
filenames with special characters. Add newFileTreeFromEntries to eliminate
the roundtrip of extracting paths then re-inserting statuses. Fix tree-pane
mark-reviewed to use selected row instead of stale currFile.
* docs: add pi package documentation and review fixes

Add pi package section to README, docs, and landing page. Clarify
command descriptions, add missing /revdiff-reminders to docs.html,
and improve accessibility on feature icon.

* fix: address pi package PR review feedback

- Add node_modules/ to .gitignore
- Set pi plugin version to 0.1.0 (independent versioning)
- Pin pi peerDependencies to ^0.60 instead of wildcard
- Add no-commits guard to detectSmartRefFallback matching detect-ref.sh
- Add Pi Plugin section to CLAUDE.md with version bump convention

* fix: guard ctx.ui calls behind hasUI check in post-edit extension

updateStatus and setEnabled were calling ctx.ui methods even when
ctx.hasUI was false, which could throw in headless contexts.
add collapsed/wrap modes and markdown TOC feature cards to fill
3x3 grid. add hunk range example to output format section. center
orphan install card in last row using flexbox.
* zellij.dev support

* fix: use launcher script for zellij blocks to avoid sh -c quoting issues

Replace `sh -c "$REVDIFF_CMD; touch ..."` with a temp launcher script
in both Zellij blocks, matching the cmux/ghostty pattern. Also add
TMPBASE to launch-plan-review.sh for macOS sandbox compatibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
* add plan: global-hunk-navigation

* feat: add hasNextFile/hasPrevFile helpers to fileTree

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* feat: add pendingHunkJump field for cross-file hunk navigation deferred positioning

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* feat: implement global hunk navigation with cross-file jump

Add handleHunkNav method to diffview.go that moves to next/prev hunk
regardless of which pane has focus. When at the last hunk of a file,
automatically navigates to the next file and lands on its first hunk
(and vice versa for backward navigation). Hunk nav keys are moved to
the global key switch so they work from the tree pane too.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* feat: verify acceptance criteria and fix handleKey cyclomatic complexity

Extracted openAnnotList helper and helpActive predicate to reduce
handleKey cyclomatic complexity from 22 to 20, satisfying gocyclo lint.
All tests pass, lint clean.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* feat: update docs for cross-file hunk navigation and complete plan

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* Reviews findings

* Fix lint failures

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
…mputun#62)

* feat: add u toggle to show/hide untracked files in file tree

Read-only implementation — no git mutations, no interface pollution.
- UntrackedFiles() added only to *Git, exposed via ModelConfig.LoadUntracked callback
- u key toggles untracked file visibility in tree
- ? icon shown in status bar when active

* fix: show untracked file contents as all-added lines, clear diff on empty tree

* feat: always show staged-only files (new files added to index)

* fix: preserve file selection when toggling untracked files

* feat: show ? status icon for untracked files in file tree

* fix: use m.diffLines for highlighting after untracked fallback, wrap errors

* fix: preserve reviewed marks when toggling untracked files

* fix: save reviewed marks BEFORE rebuilding tree, not after

* address review feedback: tests, error handling, dedup, gated fallback

1. Add tests for UntrackedFiles, ReadFileAsAdded, toggle cycle,
   staged-only merge, dedup, and gated untracked fallback
2. Align ReadFileAsAdded with readFileAsContext: broken symlink
   handling, non-regular file placeholder, error wrapping
3. Log staged/untracked fetch failures as warnings instead of
   silently ignoring them
4. Gate handleFileLoaded disk fallback to FileUntracked status only
5. Dedup untracked files against existing entries (staged + unstaged)

* restrict staged-only merge to FileAdded, O(1) restoreReviewed

* log untracked fallback read errors, add broken symlink test for ReadFileAsAdded
When a non-Latin keyboard layout is active (Russian, Greek, Hebrew),
hotkeys now work based on physical key position. For example, pressing
г (Cyrillic) triggers the same action as u, since both are at the same
physical key position on QWERTY/ЙЦУКЕН layouts.

Implemented as a transparent fallback in Keymap.Resolve(): if a key has
no direct binding and is a known non-Latin character, it is translated
to its Latin QWERTY equivalent and looked up again.

Only non-ASCII characters are mapped to avoid ambiguity — ASCII chars
like ';' exist at different physical positions across layouts.

Supported layouts: Russian/Cyrillic (ЙЦУКЕН, also Ukrainian, Belarusian,
Kazakh, Serbian Cyrillic), Greek, Hebrew.
@sanchesfree
sanchesfree requested a review from umputun as a code owner April 8, 2026 06:29

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

nice feature, clean implementation. one issue I spotted:

Ukrainian і mapping - 'і': 'b' looks wrong. on the standard Ukrainian ЙЦУКЕН layout, і replaces Russian ы at the s position, not b. same for uppercase 'І': 'B' - should be 'І': 'S'. the ї→] and є→' mappings are correct. could you double-check which layout variant you used?

everything else looks solid - tests are thorough, the fallback in Resolve() is non-invasive, and the ASCII exclusion logic makes sense.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a layout-agnostic key binding fallback so that non-Latin keyboard layouts (Cyrillic/Greek/Hebrew) trigger the same actions as their Latin QWERTY physical-key equivalents, without changing existing bindings or UI display of canonical keys.

Changes:

  • Introduces a static non-Latin → Latin QWERTY alias table plus a small helper resolver.
  • Updates Keymap.Resolve() to retry binding lookup via the layout alias when a direct lookup misses.
  • Adds unit tests for the alias table and integration tests for Resolve() fallback/precedence and for not affecting KeysFor()/help output.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
app/keymap/layout.go Adds the non-Latin → Latin QWERTY alias map and layoutResolve() helper used for fallback resolution.
app/keymap/keymap.go Extends Resolve() to attempt a layout-alias lookup for single-rune non-Latin keys when unbound.
app/keymap/layout_test.go Adds tests for mapping correctness and for Resolve() fallback/precedence + non-pollution of key listing/help.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/keymap/layout.go Resolved
Comment thread app/keymap/layout_test.go Resolved
Comment thread app/keymap/layout_test.go Resolved
Comment thread app/keymap/layout_test.go Resolved
Comment thread app/keymap/layout_test.go Resolved
@sanchesfree

Copy link
Copy Markdown
Contributor Author

all feedback addressed — Ukrainian і→s fixed, layoutResolve returns (r, false) on miss, test names aligned with actual assertions, shadow declarations cleaned up. ready for another look.

@umputun umputun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

thx for addressing all the feedback. Ukrainian і→s is correct now, layoutResolve return is clean, test names match assertions.

one thing before merge - 1.txt and 2.txt are in the PR, look like accidental test/debug files. pls remove them

minor nit: TestKeymap_ResolveLayoutFallback "direct binding takes precedence" subtest mutates the shared km with km.Bind("г", ActionQuit) and that mutation leaks into subsequent subtests. works by coincidence since nothing else tests "г" unbound. safer to use its own km := Default() inside that subtest

@sanchesfree sanchesfree closed this Apr 8, 2026
@sanchesfree
sanchesfree force-pushed the feature/layout-agnostic-keys branch from 58257a1 to 0db77f1 Compare April 8, 2026 19:22
@sanchesfree

Copy link
Copy Markdown
Contributor Author

sorry about 1.txt/2.txt — leftover debug files, completely removed from all commits now. also fixed the shared km mutation in the direct_binding test with a local customKm.

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.