سؤال

Triple-clicking the mouse to select a paragraph sets document.getSelection().leftOffset to 0 (which seems right) but the rightOffset property is set to 1, so code that processes the selection produces results consistent with only the first character in the paragraph being selected. Is this a bug, or am I missing something?

هل كانت مفيدة؟

المحلول

I assume you mean anchorOffset and focusOffset rather than leftOffset and rightOffset.

Anyway, yes, you're missing something: anchorOffset and focusOffset are not necessarily relative to a text node. They can instead be relative to an element, in which case the offset is the number of child nodes of the container node (anchorNode or focusNode) preceding the selection boundary in question. In your case, the selection extends from the start of zeroth child (i.e. the start) of the paragraph's parent to the point after the first child (which is the paragraph itself).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top