brettz9 / jump-to-anchor

Jump to the closest anchor for a selected element
MIT License
9 stars 2 forks source link

hotkey to select and copy #22

Open Zedroid opened 4 months ago

Zedroid commented 4 months ago

could you please add keyboard shortcuts to let me copy the text paragrph down from anchor point? i use a tts screen reader through my clipboard

brettz9 commented 4 months ago

My health and energy are not great, so will have to see how I'm feeling as to whether I can get to this.

Zedroid commented 4 months ago

It's ok. I'm sorry to hear. Take care. Get well soon.

brettz9 commented 3 weeks ago

I'm finding it tricky to pinpoint an effective algorithm for different cases...

For example, given Wikipedia's structure:

<h2><span id="Some_heading">Some heading</span></h2>
<p>Some paragraph of text...</p>

...by clicking into the paragraph, we might:

  1. Look for an anchor, but since the paragraph is not an anchor, we look at the element above the paragraph, and since it too is not an anchor, we look for the deepest child, and since it is an anchor, return this element (and if it weren't, keep looking up the chain for ancestor nodes).
  2. Just grab the parent node of the paragraph text selection and get the paragraph text

No. 1 is what we do now, but it is a problematic in this case, as we don't want the anchor. No. 2 works but it doesn't work well with structures like:

<a name="par1"></a>
Some <u>underlined</u> text here...
<a name="par2"></a>
Some more text...

...as clicking somewhere on "text here..." will just get "text here..." (and grabbing the parent node of "text here..." is not ideal as it will grab the text of all paragraphs).

Perhaps the algorithm should look only between but not including the nearest previous and nearest following anchor (unless the clicked area is itself an anchor, in which case, just grab the contents, e.g., if one clicked on the heading above). This might be difficult to define precisely, however...