Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add popup after selection #239

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion lisp/pdf-view.el
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ if available."
:group 'pdf-view
:type 'boolean)

(defcustom pdf-view-selection-show-popup t
"Whether a popup menu will show up after text has been selected.

This variable affects whether to show popup menu like other PDF editors when a text block is selected. Default to true to make this feature known to user."
:group 'pdf-view
:type 'boolean)

(defface pdf-view-region
'((((background dark)) (:inherit region))
(((background light)) (:inherit region)))
Expand Down Expand Up @@ -1408,6 +1415,14 @@ Deactivate the region if DEACTIVATE-P is non-nil."
(deactivate-mark)
(pdf-view-redisplay t)))

(easy-menu-define pdf-view-quick-popup nil "Quick popup"
`("Quick popup"
["Highlight" (pdf-annot-add-highlight-markup-annotation (pdf-view-active-region t) "yellow")]
["Copy" (lambda() (interactive) (kill-new (car (pdf-view-active-region-text))))]
["More" (message "Set variable pdf-view-quick-popup in your startup file to change")]
["Turn off" (customize-variable 'pdf-view-selection-show-popup)]
))

(defun pdf-view-mouse-set-region (event &optional allow-extend-p
rectangle-p
selection-style)
Expand Down Expand Up @@ -1500,7 +1515,11 @@ Stores the region in `pdf-view-active-region'."
(setq pdf-view-active-region
(append pdf-view-active-region
(list region)))
(pdf-view--push-mark))))
(pdf-view--push-mark)
(if (and
pdf-view-selection-show-popup
(not (string-blank-p (car (pdf-view-active-region-text)))))
(popup-menu pdf-view-quick-popup)))))

(defun pdf-view-mouse-extend-region (event)
"Extend the currently active region with mouse event EVENT."
Expand Down