找回密码
 加入
搜索
查看: 1702|回复: 3

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

[复制链接]
发表于 2017-5-8 05:26:47 | 显示全部楼层 |阅读模式
本帖最后由 cashiba 于 2017-5-10 04:05 编辑

如题。
在关键词处置入光标,在没有抹黑关键词明确完整的关键词范围时,是如何自动锁定正确的关键词的?是用正则筛选判断吗?
发表于 2017-5-8 06:50:46 | 显示全部楼层
我来顶帖、、、
发表于 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[editor.CurrentPos] == 40 or editor.CharAt[editor.CurrentPos] == 32 then
                        editor:WordLeft()
                end
                -- Cache the style as it's used numerous times.
                local style = editor.StyleAt[editor.CurrentPos]
                -- 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[line] do
                                -- Make sure we don't count brackets in strings.
                                if editor.StyleAt[i] ~= SCE_AU3_STRING then
                                        -- Found an opening bracket, increment counter and set flag.
                                        if editor.CharAt[i] == 40 then
                                                brackets = brackets + 1
                                                found = true
                                        end
                                        -- Found a closing bracket, decrement counter.
                                        if editor.CharAt[i] == 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[line] - 1, -1 do
                                if editor.StyleAt[i] ~= 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[line] do
                                if editor.StyleAt[i] ~= SCE_AU3_STRING then
                                        to = i
                                        break
                                end
                        end
                end
                -- Get the text range.
                word = editor:textrange(from, to)
        end
        return word
end    -- GetWord2()

评分

参与人数 1金钱 +19 收起 理由
cashiba + 19

查看全部评分

 楼主| 发表于 2017-5-10 04:04:16 | 显示全部楼层
调用Scintilla的SCI_GETSELTEXT函数,如果返回空,循環读取光标左右字符,直到单词边界,LUA函数原型
tubaba 发表于 2017-5-8 13:18

原来是用的Lua函数....感谢tubaba大侠解惑~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-27 13:05 , Processed in 0.075858 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表