Click find script [fix]

From: Jay <>
Date: Tue, 27 Apr 2010 21:45:53 -0700 (PDT)

While I'm at it, the other day I began using the wiki's clickfind
script and found that it had a bug when the same word was contained
twice in the same line, with the first occurrence being at the line-

Here is the fixed and optimized highlightFind function for the script:

function highlightFind(position, line)
        -- Grab the word that was clicked on
        needle = buffer:get_sel_text()
        -- Trim any whitespace
        needle = needle:gsub('%s', '')
        -- Escape unwanted characters
        needle = needle:gsub('([().*+?^$%%[%]-])', '%%%1')
        -- Clear out the old marks
        buffer.indicator_current = 0
        buffer:indicator_clear_range(0, buffer.length)
        -- Don't look for zero-length strings
        if #needle > 0 then
                for i = 0, buffer.line_count do
                        local text = buffer:get_line(i)
                        if #text>0 then
                                local first, last = 0, 0
                                while first do
                                        first, last = text:find("%f[%w]"..needle.."%f[%W]",last)
                                        if last then
                                                buffer:marker_add(i, BACK_MARKER_NUMBER)
                                                if (first ~= nil) and (first >0) then
                                                        first = first - 1
                                                local head = last - first
                                                buffer:indicator_fill_range(buffer:position_from_line(i)+ first,
head )
                                                last = last+1
                --buffer:set_sel(position, position) -- restore caret


You received this message because you are subscribed to the Google Groups "textadept" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at
Received on Wed 28 Apr 2010 - 00:45:53 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:44:06 EST