forked from dail8859/LuaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelectionAddNext.lua
26 lines (25 loc) · 1.13 KB
/
SelectionAddNext.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- Select the next occurrence of the current word
npp.AddShortcut("Selection Add Next", "Ctrl+D", function()
-- From SciTEBase.cxx
local flags = SCFIND_MATCHCASE -- can use 0
editor:SetTargetRange(0, editor.TextLength)
editor.SearchFlags = flags
-- From Editor.cxx
if editor.SelectionEmpty or not editor.MultipleSelection then
local startWord = editor:WordStartPosition(editor.CurrentPos, true)
local endWord = editor:WordEndPosition(startWord, true)
editor:SetSelection(startWord, endWord)
else
local i = editor.MainSelection
local s = editor:textrange(editor.SelectionNStart[i], editor.SelectionNEnd[i])
local searchRanges = {{editor.SelectionNEnd[i], editor.TargetEnd}, {editor.TargetStart, editor.SelectionNStart[i]}}
for _, range in pairs(searchRanges) do
editor:SetTargetRange(range[1], range[2])
if editor:SearchInTarget(s) ~= -1 then
editor:AddSelection(editor.TargetStart, editor.TargetEnd)
editor:ScrollRange(editor.TargetStart, editor.TargetEnd)
break
end
end
end
end)