cashiba 发表于 2017-5-8 05:26:47

Scite编辑代码时光标置入关键词处按F1自动....如何实现的?[已解决]

本帖最后由 cashiba 于 2017-5-10 04:05 编辑

如题。
在关键词处置入光标,在没有抹黑关键词明确完整的关键词范围时,是如何自动锁定正确的关键词的?是用正则筛选判断吗?

爱火箭528 发表于 2017-5-8 06:50:46

我来顶帖、、、

tubaba 发表于 2017-5-8 13:18:10

本帖最后由 tubaba 于 2017-5-8 13:25 编辑

调用Scintilla的SCI_GETSELTEXT函数,如果返回空,循環读取光标左右字符,直到单词边界,SCI_GETSELTEXT(<unused>, char *text NUL-terminated) → int
This copies the currently selected text and a terminating 0 byte to the text buffer. The buffer size should be determined by calling with a NULL pointer for the text argument SCI_GETSELTEXT(0,0). This allows for rectangular and discontiguous selections as well as simple selections. See Multiple Selection for information on how multiple and rectangular selections and virtual space are copied.

LUA函数原型function AutoItTools:GetWord2()
        local word = editor:GetSelText()
        if word == "" then
                -- When on an ( or space, go to the start of the previous word.
                if editor.CharAt == 40 or editor.CharAt == 32 then
                        editor:WordLeft()
                end
                -- Cache the style as it's used numerous times.
                local style = editor.StyleAt
                -- The start and end of the text range.
                local from = editor:WordStartPosition(editor.CurrentPos)
                local to = editor:WordEndPosition(editor.CurrentPos)
                -- Use a variable to shorten the for loop code.
                local line = editor:LineFromPosition(editor.CurrentPos)
                -- Caret is on a function.
                if style == SCE_AU3_FUNCTION or style == SCE_AU3_DEFAULT or style == SCE_AU3_UDF then
                        -- A counter of the number of opening brackets encountered.
                        local brackets = 0
                        -- A flag set to true if an opening bracket is encountered.
                        local found = false
                        -- Iterate the line looking for the end of the function call.
                        for i = editor.CurrentPos, editor.LineEndPosition do
                                -- Make sure we don't count brackets in strings.
                                if editor.StyleAt ~= SCE_AU3_STRING then
                                        -- Found an opening bracket, increment counter and set flag.
                                        if editor.CharAt == 40 then
                                                brackets = brackets + 1
                                                found = true
                                        end
                                        -- Found a closing bracket, decrement counter.
                                        if editor.CharAt == 41 then
                                                brackets = brackets - 1
                                        end
                                end
                                -- We found a bracket and we found the end, set to and break.
                                if found and brackets == 0 then
                                        to = i + 1
                                        break
                                end
                        end
                        -- If we didn't find any brackets, just return the simple GetWord().
                        if not found then
                                return self:GetWord()
                        end
                -- Caret is in a string.
                elseif style == SCE_AU3_STRING then
                        -- Find the start of the string.To do this, we iterate backwards
                        -- to the indentation.
                        for i = editor.CurrentPos, editor.LineIndentPosition - 1, -1 do
                                if editor.StyleAt ~= SCE_AU3_STRING then
                                        -- We have to add 1 or we'll pick up the non-string
                                        -- character as well.
                                        from = i + 1
                                        break
                                end
                        end
                        -- Find the end of the string.To do this, we iterate forwards to
                        -- the end of the string.
                        for i = editor.CurrentPos, editor.LineEndPosition do
                                if editor.StyleAt ~= SCE_AU3_STRING then
                                        to = i
                                        break
                                end
                        end
                end
                -- Get the text range.
                word = editor:textrange(from, to)
        end
        return word
end    -- GetWord2()

cashiba 发表于 2017-5-10 04:04:16

调用Scintilla的SCI_GETSELTEXT函数,如果返回空,循環读取光标左右字符,直到单词边界,LUA函数原型
tubaba 发表于 2017-5-8 13:18 http://www.autoitx.com/images/common/back.gif
原来是用的Lua函数....感谢tubaba大侠解惑~
{:face (88):}
页: [1]
查看完整版本: Scite编辑代码时光标置入关键词处按F1自动....如何实现的?[已解决]