Use onMouseUp
and onDoubleClick
events to detect to call method, that will determine selection using JavaScript Selection API.
Use window.getSelection()
to get selection object.
To get selected text, use window.getSelection.toString()
.
To get coordinates of selected text area for rendering popup menu, use selection.getRangeAt(0).getBoundingClientRect()
.
As an example implementation, take a look at react-highlight library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…