Bypass key chords in dired
ober
3bd8b31ecec4adb48354001db423df8c26615b8a
--- a/lib/jerboa-emacs/qt/app.sls +++ b/lib/jerboa-emacs/qt/app.sls @@ -1744,6 +1744,9 @@ (= code (+ QT_KEY_A 23)))))] + [dired-key-buffer? (and qt-buf + (dired-buffer? + qt-buf))] [chord-relevant? (or (and *chord-pending-char* (not *chord-timer-fired*)) (and (not autorepeat?) @@ -1785,198 +1788,222 @@ code mods (or text "")) - (let ([is-printable (and (= (string-length - text) - 1) - (> (char->integer - (string-ref - text - 0)) - 31))] - [no-ctrl (zero? - (bitwise-and - mods - QT_MOD_CTRL))] - [no-alt (zero? + (if dired-key-buffer? + (begin + (when *chord-pending-char* + (qt-timer-stop! + *chord-timer*) + (set! *chord-pending-char* + #f) + (set! *chord-pending-term* + #f)) + (emit! code mods text)) + (let ([is-printable (and (= (string-length + text) + 1) + (> (char->integer + (string-ref + text + 0)) + 31))] + [no-ctrl (zero? + (bitwise-and + mods + QT_MOD_CTRL))] + [no-alt (zero? + (bitwise-and + mods + QT_MOD_ALT))]) + (verbose-log! "CHORD-CHECK pending=" + (if *chord-pending-char* + (string + *chord-pending-char*) + "#f") + " key=" + (if (and is-printable + no-ctrl + no-alt) + text + "non-printable") + " chord-start?=" + (if (and is-printable + no-ctrl + no-alt) + (if (chord-start-char? + (string-ref + text + 0)) + "Y" + "N") + "N/A") + " autorepeat=" + (if autorepeat? "Y" "N") + " prefix=" + (if (null? + (key-state-prefix-keys + (app-state-key-state + app))) + "none" + "active")) + (cond + [(and *chord-pending-char* + (not *chord-timer-fired*)) + (let* ([ch1 *chord-pending-char*] + [saved-code *chord-pending-code*] + [saved-mods *chord-pending-mods*] + [saved-text *chord-pending-text*] + [ch2 (and (= (string-length + text) + 1) + (> (char->integer + (string-ref + text + 0)) + 31) + (zero? + (bitwise-and + mods + QT_MOD_CTRL)) + (zero? + (bitwise-and + mods + QT_MOD_ALT)) + (string-ref + text + 0))]) + (cond + [autorepeat? + (verbose-log! + "CHORD-AUTOREPEAT ignored ch=" + (string ch1)) + (void)] + [(and (not ch2) + (or (and (>= code + 16777248) + (<= code + 16777253)) + (= code + 16777299) + (= code + 16777300) + (= code + 16781571))) + (verbose-log! + "CHORD-IGNORE-MODIFIER pending=" + (string ch1) + " code=" + (number->string + code)) + (void)] + [(not ch2) + (verbose-log! + "CHORD-CANCEL-NONCHORD pending=" + (string ch1) + " code=" + (number->string + code)) + (qt-timer-stop! + *chord-timer*) + (set! *chord-pending-char* + #f) + (emit! + saved-code + saved-mods + saved-text) + (emit! + code + mods + text)] + [else + (let ([chord-cmd (chord-lookup + ch1 + ch2)]) + (verbose-log! + "CHORD-RESOLVE ch1=" + (string ch1) + " ch2=" + (string ch2) + " cmd=" + (if chord-cmd + (symbol->string + chord-cmd) + "#f")) + (qt-timer-stop! + *chord-timer*) + (set! *chord-pending-char* + #f) + (if chord-cmd + (begin + (execute-command! + app + chord-cmd) + (qt-refresh-after-key! + app + echo-label + "chord-command")) + (begin + (emit! + saved-code + saved-mods + saved-text) + (emit! + code + mods + text))))]))] + [(and (not autorepeat?) + (= (string-length + text) + 1) + (> (char->integer + (string-ref + text + 0)) + 31) + (zero? (bitwise-and mods - QT_MOD_ALT))]) - (verbose-log! "CHORD-CHECK pending=" - (if *chord-pending-char* - (string - *chord-pending-char*) - "#f") - " key=" - (if (and is-printable - no-ctrl - no-alt) - text - "non-printable") - " chord-start?=" - (if (and is-printable - no-ctrl - no-alt) - (if (chord-start-char? - (string-ref text 0)) - "Y" - "N") - "N/A") - " autorepeat=" - (if autorepeat? "Y" "N") - " prefix=" - (if (null? - (key-state-prefix-keys - (app-state-key-state - app))) - "none" - "active")) - (cond - [(and *chord-pending-char* - (not *chord-timer-fired*)) - (let* ([ch1 *chord-pending-char*] - [saved-code *chord-pending-code*] - [saved-mods *chord-pending-mods*] - [saved-text *chord-pending-text*] - [ch2 (and (= (string-length - text) - 1) - (> (char->integer - (string-ref - text - 0)) - 31) - (zero? - (bitwise-and - mods - QT_MOD_CTRL)) - (zero? - (bitwise-and - mods - QT_MOD_ALT)) - (string-ref - text - 0))]) - (cond - [autorepeat? - (verbose-log! - "CHORD-AUTOREPEAT ignored ch=" - (string ch1)) - (void)] - [(and (not ch2) - (or (and (>= code - 16777248) - (<= code - 16777253)) - (= code - 16777299) - (= code - 16777300) - (= code - 16781571))) - (verbose-log! - "CHORD-IGNORE-MODIFIER pending=" - (string ch1) - " code=" - (number->string code)) - (void)] - [(not ch2) - (verbose-log! - "CHORD-CANCEL-NONCHORD pending=" - (string ch1) - " code=" - (number->string code)) - (qt-timer-stop! - *chord-timer*) - (set! *chord-pending-char* - #f) - (emit! - saved-code - saved-mods - saved-text) - (emit! code mods text)] - [else - (let ([chord-cmd (chord-lookup - ch1 - ch2)]) - (verbose-log! "CHORD-RESOLVE ch1=" - (string ch1) " ch2=" - (string ch2) " cmd=" - (if chord-cmd - (symbol->string - chord-cmd) - "#f")) - (qt-timer-stop! - *chord-timer*) - (set! *chord-pending-char* - #f) - (if chord-cmd - (begin - (execute-command! - app - chord-cmd) - (qt-refresh-after-key! - app - echo-label - "chord-command")) - (begin - (emit! - saved-code - saved-mods - saved-text) - (emit! - code - mods - text))))]))] - [(and (not autorepeat?) - (= (string-length text) - 1) - (> (char->integer - (string-ref - text - 0)) - 31) - (zero? - (bitwise-and - mods - QT_MOD_CTRL)) - (zero? - (bitwise-and - mods - QT_MOD_ALT)) - (null? - (key-state-prefix-keys - (app-state-key-state - app))) - (chord-start-char? - (string-ref text 0))) - (verbose-log! "CHORD-PENDING ch=" - (string - (string-ref text 0)) - " timeout=" - (number->string - *chord-timeout*) - "ms") - (set! *chord-pending-char* - (string-ref text 0)) - (set! *chord-pending-code* - code) - (set! *chord-pending-mods* - mods) - (set! *chord-pending-text* - text) - (set! *chord-pending-term* - (if term-fastpath? - qt-term - #f)) - (set! *chord-timer-fired* #f) - (qt-timer-start! - *chord-timer* - *chord-timeout*)] - [else - (emit! - code - mods - text)])))))]))))]) + QT_MOD_CTRL)) + (zero? + (bitwise-and + mods + QT_MOD_ALT)) + (null? + (key-state-prefix-keys + (app-state-key-state + app))) + (chord-start-char? + (string-ref + text + 0))) + (verbose-log! "CHORD-PENDING ch=" + (string + (string-ref text 0)) + " timeout=" + (number->string + *chord-timeout*) + "ms") + (set! *chord-pending-char* + (string-ref text 0)) + (set! *chord-pending-code* + code) + (set! *chord-pending-mods* + mods) + (set! *chord-pending-text* + text) + (set! *chord-pending-term* + (if term-fastpath? + qt-term + #f)) + (set! *chord-timer-fired* + #f) + (qt-timer-start! + *chord-timer* + *chord-timeout*)] + [else + (emit! + code + mods + text)]))))))]))))]) (qt-on-key-press-consuming! (qt-current-editor fr) key-handler) --- a/src/jerboa-emacs/qt/app.ss +++ b/src/jerboa-emacs/qt/app.ss @@ -1444,6 +1444,7 @@ (not (and (not (zero? (bitwise-and mods QT_MOD_ALT))) (zero? (bitwise-and mods QT_MOD_CTRL)) (= code (+ QT_KEY_A 23)))))) ;; M-x + (dired-key-buffer? (and qt-buf (dired-buffer? qt-buf))) ;; Chord-relevant keys must go through chord detection even inside ;; a terminal: a pending chord, or a printable chord-start char. (chord-relevant? (or (and *chord-pending-char* (not *chord-timer-fired*)) @@ -1462,6 +1463,15 @@ (if (and term-fastpath? (not chord-relevant?)) ;; Forward non-chord terminal keys straight to the terminal widget (qt-terminal-send-key-event! qt-term code mods (or text "")) + (if dired-key-buffer? + ;; Dired has one-key commands and type-to-search. Chord detection + ;; delays/replays printable letters here, which makes search feel dead. + (begin + (when *chord-pending-char* + (qt-timer-stop! *chord-timer*) + (set! *chord-pending-char* #f) + (set! *chord-pending-term* #f)) + (emit! code mods text)) ;; Normal: chord detection logic (let ((is-printable (and (= (string-length text) 1) (> (char->integer (string-ref text 0)) 31))) @@ -1559,7 +1569,7 @@ ;; Case 3: Normal key — no chord involvement (else - (emit! code mods text)))))))))))))) ; extra parens close let + if + let* (terminal) + minibuffer-active? when + (emit! code mods text))))))))))))))) ; extra parens close dired if + let + if + let* (terminal) + minibuffer-active? when ;; Install on the initial editor (consuming — editor doesn't see keys) (qt-on-key-press-consuming! (qt-current-editor fr) key-handler)