I have a TextBox in a GWT app I'm building that's used for advanced searched. I'm trying to find a way to use syntax highlighting for certain characters sequences (e.g. the string #title, or just #T) in the search string, but I can't find anything about how to allow for coloring of individual symbols. I suppose I need something more complex than just a TextBox but I'm not sure what to use. Would it perhaps be possible to do with a single-line, stripped down RichTextBox, or is there a better way?
Asked
Active
Viewed 408 times
1 Answers
2
You cannot do it with an input. Use a FlowPanel (or simply a div element), and set ContentEditable on it. Most browsers support it now. Then you can insert regular HTML tags (bold, span) inside the text on KeyUpEvent, and you can style the spans anyway you like.

Andrei Volgin
- 40,755
- 6
- 49
- 58
-
This works with the exception that the caret position resets to the first character with every keyUp. I'm using a HTML (which is compiled into a div) wrapped in a FocusPanel (for keyUpHandling), and it doesn't have any get or set caret positions. I was trying to post a few line of codes but I can't get the indentation to work... – Jonas Rosenqvist Feb 19 '14 at 18:17
-
Look at this: http://stackoverflow.com/questions/512528/set-cursor-position-in-html-textbox – Andrei Volgin Feb 19 '14 at 18:23
-
Thanks, but I don't really know JavaScript. I've tried just copying it into a native method but it just keeps returning 0. – Jonas Rosenqvist Feb 19 '14 at 19:07