Detecting words

29 views
Skip to first unread message

Andrew Truckle

unread,
Jan 17, 2025, 2:43:52 PM1/17/25
to scintilla-interest
I am trying in OnCharAdded:

const auto pos = m_edit.GetCurrentPos();
const auto wordStart = m_edit.WordStartPosition(pos, true);
const auto prevWordStart = m_edit.WordStartPosition(wordStart - 1, true);

// Calculate the length of the text range
const auto rangeLength = pos - prevWordStart;
std::string text(rangeLength, '\0'); // Pre-allocate space for the text

Scintilla::TextRangeFull tr{ prevWordStart, pos, text.data() };
m_edit.GetTextRangeFull(&tr);

I can correct text the string for "xsl:". That is good. But if I then want to test again the function names, eg I now have:

"<xsl:apply-templates "

So they just hit the space. If I run this code now the word retried is not "apply-templates" but "templates". What is the right way to handle this? I was hoping the show the parameter list for apply-templates. But because it only gave me "templates" it fails.

Matt G

unread,
Jan 18, 2025, 10:05:57 AM1/18/25
to scintilla...@googlegroups.com
Have you used SCI_SETWORDCHARS to set the characters which comprise words and included "-"? Scintilla Documentation



Andrew Truckle

unread,
Jan 18, 2025, 10:31:27 AM1/18/25
to scintilla-interest
Hi Matt

I have not investigated that. Bu I now realise that even that is not sufficient. For example:

<xsl:variable name="happy" ^

If I have typed the above and the cursor is now where the ^  is. At the point I need to detect:
1. That the command is xsl:variable
2. That the name parameter has already been applied.
3. Display the Select value in the drop-list.

My original idea will not work anyway. It would only work if I am on the first parameter. So this is where I am getting confused. Whilst I can display a function list, or a parameter list, I need to know the context. I am not sure how to programatically work that out. Originally I though that I could possibly use reg ex to find the function for the current text. eg: search backword for xsl: and extract the text afterwards, in this case "variable". This would give me the function for showing the parameter list. But I don't know how. 

Andrew Truckle

unread,
Jan 18, 2025, 10:42:22 AM1/18/25
to scintilla-interest
If I add:

m_edit.SetWordChars("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-");

Then yes, it returns the word including the hyphen. So I see a parameter list. But if I then choose a parameter and assign a value and hit space, not we show no list (as per my previous message).

Either there is design concept I need to take on board or something else. Or I am trying to achieve too much.

Mitchell

unread,
Jan 18, 2025, 10:44:04 AM1/18/25
to scintilla...@googlegroups.com
Hi,

> On Jan 18, 2025, at 10:31 AM, Andrew Truckle <truc...@gmail.com> wrote:
>
> Hi Matt
>
> I have not investigated that. Bu I now realise that even that is not sufficient. For example:
>
> <xsl:variable name="happy" ^
>
> If I have typed the above and the cursor is now where the ^ is. At the point I need to detect:
> 1. That the command is xsl:variable
> 2. That the name parameter has already been applied.
> 3. Display the Select value in the drop-list.
>
> My original idea will not work anyway. It would only work if I am on the first parameter. So this is where I am getting confused. Whilst I can display a function list, or a parameter list, I need to know the context. I am not sure how to programatically work that out. Originally I though that I could possibly use reg ex to find the function for the current text. eg: search backword for xsl: and extract the text afterwards, in this case "variable". This would give me the function for showing the parameter list. But I don't know how.

If you know your tags will only span one line, you could use SCI_GETCURLINE and manually parse the returned string up to the returned position, splitting on spaces for example. Otherwise you’re getting into very complex territory that probably involves iterating backwards, looking for a ‘<‘ not in a string and then parsing the result.

Cheers,
Mitchell

Andrew Truckle

unread,
Jan 18, 2025, 11:44:44 AM1/18/25
to scintilla-interest
Alright, I think for now I am going to keep things simple. I'll just check for xsl: and at that point show a function list. Not complicate it with any other stuff.
Reply all
Reply to author
Forward
0 new messages