Skip to content

Commit 9ad676c

Browse files
committed
feat(log): add focus option for log window
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.
1 parent f06ac07 commit 9ad676c

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ require("flutter-tools").setup {
253253
-- takes a log_line as string argument; returns a boolean or nil;
254254
-- the log_line is only added to the output if the function returns true
255255
notify_errors = false, -- if there is an error whilst running then notify the user
256-
open_cmd = "tabedit", -- command to use to open the log buffer
256+
open_cmd = "botright 30vnew", -- command to use to open the log buffer
257+
focus_on_open = true, -- focus on the newly opened log window
257258
},
258259
dev_tools = {
259260
autostart = false, -- autostart devtools server if not detected

doc/flutter-tools.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,8 @@ both are set.
289289
-- takes a log_line as string argument; returns a boolean or nil;
290290
-- the log_line is only added to the output if the function returns true
291291
notify_errors = false, -- if there is an error whilst running then notify the user
292-
open_cmd = "tabedit", -- command to use to open the log buffer
292+
open_cmd = "botright 30vnew", -- command to use to open the log buffer
293+
focus_on_open = true, -- focus on the newly opened log window
293294
},
294295
dev_tools = {
295296
autostart = false, -- autostart devtools server if not detected

lua/flutter-tools/config.lua

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ local config = {
113113
filter = nil,
114114
enabled = true,
115115
notify_errors = false,
116+
focus_on_open = true,
116117
}, {
117118
__index = function(_, k) return k == "open_cmd" and get_split_cmd(0.4, 50) or nil end,
118119
}),

lua/flutter-tools/log.lua

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ local function create(config)
3232
filename = M.filename,
3333
filetype = "log",
3434
open_cmd = config.open_cmd,
35+
focus_on_open = config.focus_on_open,
3536
}
3637
ui.open_win(opts, function(buf, win)
3738
if not buf then

lua/flutter-tools/ui.lua

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ function M.open_win(opts, on_open)
144144
vim.bo[buf].swapfile = false
145145
vim.bo[buf].buftype = "nofile"
146146
if on_open then on_open(buf, win) end
147+
if not opts.focus_on_open then
148+
-- Switch back to the previous window
149+
vim.cmd("wincmd p")
150+
end
147151
end
148152

149153
return M

0 commit comments

Comments
 (0)