简体   繁体   中英

How to get cursor position in lightning input rich text in lwc?

Sommeone please tell on how to get get cursor position in lightning input rich text in lightning web component.

I am using the following code but getting undefined:

let element = this.template.querySelector("lightning-input-rich-text");
console.log(element.selectionStart, element.selectionEnd);

I wouldn't call it a complete solution.

Use "window.getSelection()" to get the selection indexes, however you might want to ensure the rich text was in focus when selection occurred.

the specified method will return a Selection object, anchorOffset & extentOffset properties will contain the start and end indexes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM