Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lua/java/ui/profile.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local event = require('nui.utils.autocmd').event
local Layout = require('nui.layout')
local Menu = require('nui.menu')
local Popup = require('nui.popup')
Expand Down Expand Up @@ -144,9 +145,6 @@ function ProfileUI:get_menu()
close = { '<Esc>', '<C-c>' },
submit = { '<CR>', '<Space>' },
},
on_change = function(item)
self.focus_item = item
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On change callback is not being called on cursor change so the focus_item is the top most node when the window is opened. As a result deletion fails because focus_item is always the active item

end,
on_submit = function(item)
if item.text == new_profile then
self:_open_profile_editor()
Expand Down Expand Up @@ -327,6 +325,10 @@ end
function ProfileUI:openMenu()
self.menu = self:get_menu()

self.menu:on(event.CursorMoved, function()
self.focus_item = self.menu.tree:get_node()
end)

self.menu:mount()
-- quit
self.menu:map('n', 'q', function()
Expand All @@ -352,6 +354,7 @@ local get_error_handler = require('java.handlers.error')

--- @type ProfileUI
M.ProfileUI = ProfileUI

function M.ui()
return async(function()
local dap_config = DapSetup(jdtls().client):get_dap_config()
Expand Down
2 changes: 1 addition & 1 deletion tests/java/ui/profile_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('java.ui.profile', function()
self.table1 = table1
self.table2 = table2
end
function MockMenu.on() end
function MockMenu.unmount() end
function MockMenu.map() end
function MockMenu.mount() end
Expand Down Expand Up @@ -96,7 +97,6 @@ describe('java.ui.profile', function()
menu.table1.border.text.bottom,
'[a]ctivate [d]elete [b]ack [q]uit'
)
assert(menu.table2.on_change ~= nil)
assert(menu.table2.on_submit ~= nil)
end)

Expand Down