selectionaddnext.lua
npp.AddShortcut("Selection Add Next", "Ctrl+D", function()
local flags = SCFIND_MATCHCASE editor:SetTargetRange(0, editor.TextLength)
editor.SearchFlags = flags
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)