0

I am building a widget like piece for webpage in which a user will type his code and I need to implement the brace highlighter on it. so if a user types

 if(a == b)

the braces around a and b should be highlighted with a color indicating the scope. When a user will click around any of these brackets,the other bracket and that bracket it self will be highlighted and same will happen when a user types in and a set of bracket is completed.

For this I am using a contenteditable div and using the window.getSelection() to determine if the character which was clicked/focused on was a brace and then wrapping span tag around it to give it a color.

I am using innerHTML to set the new HTML inside the div with colored brace,but the focus is reset to the start of the div.

I wanted it to behave like a generic code editor.

Any ideas/directions or some other approach are welcomed.

Regards.

techie_28
  • 2,123
  • 4
  • 41
  • 62

0 Answers0