Scite 標示文字

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 (3.5.2 版本) 在編輯器中沒有選擇的情況下停止崩潰。

--Gavin Holt, 2014 年 12 月 20 日


最近的變更 · 偏好設定
編輯 · 歷史
最後的編輯:2014 年 12 月 20 日 10:23 pm GMT (diff)