diff options
author | 2009-07-13 16:33:06 -0400 | |
---|---|---|
committer | 2009-07-13 16:33:06 -0400 | |
commit | 95a7662f208271ca305844266ff74062d50dff5b (patch) | |
tree | 390a7524d3608760ca47b9d42bad5710e6f6c892 /core | |
parent | ce026c2b52f0461b02b2af4d89fbcce3c8994848 (diff) | |
download | textadept-95a7662f208271ca305844266ff74062d50dff5b.tar.gz textadept-95a7662f208271ca305844266ff74062d50dff5b.zip |
Added incremental find.
Diffstat (limited to 'core')
-rw-r--r-- | core/ext/command_entry.lua | 1 | ||||
-rw-r--r-- | core/ext/find.lua | 49 | ||||
-rw-r--r-- | core/ext/key_commands.lua | 12 | ||||
-rw-r--r-- | core/ext/menu.lua | 3 | ||||
-rw-r--r-- | core/locale.conf | 8 |
5 files changed, 66 insertions, 7 deletions
diff --git a/core/ext/command_entry.lua b/core/ext/command_entry.lua index 6d46c5c6..4c1ab0dd 100644 --- a/core/ext/command_entry.lua +++ b/core/ext/command_entry.lua @@ -7,6 +7,7 @@ textadept.events.add_handler('command_entry_command', function(command) -- execute a Lua command local f, err = loadstring(command) if err then error(err) end + textadept.command_entry.focus() -- toggle focus to hide f() end) diff --git a/core/ext/find.lua b/core/ext/find.lua index 950d5aa7..c68b97e3 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -157,6 +157,55 @@ end textadept.events.add_handler('find', find_) --- +-- [Local function] Finds and selects text incrementally in the current buffer +-- from a start point. +-- Flags other than SCFIND_MATCHCASE are ignored. +-- @param text The text to find. +local function find_incremental(text) + local c = textadept.constants + local flags = find.match_case and c.SCFIND_MATCHCASE or 0 + --if find.lua then flags = flags + 8 end + buffer:goto_pos(find.incremental_start or 0) + find_(text, true, flags) +end + +--- +-- Begins an incremental find using the Lua command entry. +-- Lua command functionality will be unavailable until the search is finished +-- (pressing 'Escape' by default). +function find.find_incremental() + find.incremental = true + find.incremental_start = buffer.current_pos + textadept.command_entry.entry_text = '' + textadept.command_entry.focus() +end + +textadept.events.add_handler('command_entry_keypress', + function(code) + if find.incremental then + if code == 0xff1b then -- escape + find.incremental = nil + elseif code < 256 or code == 0xff08 then -- character or backspace + local text = textadept.command_entry.entry_text + if code == 0xff08 then + find_incremental(text:sub(1, -2)) + else + find_incremental(text..string.char(code)) + end + end + end + end, 1) -- place before command_entry.lua's handler (if necessary) + +textadept.events.add_handler('command_entry_command', + function(text) -- 'find next' for incremental search + if find.incremental then + find.incremental_start = buffer.current_pos + 1 + find_incremental(text) + return true + end + end, 1) -- place before command_entry.lua's handler (if necessary) + +--- -- [Local function] Replaces found text. -- 'find_' is called first, to select any found text. The selected text is then -- replaced by the specified replacement text. diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua index 370aa1e3..a9858ddb 100644 --- a/core/ext/key_commands.lua +++ b/core/ext/key_commands.lua @@ -97,6 +97,7 @@ if not MAC then -- Find Next is an when find pane is focused. -- Find Prev is ap when find pane is focused. -- Replace is ar when find pane is focused. + keys.csf = { t.find.find_incremental } -- Find in Files is ai when find pane is focused. -- TODO: { t.find.goto_file_in_list, true } -- TODO: { t.find.goto_file_in_list, false } @@ -203,7 +204,7 @@ else --[[ C: J L U W X Z - A: B D E H I J K L U + A: B D E H J K L U CS: C D G H I J K L M O Q S T U V W X Y Z SA: A B C D H I J K L M N O Q R T U V X CA: A C E J K L M N O Q R S T U V W X Y Z @@ -276,10 +277,11 @@ else } -- Search - keys.af = { t.find.focus } -- find/replace - keys.ag = { t.find.call_find_next } - keys.sag = { t.find.call_find_prev } - keys.ar = { t.find.call_replace } + keys.af = { t.find.focus } -- find/replace + keys.ag = { t.find.call_find_next } + keys.sag = { t.find.call_find_prev } + keys.ar = { t.find.call_replace } + keys.ai = { f.find.find_incremental } keys.saf = { function() t.find.in_files = true diff --git a/core/ext/menu.lua b/core/ext/menu.lua index b053cf91..2d315764 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -75,6 +75,7 @@ local ID = { REPLACE = 305, REPLACE_ALL = 306, FIND_IN_FILES = 308, + FIND_INCREMENTAL = 311, GOTO_NEXT_FILE_FOUND = 309, GOTO_PREV_FILE_FOUND = 310, GOTO_LINE = 307, @@ -209,6 +210,7 @@ local menubar = { { l.MENU_SEARCH_FIND_AND_REPLACE, ID.FIND_AND_REPLACE }, { l.MENU_SEARCH_REPLACE, ID.REPLACE }, { l.MENU_SEARCH_REPLACE_ALL, ID.REPLACE_ALL }, + { l.MENU_SEARCH_FIND_INCREMENTAL, ID.FIND_INCREMENTAL }, { SEPARATOR, ID.SEPARATOR }, { l.MENU_SEARCH_FIND_IN_FILES, ID.FIND_IN_FILES }, { l.MENU_SEARCH_GOTO_NEXT_FILE_FOUND, ID.GOTO_NEXT_FILE_FOUND }, @@ -441,6 +443,7 @@ local actions = { [ID.FIND_AND_REPLACE] = { t.find.focus }, [ID.REPLACE] = { t.find.call_replace }, [ID.REPLACE_ALL] = { t.find.call_replace_all }, + [ID.FIND_INCREMENTAL] = { t.find.find_incremental }, [ID.FIND_IN_FILES] = { function() t.find.in_files = true diff --git a/core/locale.conf b/core/locale.conf index b7ea6e68..00300a6b 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -404,8 +404,12 @@ MENU_SEARCH_REPLACE "Replace" MENU_SEARCH_REPLACE_ALL "Replace _All" % core/ext/menu.lua -% "Find in F_iles" -MENU_SEARCH_FIND_IN_FILES "Find in F_iles" +% "Find _Incremental" +MENU_SEARCH_FIND_INCREMENTAL "Find _Incremental" + +% core/ext/menu.lua +% "Find in Fi_les" +MENU_SEARCH_FIND_IN_FILES "Find in Fi_les" % core/ext/menu.lua % "Goto Next File Found" |