Scite Mark Word

lua-users home
wiki

您可以使用此功能来标记文档中某个单词的所有出现位置。

您应该在您的 SciTEUser.properties 文件中添加类似以下内容:

command.name.37.*=markOccurrences
command.mode.37.*=subsystem:lua,savebefore:no
command.37.*=markOccurrences
command.shortcut.37.*=Ctrl+.

command.name.38.*=clearOccurrences
command.mode.38.*=subsystem:lua,savebefore:no
command.38.*=clearOccurrences
command.shortcut.38.*=Ctrl+,

而此功能则在您的 SciTEStartup.lua 文件中:

function clearOccurrences()
    scite.SendEditor(SCI_SETINDICATORCURRENT, 0)
    scite.SendEditor(SCI_INDICATORCLEARRANGE, 0, editor.Length)
end

function markOccurrences()
    if editor.SelectionStart == editor.SelectionEnd then
        return
    end
    clearOccurrences()
    scite.SendEditor(SCI_INDICSETSTYLE, 0, INDIC_ROUNDBOX)
    scite.SendEditor(SCI_INDICSETFORE, 0, 255)
    local txt = GetCurrentWord()
    local flags = SCFIND_WHOLEWORD
    local s,e = editor:findtext(txt,flags,0)
    while s do
        scite.SendEditor(SCI_INDICATORFILLRANGE, s, e - s)
        s,e = editor:findtext(txt,flags,e+1)
    end
end

function isWordChar(char)
    local strChar = string.char(char)
    local beginIndex = string.find(strChar, '%w')
    if beginIndex ~= nil then
        return true
    end
    if strChar == '_' or strChar == '$' then
        return true
    end
    
    return false
end

function GetCurrentWord()
    local beginPos = editor.CurrentPos
    local endPos = beginPos
    if editor.SelectionStart ~= editor.SelectionEnd then
        return editor:GetSelText()
    end
    while isWordChar(editor.CharAt[beginPos-1]) do
        beginPos = beginPos - 1
    end
    while isWordChar(editor.CharAt[endPos]) do
        endPos = endPos + 1
    end
    return editor:textrange(beginPos,endPos)
end

--Agustín Fernández, 2007 年 8 月 22 日

我在 markOccurrences 的开头添加了一个对无选中的测试,以防止 Scite (ver 3.5.2) 在编辑器中没有选中任何内容时崩溃。

--Gavin Holt, 2014 年 12 月 20 日


RecentChanges · preferences
编辑 · 历史
最后编辑于 2014 年 12 月 20 日 下午 4:23 GMT (差异)