Skip to content

Conversation

shaiay
Copy link

@shaiay shaiay commented Jul 16, 2025

As a user of multilingual keyboard, I sometimes search using fzf but forget to switch the keyboard language to English

This patch enables a mode where non-English characters are mapped to they keyboard equivalent English characters -- the English character sitting on the same key in the standard QWERTY keyboard, so even though you did not switch keyboard, you would get search results as though you were typing in English

A bit esoteric, but helps a bit ...

Includes implementation for Hebrew and Russian, easy to add more
90% written by gemini-cli

Ayal Org and others added 8 commits July 16, 2025 11:44
This commit introduces a new feature that allows users to search for Hebrew strings using their QWERTY keyboard equivalents. This is useful for users who work with both Hebrew and English and may not always have their keyboard set to the correct language.

The changes include:
- A mapping from Hebrew characters to their corresponding QWERTY characters.
- Modifications to the search pattern logic to generate a "keyboard converted" version of the search term.
- Updates to the matching functions to check both the original and the converted search terms.
This commit refactors the keyboard layout mapping to be more modular
and extensible. The hardcoded hebrew-to-qwerty mapping has been
replaced with a generic Keymap structure that can support multiple
languages. A new file, src/keymap.go, has been introduced to store
the mappings, and the pattern matching logic has been updated to use
the new structure.

This change makes it easier to add support for new keyboard layouts
in the future.
This commit further generalizes the keyboard layout conversion logic.

- The `hasHebrew` variable in `src/pattern.go` has been renamed to
  `needsConversion` to reflect its broader applicability.
- The `qwertyMapping` is now initialized by merging all language-specific
  keymaps from `src/keymap.go`, allowing for easy addition of new
  language layouts.
- The explicit mention of "hebrew" has been removed from `src/pattern.go`,
  making the code more generic.
This commit introduces a new command-line argument `--keymap-convert`
(short form `+C`) to control the keyboard layout conversion feature.

- Added `KeymapConvert` field to `Options` struct in `src/options.go`.
- Implemented parsing for `--keymap-convert` and `--no-keymap-convert`
  in `src/options.go`.
- Modified `BuildPattern` function in `src/pattern.go` and its calls
  in `src/core.go` and `src/pattern_test.go` to pass the new argument.
- Wrapped the keymap conversion logic in `src/pattern.go` with a
  conditional check for `keymapConvert`.
This commit addresses the build errors related to undefined variables
`textRunes` and `keymapConvert` in `src/pattern.go`.

- `textRunes` is now declared outside the conditional block in `BuildPattern`
  to ensure it's always in scope.
- `keymapConvert` is now passed as a parameter to `extendedMatch` and
  stored in the `Pattern` struct, resolving its undefined status within
  the function.
This commit updates the help string in `src/options.go` to include
the newly added `--keymap-convert` command-line option and its
short forms (`+C` and `-C`).
@shaiay shaiay marked this pull request as ready for review July 16, 2025 17:13
@nenahp
Copy link

nenahp commented Jul 16, 2025

maybe this be achieved by define a start:execute-silent:switch-cmd action?

@shaiay
Copy link
Author

shaiay commented Jul 16, 2025

I ma not sure I understand, but this implementation is activated by a command line switch

@nenahp
Copy link

nenahp commented Jul 16, 2025

that's it. i wonder if it's technically possible to have a command to switch? ok.. in your case maybe it's a bit tricky since you have to talk with the keyboard rather than the os.

(btw there are software level keyboards like kanata. off topic here but it's great if fzf is not the only case)

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.

2 participants