简体   繁体   中英

How can I check if contenteditable caret is inside { }

Okay so i'm currently attempting to make a text editor for css, basically I need to add a tab automatically on new line if the caret is inside { }. I have tried a few ways to go about this and have removed it all as nothing seemed to work, any and all help is appreciated.

Use the Selection API . It has everything you need. Including detecting where the cursor is, determining the surrounding HTML elements and characters, etc.

It is meant to help with identifying selected text but is very robust.

https://developer.mozilla.org/en-US/docs/Web/API/Selection

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