themes kitten: fix some keybaord shortcuts not working with weird IME systems on Linux that convert key events into text events

This commit is contained in:
Kovid Goyal
2024-10-15 09:51:52 +05:30
parent a81fd3b1c2
commit 62d5e13cbd
2 changed files with 24 additions and 10 deletions

View File

@@ -231,13 +231,13 @@ func (self *handler) next(delta int, allow_wrapping bool) {
}
func (self *handler) on_browsing_key_event(ev *loop.KeyEvent) error {
if ev.MatchesPressOrRepeat("esc") || ev.MatchesPressOrRepeat("q") {
if ev.MatchesPressOrRepeat("esc") || ev.MatchesCaseInsensitiveTextOrKey("q") {
self.lp.Quit(0)
ev.Handled = true
return nil
}
for _, cat := range self.tabs {
if ev.MatchesPressOrRepeat(cat[0:1]) || ev.MatchesPressOrRepeat("alt+"+cat[0:1]) {
if ev.MatchesPressOrRepeat(cat[0:1]) || ev.MatchesPressOrRepeat("alt+"+cat[0:1]) || ev.MatchesCaseInsensitiveTextOrKey(cat[0:1]) {
ev.Handled = true
if cat != self.current_category() {
self.set_current_category(cat)
@@ -256,12 +256,12 @@ func (self *handler) on_browsing_key_event(ev *loop.KeyEvent) error {
ev.Handled = true
return nil
}
if ev.MatchesPressOrRepeat("j") || ev.MatchesPressOrRepeat("down") {
if ev.MatchesCaseInsensitiveTextOrKey("j") || ev.MatchesPressOrRepeat("down") {
self.next(1, true)
ev.Handled = true
return nil
}
if ev.MatchesPressOrRepeat("k") || ev.MatchesPressOrRepeat("up") {
if ev.MatchesCaseInsensitiveTextOrKey("k") || ev.MatchesPressOrRepeat("up") {
self.next(-1, true)
ev.Handled = true
return nil
@@ -282,12 +282,12 @@ func (self *handler) on_browsing_key_event(ev *loop.KeyEvent) error {
}
return nil
}
if ev.MatchesPressOrRepeat("s") || ev.MatchesPressOrRepeat("/") {
if ev.MatchesCaseInsensitiveTextOrKey("s") || ev.MatchesCaseInsensitiveTextOrKey("/") {
ev.Handled = true
self.start_search()
return nil
}
if ev.MatchesPressOrRepeat("c") || ev.MatchesPressOrRepeat("enter") {
if ev.MatchesCaseInsensitiveTextOrKey("c") || ev.MatchesPressOrRepeat("enter") {
ev.Handled = true
if self.themes_list == nil || self.themes_list.Len() == 0 {
self.lp.Beep()
@@ -496,25 +496,25 @@ func (self *handler) draw_theme_demo() {
// accepting {{{
func (self *handler) on_accepting_key_event(ev *loop.KeyEvent) error {
if ev.MatchesPressOrRepeat("q") || ev.MatchesPressOrRepeat("esc") || ev.MatchesPressOrRepeat("shift+q") {
if ev.MatchesCaseInsensitiveTextOrKey("q") || ev.MatchesPressOrRepeat("esc") || ev.MatchesPressOrRepeat("shift+q") {
ev.Handled = true
self.lp.Quit(0)
return nil
}
if ev.MatchesPressOrRepeat("a") || ev.MatchesPressOrRepeat("shift+a") {
if ev.MatchesCaseInsensitiveTextOrKey("a") || ev.MatchesPressOrRepeat("shift+a") {
ev.Handled = true
self.state = BROWSING
self.draw_screen()
return nil
}
if ev.MatchesPressOrRepeat("p") || ev.MatchesPressOrRepeat("shift+p") {
if ev.MatchesCaseInsensitiveTextOrKey("p") || ev.MatchesPressOrRepeat("shift+p") {
ev.Handled = true
self.themes_list.CurrentTheme().SaveInDir(utils.ConfigDir())
self.update_recent()
self.lp.Quit(0)
return nil
}
if ev.MatchesPressOrRepeat("m") || ev.MatchesPressOrRepeat("shift+m") {
if ev.MatchesCaseInsensitiveTextOrKey("m") || ev.MatchesPressOrRepeat("shift+m") {
ev.Handled = true
self.themes_list.CurrentTheme().SaveInConf(utils.ConfigDir(), self.opts.ReloadIn, self.opts.ConfigFileName)
self.update_recent()

View File

@@ -306,6 +306,20 @@ func (self *KeyEvent) MatchesPressOrRepeat(spec string) bool {
return self.MatchesParsedShortcut(ParseShortcut(spec), PRESS|REPEAT)
}
func (self *KeyEvent) MatchesCaseSensitiveTextOrKey(spec string) bool {
if self.MatchesParsedShortcut(ParseShortcut(spec), PRESS|REPEAT) {
return true
}
return self.Text == spec
}
func (self *KeyEvent) MatchesCaseInsensitiveTextOrKey(spec string) bool {
if self.MatchesParsedShortcut(ParseShortcut(spec), PRESS|REPEAT) {
return true
}
return strings.ToLower(self.Text) == strings.ToLower(spec)
}
func (self *KeyEvent) MatchesRelease(spec string) bool {
return self.MatchesParsedShortcut(ParseShortcut(spec), RELEASE)
}