Skip to content

Commit 200127b

Browse files
committed
fix(term): follow winnr if "console" is enabled
Also adds some minor tweaks
1 parent a9e4701 commit 200127b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lua/dap-view/term/scroll.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local setup = require("dap-view.setup")
12
local util = require("dap-view.util")
23
local state = require("dap-view.state")
34

@@ -22,17 +23,21 @@ M.scroll = function(bufnr)
2223
end,
2324
})
2425

26+
local winnr = vim.tbl_contains(setup.config.winbar.sections, "console") and state.winnr or state.term_winnr
27+
2528
api.nvim_buf_attach(bufnr, false, {
2629
on_lines = function()
27-
if not util.is_win_valid(state.term_winnr) then
30+
if not util.is_win_valid(winnr) then
2831
return
2932
end
33+
---@cast winnr integer
3034
if autoscroll and vim.fn.mode() == "n" then
31-
api.nvim_win_call(state.term_winnr, function()
35+
api.nvim_win_call(winnr, function()
3236
if api.nvim_get_current_buf() == bufnr then
33-
-- vim.schedule ensures the cursor movement happens in the main event loop.
37+
-- vim.schedule ensures the cursor movement happens in the main event loop
38+
-- otherwise the call may happen too early
3439
vim.schedule(function()
35-
api.nvim_win_set_cursor(state.term_winnr, { api.nvim_buf_line_count(bufnr), 0 })
40+
api.nvim_win_set_cursor(winnr, { api.nvim_buf_line_count(bufnr), 0 })
3641
end)
3742
end
3843
end)

lua/dap-view/threads/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local api = vim.api
88
M.track_cursor_position = function(current_frame_id)
99
for k, v in pairs(state.frames_by_line) do
1010
if v.id == current_frame_id then
11-
api.nvim_win_set_cursor(state.winnr, { k, 1 })
11+
api.nvim_win_set_cursor(state.winnr, { k, 0 })
1212
end
1313
end
1414
end

lua/dap-view/views/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ M.switch_to_view = function(view)
5454
local buf_len = api.nvim_buf_line_count(state.bufnr)
5555
state.cur_pos[view] = math.min(cursor_line, buf_len)
5656

57-
api.nvim_win_set_cursor(state.winnr, { state.cur_pos[view], 1 })
57+
api.nvim_win_set_cursor(state.winnr, { state.cur_pos[view], 0 })
5858
end
5959

6060
return M

0 commit comments

Comments
 (0)