Search code examples
scintillascintillanet

Detect cursor is over comment or string in Scintilla NET


Is there any built in function in Scintilla.NET to detect the cursor is over a comment or string? I'd want to avoid the autocompletion to work when the user is typing comments or strings.

I'm aware I can scan the whole text backwards, searching for //, /* */ and pairs of " " but I'm almost sure there must be a built-in function to do that.

Thanks!


Solution

  • If you're using a lexer, you can get the style number at the current caret postion and check to see if it corresponds with a string or comment. The Scintilla API for retrieving the style number is:

    The Scintilla.NET documentation states there are already some convenience APIs for detecting comments:

    • ScintillaNET.Scintilla.PositionIsOnComment(System.Int32)
    • ScintillaNET.Scintilla.PositionIsOnComment(System.Int32,ScintillaNET.Lexer)

    But there does not seem to be anything equivalent for strings - so it looks like you'll have to roll your own by using the above Scintilla message with one of the ScintillaNET.Scintilla.SendMessageDirect() methods.