Skip to content

Commit a1cd5fa

Browse files
committed
fix Enter being swallowed by chat mode-map <return> binding
1 parent 98ac99a commit a1cd5fa

5 files changed

Lines changed: 30 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
- Bugfix: Enter now works with transient/overriding keymaps that bind only `"RET"` (e.g. Embark's action maps) inside chat buffers. `eca-chat-mode-map` bound the raw `<return>` event, which blocked the `<return>` -> `RET` key translation in GUI frames, so those keymaps' `RET` binding was never reached and the keypress silently fell through to `eca-chat--key-pressed-return` instead; only `RET` is bound now.
56
- Restore the rolled-back user message into the prompt field. `Rollback chat to before this message` (when messages are included) used to discard the clicked message's text together with the rest of the turn; the text now lands in the prompt unsent, ready to edit and resend, and any draft already typed in the prompt is kept below it, separated by a blank line.
67
- Fall back to the buffer's `xref` backend (eglot, etags with a loaded tags table, any custom backend) for `editor/getDefinition`/`editor/getReferences` when lsp-mode cannot serve the file, instead of answering no-server. `includeDeclaration: false` is honored by filtering definition locations out of the references, since LSP-backed xref backends always include the declaration. (editor-code-assistant/eca#351)
78

‎eca-chat-expandable.el‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ NESTED-PROPS is a plist with :parent-id and :label-indent for nested blocks."
291291
(define-key km (kbd "<mouse-1>") (lambda () (interactive) (eca-chat--expandable-content-toggle id)))
292292
(define-key km (kbd "<tab>") (lambda () (interactive) (eca-chat--expandable-content-toggle id)))
293293
(define-key km (kbd "RET") (lambda () (interactive) (eca-chat--expandable-content-toggle id)))
294-
(define-key km (kbd "<return>") (lambda () (interactive) (eca-chat--expandable-content-toggle id)))
295294
km)
296295
'help-echo "mouse-1 / tab / RET: expand/collapse"))
297296
(eca-chat--insert "\n")

‎eca-chat-image.el‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,11 @@ always use the textual fallback."
355355
(format "Image (%s, %d bytes) — RET or mouse-2 to save"
356356
(or (plist-get image-content :mediaType) "?")
357357
(length (image-property image :data))))
358-
;; Bind both `RET' (terminal) and `<return>' (graphical
359-
;; frame function-key event) so RET works regardless of
360-
;; whether the chat mode-map has the function-key bound;
361-
;; otherwise `eca-chat--key-pressed-return' shadows ours.
362358
(let* ((save-fn (lambda ()
363359
(interactive)
364360
(eca-chat-save-image-at-point ov)))
365361
(map (make-sparse-keymap)))
366362
(define-key map (kbd "RET") save-fn)
367-
(define-key map (kbd "<return>") save-fn)
368363
(define-key map [mouse-2] save-fn)
369364
(overlay-put ov 'keymap map))))))
370365
(parent-tool-call-id

‎eca-chat.el‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,6 @@ and resume link are not left behind under the replayed messages.")
843843
(define-key map (kbd "C-<return>") #'eca-chat--key-pressed-queue)
844844
(define-key map (kbd "C-<up>") #'eca-chat--key-pressed-previous-prompt-history)
845845
(define-key map (kbd "C-<down>") #'eca-chat--key-pressed-next-prompt-history)
846-
(define-key map (kbd "<return>") #'eca-chat--key-pressed-return)
847846
(define-key map (kbd "RET") #'eca-chat--key-pressed-return)
848847
(define-key map (kbd "C-c C-<return>") #'eca-chat-send-prompt-at-chat)
849848
;; Bind only TAB, never the raw <tab> function-key event: binding
@@ -6237,11 +6236,10 @@ ECA chat state, prompt overlays, and rule-based hints."
62376236
derived from `eca-chat-mode'. `eca-chat-mode' likely failed to activate." mm)
62386237
hints))
62396238
(when (and in-chat-p
6240-
(not (eq ret-cmd 'eca-chat--key-pressed-return))
6241-
(not (eq return-cmd 'eca-chat--key-pressed-return)))
6242-
(push (format "RET is bound to `%s' (and <return> to `%s'), not \
6239+
(not (eq ret-cmd 'eca-chat--key-pressed-return)))
6240+
(push (format "RET is bound to `%s', not \
62436241
`eca-chat--key-pressed-return'. Another keymap is intercepting RET — see \
6244-
\"Likely shadowing\" below." ret-cmd return-cmd)
6242+
\"Likely shadowing\" below." ret-cmd)
62456243
hints))
62466244
(when (and in-chat-p (null session))
62476245
(push "(eca-session) returned nil from inside the chat buffer — \

‎test/eca-chat-test.el‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,32 @@ does not treat the first line as metadata. Returns FN's value."
16721672
(it "does not bind the raw <tab> event (#281)"
16731673
(expect (lookup-key eca-chat-mode-map (kbd "<tab>")) :to-be nil)))
16741674

1675+
;; ---------------------------------------------------------------------------
1676+
;; eca-chat-mode-map RET bindings
1677+
;; ---------------------------------------------------------------------------
1678+
1679+
(describe "eca-chat-mode-map RET bindings"
1680+
1681+
(it "binds RET to eca-chat--key-pressed-return"
1682+
(expect (lookup-key eca-chat-mode-map (kbd "RET"))
1683+
:to-be #'eca-chat--key-pressed-return))
1684+
1685+
;; Binding raw <return> would block the <return> -> RET key translation
1686+
;; in GUI frames, so transient/overriding keymaps binding only "RET"
1687+
;; (e.g. embark-file-map) would never receive Enter. lookup-key follows
1688+
;; the parent map, so this also catches a future <return> binding
1689+
;; inherited from markdown-mode-map.
1690+
(it "does not bind the raw <return> event"
1691+
(expect (lookup-key eca-chat-mode-map (kbd "<return>")) :to-be nil))
1692+
1693+
;; Modified Enter chords are unaffected: they are distinct events with
1694+
;; no ASCII equivalent, so they must stay bound as function keys.
1695+
(it "still binds the modified <return> chords"
1696+
(expect (lookup-key eca-chat-mode-map (kbd "S-<return>"))
1697+
:to-be #'eca-chat--key-pressed-newline)
1698+
(expect (lookup-key eca-chat-mode-map (kbd "C-<return>"))
1699+
:to-be #'eca-chat--key-pressed-queue)))
1700+
16751701
;; ---------------------------------------------------------------------------
16761702
;; eca-chat--shell-command-state-face
16771703
;; ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)