How to get the word or token under the cursor

SyntaxEditor for Windows Forms Forum

Posted 15 years ago by shark92651
I want to define an EditAction that will do something with the word that the cursor is on. Is there an easy way to get this? It would need to read up to the delimiters that are defined for the language. It would be ideal if it would handle "dot" notation and return the entire identifier. For example, if I have the text "Hello World" and the caret is somewhere inside "World", I would like to return just "World". However, if the text is "Hello.World", I would like to return "Hello.World".

Comments (1)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
While there are EditorView.GetCurrentWordRange and EditorView.GetCurrentWordText methods, if you want something more complex, then the best thing to do would be to get a TextStream (Document.GetTextStream) at the selected view's end offset (the caret offset), and then scan one way to find the beginning of the word and then back the other way to find the end. TextStream even has methods like GoToNextWordStart, etc. that you can use for this.

Actipro Software Support

The latest build of this product (v2018.1 build 0341) was released 6 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.