orbitalquark / textadept

Textadept is a fast, minimalist, and remarkably extensible cross-platform text editor for programmers.
https://orbitalquark.github.io/textadept
MIT License
653 stars 39 forks source link

Keyboard shortcuts don't work with non-English layouts. #64

Closed winterwolf closed 3 years ago

winterwolf commented 3 years ago

OS: Xubuntu 20.04 Layout: Russian (or other non-Latin)

orbitalquark commented 3 years ago

Textadept's key bindings are based on what the key's typed character would be. Unfortunately, I think you'll have to manually remap your keys. I don't know a way around this.

winterwolf commented 3 years ago

But you somehow handle keys that have no characters - Enter, Backspace, Tab, etc... Probably they have some special codes? Maybe it's possible to gather such codes for all keys?

rgieseke commented 3 years ago

If you have a mapping from russian to Latin layout it might be possible to do that programmatically. For example one could maybe check whether the code is in the range of your alphabet letters and map them to the latin code. Or iterate through the keys table and add shortcuts for different letters.

orbitalquark commented 3 years ago

Ah yes, keys.KEYSYMS does have codes for unprintable keys like the ones you mentioned, arrow keys, home/end, etc. I chose not to use key codes because (ironically) they vary depending on physical keyboard layout.

winterwolf commented 3 years ago

Tricks like this:

keys["ctrl+м"] = keys["ctrl+v"]

doesn't work! 😭

I inspected table, there is no errors and keys are registered, but they just don't work at all.

rgieseke commented 3 years ago

You can uncomment this line to inspect what's happening: https://github.com/orbitalquark/textadept/blob/default/core/keys.lua#L177

This should print something like, e.g. for ctrl+u:

117 nil false   true    false   false   false

This line is also relevant, you might have to add м to keys.KEYSYMS: https://github.com/orbitalquark/textadept/blob/default/core/keys.lua#L181

winterwolf commented 3 years ago

ctrl+v: 118 nil false true false false false ctrl+м: 1741 nil false true false false false

rgieseke commented 3 years ago

From the manual:

For key values greater than 255, Textadept uses the keys.KEYSYMS lookup table.

What happens if you do keys.KEYSYMS[1741] = 'м'

winterwolf commented 3 years ago

Yes, it works, thank you!

rgieseke commented 3 years ago

Awesome, if you find a table with mappings for your keyboard layout you can add these programmatically to Textadept!

winterwolf commented 3 years ago

My issue is solved!

do -- Russian keys
  local t = {
    [1738] = "q",
    [1731] = "w",
    [1749] = "e",
    [1739] = "r",
    [1733] = "t",
    [1742] = "y",
    [1735] = "u",
    [1755] = "i",
    [1757] = "o",
    [1754] = "p",
    [1736] = "[",
    [1759] = "]",
    [1734] = "a",
    [1753] = "s",
    [1751] = "d",
    [1729] = "f",
    [1744] = "g",
    [1746] = "h",
    [1743] = "j",
    [1740] = "k",
    [1732] = "l",
    [1750] = ";",
    [1756] = "'",
    [1745] = "z",
    [1758] = "x",
    [1747] = "c",
    [1741] = "v",
    [1737] = "b",
    [1748] = "n",
    [1752] = "m",
    [1730] = ",",
    [1728] = "."
  }
  for k, v in pairs(t) do
    keys.KEYSYMS[k] = v
  end
end