Skip to content

Commit

Permalink
feat(log): add focus option for log window
Browse files Browse the repository at this point in the history
Added a new configuration option `focus_on_open` to control whether the
log window should be focused when opened. Updated the default
`open_cmd` to `botright 30vnew` because this is default option.
Modified the `open_win` function to switch back to the previous window
if `focus_on_open` is set to false.
  • Loading branch information
sidlatau committed Nov 22, 2024
1 parent f06ac07 commit 9ad676c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ require("flutter-tools").setup {
-- takes a log_line as string argument; returns a boolean or nil;
-- the log_line is only added to the output if the function returns true
notify_errors = false, -- if there is an error whilst running then notify the user
open_cmd = "tabedit", -- command to use to open the log buffer
open_cmd = "botright 30vnew", -- command to use to open the log buffer
focus_on_open = true, -- focus on the newly opened log window
},
dev_tools = {
autostart = false, -- autostart devtools server if not detected
Expand Down
3 changes: 2 additions & 1 deletion doc/flutter-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ both are set.
-- takes a log_line as string argument; returns a boolean or nil;
-- the log_line is only added to the output if the function returns true
notify_errors = false, -- if there is an error whilst running then notify the user
open_cmd = "tabedit", -- command to use to open the log buffer
open_cmd = "botright 30vnew", -- command to use to open the log buffer
focus_on_open = true, -- focus on the newly opened log window
},
dev_tools = {
autostart = false, -- autostart devtools server if not detected
Expand Down
1 change: 1 addition & 0 deletions lua/flutter-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ local config = {
filter = nil,
enabled = true,
notify_errors = false,
focus_on_open = true,
}, {
__index = function(_, k) return k == "open_cmd" and get_split_cmd(0.4, 50) or nil end,
}),
Expand Down
1 change: 1 addition & 0 deletions lua/flutter-tools/log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local function create(config)
filename = M.filename,
filetype = "log",
open_cmd = config.open_cmd,
focus_on_open = config.focus_on_open,
}
ui.open_win(opts, function(buf, win)
if not buf then
Expand Down
4 changes: 4 additions & 0 deletions lua/flutter-tools/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ function M.open_win(opts, on_open)
vim.bo[buf].swapfile = false
vim.bo[buf].buftype = "nofile"
if on_open then on_open(buf, win) end
if not opts.focus_on_open then
-- Switch back to the previous window
vim.cmd("wincmd p")
end
end

return M

0 comments on commit 9ad676c

Please sign in to comment.