Add support for copying text content of screenshot

This is basically just useful because of the automatic de-indentation.
This commit is contained in:
TEC 2023-01-19 23:59:13 +08:00
parent d84a8581bd
commit e2a364c1a1
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 15 additions and 1 deletions

View File

@ -486,6 +486,19 @@ If BODY starts with :no-img then `screenshot--process' is not called."
(delete-file screenshot--tmp-file)
(message "Screenshot copied"))
(screenshot--def-action text-copy
"Copy the current selection (BEG-END) as text to the clipboard."
:no-img
(let ((content (string-trim-right (buffer-substring beg end))))
(with-temp-buffer
(insert content)
(when screenshot-remove-indent-p
(indent-rigidly (point-min) (point-max)
(- (indent-rigidly--current-indentation
(point-min) (point-max)))))
(gui-select-text (buffer-substring-no-properties
(point-min) (point-max))))))
(defcustom screenshot-upload-fn nil
"Function or string which provides a method to upload a file.
If a function, it must take a filename and returns a URL to it.
@ -573,7 +586,8 @@ return a URL."
("u" "Image" screenshot-upload)
("U" "Text" screenshot-text-upload)]
["Copy"
("c" "Image" screenshot-copy)]])
("c" "Image" screenshot-copy)
("C" "Text" screenshot-text-copy)]])
(provide 'screenshot)
;;; screenshot.el ends here