Created
July 5, 2010 20:51
-
-
Save rgieseke/464675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Experimental search for Textadept using the status bar | |
-- ctrl-f, ctrl-g: next, ctrl-shift-g: previous | |
-- backspace: delete all, delete: delete one char | |
keys.cf = {function() | |
local KEYSYMS = _m.textadept.keys.KEYSYMS | |
local string_char = string.char | |
local search_term = '' | |
gui.statusbar_text = 'Search: ' | |
events.emit('update_ui') | |
events.connect('keypress', function(code, shift, control, alt) | |
if KEYSYMS[code] == 'esc' or | |
KEYSYMS[code] == 'up' or | |
KEYSYMS[code] == 'down' or | |
KEYSYMS[code] == 'left' or | |
KEYSYMS[code] == 'right' then | |
events.disconnect('keypress', 1) | |
gui.statusbar_text = '' | |
return | |
elseif control and code == 103 then --"g" | |
buffer:goto_pos(buffer.anchor) | |
buffer:search_anchor() | |
result = buffer:search_next(0, search_term) | |
buffer:scroll_caret() | |
if result == -1 then | |
buffer:document_start() | |
buffer:search_anchor() | |
buffer:search_next(0, search_term) | |
buffer:scroll_caret() | |
end | |
return true | |
elseif control and shift and code == 71 then --"G" | |
buffer:search_anchor() | |
result = buffer:search_prev(0, search_term) | |
buffer:scroll_caret() | |
if result == -1 then | |
buffer:document_end() | |
buffer:search_anchor() | |
buffer:search_prev(0, search_term) | |
buffer:scroll_caret() | |
end | |
return true | |
elseif KEYSYMS[code] == '\b' then -- backspace | |
search_term = '' | |
gui.statusbar_text = 'Search: ' | |
return true | |
elseif KEYSYMS[code] == 'del' then | |
search_term = string.sub(search_term, 1, #search_term -1) | |
gui.statusbar_text = 'Search: '..search_term | |
return true | |
elseif code < 256 then | |
char= string_char(code) | |
search_term = search_term..char | |
gui.statusbar_text = 'Search: '..search_term | |
buffer:search_anchor() | |
result = buffer:search_next(0, search_term) | |
buffer:scroll_caret() | |
if result == -1 then | |
buffer:document_start() | |
buffer:search_anchor() | |
buffer:search_prev(0, search_term) | |
buffer:scroll_caret() | |
end | |
return true | |
else | |
-- other keys are not processed | |
return true | |
end | |
end | |
, 1) | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment