How can I insert text at the caret position of a StyledText in SWT?
An example of what I mean is as follows:
I have a StyledText with "Hello, world!", in. The caret position is in between the space and w, like so (the vertical bar/pipe, "|", is my blinking cursor):
Hello, |world!
I need some sort of way to insert text, so if I did something like myMethodThatInsertsText("beautiful "), it will change the text to (vertical bar still being cursor):
Hello, beautiful |world!
Do I have to do this manually, or is there a method that I just haven't found yet?
The method StyledText#insert(String)
does exactly what you want.
If text is selected within the StyledText
, insert
will replace that text. However, if nothing is selected, the text will be inserted at the caret position.