문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top