diff options
-rw-r--r-- | docs/api.md | 2 | ||||
-rw-r--r-- | modules/lua/ta_api | 2 | ||||
-rw-r--r-- | modules/textadept/find.lua | 9 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 12 | ||||
-rw-r--r-- | test/test.lua | 17 |
5 files changed, 27 insertions, 15 deletions
diff --git a/docs/api.md b/docs/api.md index 63c4f4bb..d4f9f75b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -8977,7 +8977,7 @@ Displays and focuses the Find & Replace Pane. Parameters: -* *`options`*: Optional table of options to initially set. +* *`options`*: Optional table of `ui.find` field options to initially set. <a id="ui.find.goto_file_found"></a> #### `ui.find.goto_file_found`(*line\_num, next*) diff --git a/modules/lua/ta_api b/modules/lua/ta_api index 0c1a0918..31721d33 100644 --- a/modules/lua/ta_api +++ b/modules/lua/ta_api @@ -523,7 +523,7 @@ find_prev_button_text ui.find.find_prev_button_text (string, Write-only)\nThe te first_visible_line view.first_visible_line (number)\nThe line number of the line at the top of the view. float lexer.float (pattern)\nA pattern that matches a floating point number. focus ui.command_entry.focus()\nOpens the command entry. -focus ui.find.focus(options)\nDisplays and focuses the Find & Replace Pane.\n@param options Optional table of options to initially set. +focus ui.find.focus(options)\nDisplays and focuses the Find & Replace Pane.\n@param options Optional table of `ui.find` field options to initially set. fold lexer.fold(lexer, text, start_pos, start_line, start_level)\nDetermines fold points in a chunk of text *text* using lexer *lexer*,\nreturning a table of fold levels associated with line numbers.\n*text* starts at position *start_pos* on line number *start_line* with a\nbeginning fold level of *start_level* in the buffer.\n@param lexer The lexer to fold text with.\n@param text The text in the buffer to fold.\n@param start_pos The position in the buffer *text* starts at, counting from\n 1.\n@param start_line The line number *text* starts on, counting from 1.\n@param start_level The fold level *text* starts on.\n@return table of fold levels associated with line numbers. fold_all view.fold_all(view, action)\nContracts, expands, or toggles all fold points, depending on *action*.\nWhen toggling, the state of the first fold point determines whether to\nexpand or contract.\n@param view A view.\n@param action The fold action to perform. Valid values are:\n * `view.FOLDACTION_CONTRACT`\n * `view.FOLDACTION_EXPAND`\n * `view.FOLDACTION_TOGGLE` fold_by_indentation lexer.fold_by_indentation (boolean)\nWhether or not to fold based on indentation level if a lexer does not have\na folder.\nSome lexers automatically enable this option. It is disabled by default.\nThis is an alias for `lexer.property['fold.by.indentation'] = '1|0'`. diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 5450a02a..0e84d48f 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -127,13 +127,14 @@ end local orig_focus = M.focus --- -- Displays and focuses the Find & Replace Pane. --- @param options Optional table of options to initially set. +-- @param options Optional table of `ui.find` field options to initially set. -- @name focus function M.focus(options) local already_in_files = M.in_files - if assert_type(options, 'table/nil', 1) then - for k, v in pairs(options) do M[k] = v end - end + if not assert_type(options, 'table/nil', 1) then options = {} end + if not options.in_files then options.in_files = false end -- reset + if not options.incremental then options.incremental = false end -- reset + for k, v in pairs(options) do M[k] = v end M.replace_label_text = not M.in_files and _L['Replace:'] or _L['Filter:'] if M.in_files then if not already_in_files then repl_text = M.replace_entry_text end -- save diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 2dee4f60..1ae2d909 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -147,20 +147,14 @@ local default_menubar = { }, { title = _L['Search'], - {_L['Find'], function() - ui.find.focus{in_files = false, incremental = false} - end}, + {_L['Find'], ui.find.focus}, {_L['Find Next'], ui.find.find_next}, {_L['Find Previous'], ui.find.find_prev}, {_L['Replace'], ui.find.replace}, {_L['Replace All'], ui.find.replace_all}, - {_L['Find Incremental'], function() - ui.find.focus{in_files = false, incremental = true} - end}, + {_L['Find Incremental'], function() ui.find.focus{incremental = true} end}, SEPARATOR, - {_L['Find in Files'], function() - ui.find.focus{in_files = true, incremental = false} - end}, + {_L['Find in Files'], function() ui.find.focus{in_files = true} end}, {_L['Goto Next File Found'], function() ui.find.goto_file_found(true) end}, {_L['Goto Previous File Found'], function() ui.find.goto_file_found(false) diff --git a/test/test.lua b/test/test.lua index 37f525b2..25aff22a 100644 --- a/test/test.lua +++ b/test/test.lua @@ -2656,6 +2656,23 @@ function test_find_replace_regex_transforms() buffer:close(true) end +function test_ui_find_focus() + buffer:new() + buffer:append_text(' foo\n\n foo') + ui.find.focus{incremental = true} + ui.find.find_entry_text = 'foo' + if CURSES then events.emit(events.FIND_TEXT_CHANGED) end -- simulate + assert_equal(buffer:line_from_position(buffer.current_pos), 1) + buffer:line_down() + ui.find.focus() -- should turn off incremental find + ui.find.find_entry_text = 'f' + if CURSES then events.emit(events.FIND_TEXT_CHANGED) end -- simulate + assert_equal(buffer:line_from_position(buffer.current_pos), 2) + buffer:close(true) + + assert_raises(function() ui.find.focus(1) end, 'table/nil expected, got number') +end + function test_history() local filename1 = _HOME .. '/test/modules/textadept/history/1' io.open_file(filename1) |