Find a line above or below in Javascript

I am working on an internal HTML editor, focusing only on Firefox. I have an element inserted where the cursor should be, as well as left and right arrows, but I cannot find a way to find:

  • Beginning and end of line for home and end keys
  • Next line up or down for up / down arrows.

I see document.elementFromPoint, but that does not give me a Range object. The Range object itself seems useless when it comes to using pixel positions.

+3
source share
2 answers

, document.elementFromPoint() document.createRange() Range.selectNodeContents();

(100,200)

var elem = document.elementFromPoint(100,200);
var r = document.createRange();
var s = window.getSelection()
r.selectNodeContents(elem);
s.removeAllRanges();
s.addRange(r);

, .

+1

, " ". , ? ?

IE Firefox element.getClientRects() . . . quirksmode .

, , . , P, , Firefox , , P. , .

, , . / /.

0

Source: https://habr.com/ru/post/1737055/


All Articles