Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion eca-chat-context.el
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,9 @@ DATA is the binary image data as a string."
(seq-some (lambda (type)
(and (symbolp type)
(string-match-p "^image/" (symbol-name type))))
(if (vectorp targets) (append targets nil) targets))))
(cond ((vectorp targets) (append targets nil))
((symbolp targets) (list targets))
(t targets)))))

(defun eca-chat--yank-considering-image (orig-fun &rest args)
"Around advice for paste commands to use `yank-media' for images.
Expand Down
26 changes: 26 additions & 0 deletions test/eca-chat-context-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,31 @@
(set-buffer-modified-p nil))
(kill-buffer buf))))))

(describe "eca-chat--clipboard-image-p"
(before-each
(spy-on 'display-graphic-p :and-return-value t))

(it "returns non-nil when TARGETS contains an image type"
(spy-on 'gui-get-selection
:and-return-value (vector 'TARGETS 'UTF8_STRING 'image/png))
(expect (eca-chat--clipboard-image-p) :to-be-truthy))

(it "returns nil when TARGETS is a vector without an image type"
(spy-on 'gui-get-selection
:and-return-value (vector 'TARGETS 'UTF8_STRING 'STRING))
(expect (eca-chat--clipboard-image-p) :to-be nil))

(it "returns nil without erroring when TARGETS is a bare symbol"
;; Some X11 clients (e.g. st) only advertise a single selection
;; target, in which case `gui-get-selection' returns a bare
;; symbol instead of a vector/list of targets.
(spy-on 'gui-get-selection :and-return-value 'UTF8_STRING)
(expect (eca-chat--clipboard-image-p) :to-be nil))

(it "returns non-nil when TARGETS is a list containing an image type (default pass-through)"
(spy-on 'gui-get-selection
:and-return-value (list 'TARGETS 'UTF8_STRING 'image/png))
(expect (eca-chat--clipboard-image-p) :to-be-truthy)))

(provide 'eca-chat-context-test)
;;; eca-chat-context-test.el ends here
Loading