Skip to content

get word under MouseCursor or at Position of a word under the TextCursor, to display HelpScreen on F1 ? #116

Answered by magiblot
paule32 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes. The methods and fields you need are in TEditor. For example, to get the word under the cursor using a custom TMyEditor class which inherits from TEditor:

static bool isWhiteSpace(char c)
{
    return strchr("\t \n\r\0", c) == nullptr;
}

std::string TMyEditor::getWordUnderCursor()
{
    std::string s;

    uint wordEnd = nextWord(curPtr);
    uint wordBegin = prevWord(wordEnd);

    for (uint i = wordBegin; i < wordEnd; ++i)
    {
        char c = bufChar(i);
        if (!isWhiteSpace(c))
            s.push_back(c);
    }

    return s;
}

Now, the word under the cursor may change whenever the cursor position changes or the editor's contents get modified. Therefore you will need to up…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@paule32
Comment options

@magiblot
Comment options

Answer selected by paule32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants