From e9deaad1b973fd6d0702f318f802797dee28c82a Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 17 Aug 2025 16:28:06 +0530 Subject: Allow searching on input for --- TODO.org | 53 +++------------------------------------ lua/null-browser/defaults/vi.lua | 10 +++++--- lua/null-browser/extras/dmenu.lua | 15 ++++++----- lua/null-browser/utils.lua | 2 +- 4 files changed, 20 insertions(+), 60 deletions(-) diff --git a/TODO.org b/TODO.org index 1766d6e..d198260 100644 --- a/TODO.org +++ b/TODO.org @@ -17,14 +17,15 @@ - [X] Embed docs in app (`null:/docs`) - [X] web.decorations.*.set_size() - [X] Vertical tabline ui +- [X] vendor web.inspect with build - [X] Install docs/ and assets/ in build - [X] Make the asset/config/lua paths readable via lua - [X] json encode/decode - [X] Fix path to symbols.json in web.help.get_items (use docs path) - [X] Document events and event opts +- [X] Set search text as the user is typing (dmenu -r) +- [X] Update all api to use opts table options/filters pattern - [ ] Element focus (input focus) -- [X] Update all api to use opts table pattern -- [ ] Update internal apis to use table - [ ] Add win options for web.view.list / web.view.current / web.view.current_index /etc - [ ] web.keymap.configure_mode(modename, { passthrough = false }) - [ ] Fullscreen @@ -59,7 +60,6 @@ - [ ] Create window with new profile - [ ] Configuration validation - [ ] Allow toggling devtools -- [X] Set search text as the user is typing (dmenu -r) - [ ] Conflict in keymap (keymap already exists) - [ ] Allow pattern filtering for event listeners - [ ] Allow view_id, win_id filtering for event listeners @@ -70,7 +70,6 @@ - [ ] Bookmarking - [ ] Support multiple modes for keymap.set: `web.keymap.set({'n','i'}, ...)` - [ ] static linking for qt -- [X] vendor web.inspect with build - [ ] Right click context menu items - [ ] Listen to renderprocesstermination signal - [ ] Change instance manager command format @@ -88,49 +87,3 @@ - Win = 0: Current window - Win = nil, none: All windows or current window based on operation - Keep track of last focused window (current window is last focused) -#+begin_src lua -web.view.set_url(url) -- Set url for current view -web.view.set_url(url, { view = 1 }) -- Set url for view 1 -web.view.set_url(url, { view = 1, win = 1 }) -- Set url for view 1 in win 1 -web.view.set_url(url, { win = 1 }) -- Set url for current view in win 1 - -web.view.create(url, { win = 1 }) -- New view in win 1 -web.view.create(url) -- New view in current window - -web.view.close({ view = 1 }) -- Close view 1 -web.view.close() -- Close current view in current window - -web.view.list({ win = nil }) -- List all tabs -web.view.list({ win = 1 }) -- List win 1 tabs - -web.view.select({ view = 1, win = 1 }) -- Select win 1 view -web.view.select({ view = 1, win = 0 }) -- Select view 1 in current window -web.view.select({ view = 1 }) -- Select view 1 - -web.view.current({ win = 1 }) -- Current view in win 1 -web.view.current() -- Current view in current win - -web.history.back(1) -- Back for current view in current window -web.history.back(1, { view = 1 }) -- Back for view 1 -web.history.back(1, { win = 1 }) -- Back for current view in win 1 - -web.keymap.set('n', '', ..., { view = 1 }) -- Set keymap for view 1 -web.keymap.set('n', '', ..., { win = 1 }) -- Set keymap for win 1 -web.opt.new_tab_url = 'https://duckduckgo.com' - --- Search api -web.search.set_search_text('whatever') -web.search.next() -web.search.prev() -web.search.get_search_text() -web.search.current() -web.search.total() - -web.decorations.top.enable() -web.decorations.top.disable() -web.decorations.top.set_size(20) -local view_id = web.decorations.top.view() -web.view.set_html('
Hello world
', { view = view }) --- Hide/unhide -web.decorations.top.set_visible(false) -#+end_src diff --git a/lua/null-browser/defaults/vi.lua b/lua/null-browser/defaults/vi.lua index c3775bb..22f3bba 100644 --- a/lua/null-browser/defaults/vi.lua +++ b/lua/null-browser/defaults/vi.lua @@ -60,9 +60,13 @@ function M.initialize() -- Search web.keymap.set('n', '', function() - config.menu:input({ prompt = 'Search:', query = web.search.get_text() }, function(err, input) - if err then return end - web.search.set_text(input) + local view = web.view.current() + config.menu:input({ prompt = 'Search:', call_on_input = true, query = web.search.get_text() }, function(err, input) + if err then + web.search.set_text('', { view = view }) + else + web.search.set_text(input, { view = view }) + end end) end) web.keymap.set('n', '', function() web.search.reset() end) diff --git a/lua/null-browser/extras/dmenu.lua b/lua/null-browser/extras/dmenu.lua index 5d660bb..360a78e 100644 --- a/lua/null-browser/extras/dmenu.lua +++ b/lua/null-browser/extras/dmenu.lua @@ -11,6 +11,7 @@ function Dmenu:new(opts) prompt = nil, query = nil, select_last_line = true, + call_on_input = false, transform_output = nil, } local obj = {} @@ -39,12 +40,10 @@ function Dmenu:prepare_options(opts) table.insert(args, options.query) end - return { - command = options.command, + return web.utils.table_merge({}, options, { args = args, - select_last_line = options.select_last_line, transform_output = options.transform_output or function(s) return s end, - } + }) end function Dmenu:select(list, opts, callback) @@ -63,14 +62,18 @@ function Dmenu:select(list, opts, callback) local result = options.transform_output(selection) if code == 0 then - callback(nil, result) + callback(nil, result, true) else - callback('[dmenu] Exit with status code: ' .. code, result) + callback('[dmenu] Exit with status code: ' .. code, result, true) end end) web.uv.read_start(stdout, function(_, data) if data then + if options.call_on_input then + callback(nil, data, false) + end + if options.select_last_line then selection = data else diff --git a/lua/null-browser/utils.lua b/lua/null-browser/utils.lua index 4b1790a..30f67ee 100644 --- a/lua/null-browser/utils.lua +++ b/lua/null-browser/utils.lua @@ -58,7 +58,7 @@ function web.utils.string_trim(str) return res end ---- Merge multiple tables +--- Merge multiple tables into the first table --- @param tbl table --- @return table function web.utils.table_merge(tbl, ...) -- cgit v1.3.1