forked from dail8859/LuaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighlightOccurrences.lua
More file actions
Latest commit
55 lines (44 loc) · 1.71 KB
/
Copy pathHighlightOccurrences.lua
File metadata and controls
55 lines (44 loc) · 1.71 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- Mark occurrences of the current word under the cursor
-- Adjust these values if desired
localindicator=12-- not sure what one is best to use but this works
editor1.IndicStyle[indicator] =INDIC_ROUNDBOX
editor2.IndicStyle[indicator] =INDIC_ROUNDBOX
editor1.IndicAlpha[indicator] =20
editor2.IndicAlpha[indicator] =20
editor1.IndicOutlineAlpha[indicator] =20
editor2.IndicOutlineAlpha[indicator] =20
npp.AddEventHandler("OnUpdateUI", function()
localfunctiongetRangeOnScreen()
localfirstLine=editor.FirstVisibleLine
locallastLine=firstLine+editor.LinesOnScreen
localstartPos=editor:PositionFromLine(firstLine)
localendPos=editor.LineEndPosition[lastLine]
returnstartPos, endPos
end
localfunctionclearIndicatorOnScreen()
locals, e=getRangeOnScreen()
editor:IndicatorClearRange(s, e-s)
end
editor.IndicatorCurrent=indicator
ifnoteditor.SelectionEmptythen
clearIndicatorOnScreen()
returnfalse
end
localstartWord=editor:WordStartPosition(editor.CurrentPos, true)
localendWord=editor:WordEndPosition(startWord, true)
-- Not a word
ifstartWord==endWordthen
clearIndicatorOnScreen()
returnfalse
end
localword=editor:textrange(startWord, endWord)
clearIndicatorOnScreen()
-- for each match on screen turn on the indicator
localstartPos, endPos=getRangeOnScreen()
locals, e=editor:findtext(word, SCFIND_WHOLEWORD | SCFIND_MATCHCASE, startPos, endPos)
whiles~=nildo
editor:IndicatorFillRange(s, e-s)
s, e=editor:findtext(word, SCFIND_WHOLEWORD | SCFIND_MATCHCASE, e, endPos)
end
returnfalse
end)