diff options
Diffstat (limited to 'core/ext')
-rw-r--r-- | core/ext/find.lua | 39 | ||||
-rw-r--r-- | core/ext/key_commands.lua | 21 | ||||
-rw-r--r-- | core/ext/menu.lua | 15 |
3 files changed, 67 insertions, 8 deletions
diff --git a/core/ext/find.lua b/core/ext/find.lua index bf72b833..6bbeba0b 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -254,11 +254,11 @@ function find.replace_all(ftext, rtext, flags) end --- --- When the user double-clicks a found file, go to the line in the file the text --- was found at. +-- [Local function] When the user double-clicks a found file, go to the line in +-- the file the text was found at. -- @param pos The position of the caret. -- @param line_num The line double-clicked. -function goto_file(pos, line_num) +local function goto_file(pos, line_num) if buffer._type == locale.FIND_FILES_FOUND_BUFFER then line = buffer:get_line(line_num) local file, file_line_num = line:match('^(.+):(%d+):.+$') @@ -291,3 +291,36 @@ function goto_file(pos, line_num) end end textadept.events.add_handler('double_click', goto_file) + +--- +-- [Local function] Goes to the next or previous file found relative to the file +-- on the current line. +-- @param next Flag indicating whether or not to go to the next file. +function find.goto_file_in_list(next) + local orig_view = view + for _, buffer in ipairs(textadept.buffers) do + if buffer._type == locale.FIND_FILES_FOUND_BUFFER then + for _, view in ipairs(textadept.views) do + if view.doc_pointer == buffer.doc_pointer then + view:focus() + local orig_line = buffer:line_from_position(buffer.current_pos) + local line = orig_line + while true do + line = line + (next and 1 or -1) + if line > buffer.line_count - 1 then line = 0 end + if line < 0 then line = buffer.line_count - 1 end + if line == orig_line then -- prevent infinite loops + orig_view:focus() + return + end + if buffer:get_line(line):match('^(.+):(%d+):.+$') then + buffer:goto_line(line) + goto_file(buffer.current_pos, line) + return + end + end + end + end + end + end +end diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua index 803fa2cd..4a40ea5a 100644 --- a/core/ext/key_commands.lua +++ b/core/ext/key_commands.lua @@ -22,7 +22,7 @@ if not MAC then --[[ C: B D H I J K L U A: A B C D E F G H J K L M N P R S T U V W X Y Z - CS: A B C D F G H I J K L M N O Q T U V X Y Z + CS: A B C D G H I J K L M N O Q T U V X Y Z SA: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z CA: A B C D E F G H J K L M N O Q R S T U V W X Y Z CSA: A B C D E F G H J K L M N O P Q R S T U V W X Y Z @@ -96,6 +96,9 @@ 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. + -- 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 } keys.cg = { m_editing.goto_line } -- Tools @@ -202,9 +205,9 @@ else C: J L U W X Z A: B D E H I 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 F H I J K L M N O Q R T U V X - CA: A C E G J K L M N O Q R S T U V W X Y Z - CSA: A C D E G H J K L M N O P Q R 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 + CSA: A C D E H J K L M N O P Q R S T U V W X Y Z ]]-- keys.clear_sequence = 'aesc' @@ -276,7 +279,15 @@ else keys.ag = { t.find.call_find_next } keys.sag = { t.find.call_find_prev } keys.ar = { t.find.call_replace } - keys.cg = { m_editing.goto_line } + keys.saf = { + function() + t.find.in_files = true + t.find.focus() + end + } + keys.cag = { t.find.goto_file_in_list, true } + keys.csag = { t.find.goto_file_in_list, false } + keys.cg = { m_editing.goto_line } -- Tools keys['f2'] = { t.command_entry.focus } diff --git a/core/ext/menu.lua b/core/ext/menu.lua index 27788ec1..eafcefbe 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -74,6 +74,9 @@ local ID = { FIND_AND_REPLACE = 304, REPLACE = 305, REPLACE_ALL = 306, + FIND_IN_FILES = 308, + GOTO_NEXT_FILE_FOUND = 309, + GOTO_PREV_FILE_FOUND = 310, GOTO_LINE = 307, -- Tools FOCUS_COMMAND_ENTRY = 401, @@ -202,6 +205,10 @@ local menubar = { { l.MENU_SEARCH_REPLACE, ID.REPLACE }, { l.MENU_SEARCH_REPLACE_ALL, ID.REPLACE_ALL }, { 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 }, + { l.MENU_SEARCH_GOTO_PREV_FILE_FOUND, ID.GOTO_PREV_FILE_FOUND }, + { SEPARATOR, ID.SEPARATOR }, { l.MENU_SEARCH_GOTO_LINE, ID.GOTO_LINE }, }, gtkmenu { @@ -374,6 +381,14 @@ 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_IN_FILES] = { + function() + t.find.in_files = true + t.find.focus() + end + }, + [ID.GOTO_NEXT_FILE_FOUND] = { t.find.goto_file_in_list, true }, + [ID.GOTO_PREV_FILE_FOUND] = { t.find.goto_file_in_list, false }, [ID.GOTO_LINE] = { m_editing.goto_line }, -- Tools [ID.FOCUS_COMMAND_ENTRY] = { t.command_entry.focus }, |