pdf-tools icon indicating copy to clipboard operation
pdf-tools copied to clipboard

FR: Double clicking on a word to highlight it

Open haji-ali opened this issue 1 year ago • 3 comments

Would it be possible to make it so that double-clicking on a word in the pdf document selects that word? This is the default in most modern pdf viewers (and is what double-clicking on a word does in an Emacs buffer by default).

Of course I would much rather have a way to navigate and selected text in a pdf using the keyboard, but I understand that's a difficult problem to solve.

haji-ali avatar Jul 24 '22 08:07 haji-ali

Check out my fork https://github.com/orgtre/pdf-tools (pull request pending) which adds full keyboard navigation to pdf-tools. This is achieved either by rendering the cursor as a region in the page, which can be slow, or as a faster alternative, with pdf-keynav-pointer-as-cursor-minor-mode the mouse pointer is used as cursor.

As a side-effect one gets better mouse selection commands too. After you enable pdf-keynav-minor-mode, single-clicking selects letter, double-clicking selects word, triple-clicking (or shift clicking) selects sentence, shift double-clicking selects paragraph, and whatever you have bound to mark-whole-buffer selects the whole page.

orgtre avatar Jul 28 '22 11:07 orgtre

Thanks @orgtre, this looks nice and implements the features I am looking for (and more).

BTW, is there a way to select text with the keyboard? For example by setting a mark and moving the cursor similar to standard text in Emacs? Also I didn't think that the region cursor was slow, but it does disappear on some characters (weirdly this happens on moving forward while moving backward is much more consistent).

haji-ali avatar Jul 28 '22 18:07 haji-ali

Sure, you can select text with the keyboard. Everything works pretty much like in a normal Emacs buffer, so you set mark and move with the standard keys you'd use for that (see pdf-keynav-minor-mode-map). However, transient-mark-mode is not activated by default as this again makes things slower. This means you don't see the region unless you copy or annotate it, or activate transient-mark-mode by toggling pdf-keynav-transient-mark-mode.

It would be very helpful if you report any issues with disappearing cursors or other things at https://github.com/orgtre/pdf-tools/issues, preferable with an example pdf and a reproducible description of when the issue occurs (I thought I had gotten rid of most).

orgtre avatar Jul 28 '22 21:07 orgtre