aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--core/ext/command_entry.lua1
-rw-r--r--core/ext/find.lua49
-rw-r--r--core/ext/key_commands.lua12
-rw-r--r--core/ext/menu.lua3
-rw-r--r--core/locale.conf8
-rw-r--r--src/textadept.c11
6 files changed, 66 insertions, 18 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"
diff --git a/src/textadept.c b/src/textadept.c
index 6492e858..88dcca7b 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -58,7 +58,6 @@ GtkWidget *find_create_ui();
GtkListStore *find_store, *repl_store;
static void find_button_clicked(GtkWidget *, gpointer);
-static gbool find_entry_keypress(GtkWidget *, GdkEventKey *, gpointer);
// Command Entry
GtkWidget *command_entry;
@@ -811,7 +810,6 @@ GtkWidget *find_create_ui() {
attach(lua_opt, 5, 6, 0, 1, ao_normal, ao_normal, 5, 0);
attach(in_files_opt, 5, 6, 1, 2, ao_normal, ao_normal, 5, 0);
- signal(find_entry, "key-press-event", find_entry_keypress);
signal(fnext_button, "clicked", find_button_clicked);
signal(fprev_button, "clicked", find_button_clicked);
signal(r_button, "clicked", find_button_clicked);
@@ -891,14 +889,6 @@ static void find_button_clicked(GtkWidget *button, gpointer udata) {
}
}
-/**
- * Signal for a Find entry keypress.
- */
-static gbool find_entry_keypress(GtkWidget *entry, GdkEventKey *event,
- gpointer udata) {
- return l_handle_event("find_keypress", LUA_TNUMBER, event->keyval, -1);
-}
-
// Command Entry
/**
@@ -965,7 +955,6 @@ static gbool cec_match_selected(GtkEntryCompletion *entry, GtkTreeModel *model,
static void c_activated(GtkWidget *entry, gpointer udata) {
l_handle_event("command_entry_command", LUA_TSTRING,
gtk_entry_get_text(GTK_ENTRY(entry)), -1);
- ce_toggle_focus();
}
/**