@@ -807,26 +807,73 @@ function A.set_keymaps(buf, win, line_map, reopen)
807807 vim .keymap .set (' n' , k , wipe , { buffer = buf , silent = true })
808808 end
809809
810- -- open file
811- vim .keymap .set (' n' , ' <CR>' , function ()
810+ -- edit file in floating window (configurable keymap, default Enter)
811+ if cfg .keymaps .edit and cfg .keymaps .edit ~= ' ' then
812+ vim .keymap .set (' n' , cfg .keymaps .edit , function ()
813+ with_headline (line_map , function (cur , hl )
814+ local agendabuf = vim .api .nvim_get_current_buf ()
815+ vim .cmd (' edit ' .. vim .fn .fnameescape (hl .file .filename ))
816+ vim .api .nvim_win_set_cursor (0 , { hl .position .start_line , 0 })
817+ local filebuf = vim .api .nvim_get_current_buf ()
818+ pcall (vim .api .nvim_buf_delete , agendabuf , { force = true })
819+
820+ -- Add q/Esc keymaps to file buffer for consistent close behavior
821+ local function close_file ()
822+ if vim .api .nvim_buf_is_valid (filebuf ) then
823+ pcall (vim .api .nvim_buf_delete , filebuf , { force = false })
824+ end
825+ end
826+ for _ , k in ipairs ({ ' q' , ' <Esc>' }) do
827+ vim .keymap .set (' n' , k , close_file , { buffer = filebuf , silent = true })
828+ end
829+
830+ vim .api .nvim_create_autocmd (' BufWinLeave' , {
831+ buffer = filebuf ,
832+ once = true ,
833+ callback = function ()
834+ vim .schedule (function ()
835+ pcall (vim .api .nvim_buf_delete , filebuf , { force = true })
836+ reopen (cur )
837+ end )
838+ end ,
839+ })
840+ end )
841+ end , { buffer = buf , silent = true })
842+ end
843+
844+ -- goto: close float and open file in previous window
845+ local function goto_headline ()
846+ local popup = cfg .popup_mode
847+ if popup and popup .enabled then
848+ vim .notify (' goto not available in popup mode' , vim .log .levels .WARN )
849+ return
850+ end
851+
812852 with_headline (line_map , function (cur , hl )
813- local agendabuf = vim .api .nvim_get_current_buf ()
853+ local ViewPort = require (' org-super-agenda.adapters.neovim.view_float' )
854+ local prev_win = ViewPort .prev_win ()
855+
856+ -- Close the floating window
857+ if vim .api .nvim_win_is_valid (win ) then
858+ pcall (vim .api .nvim_win_close , win , true )
859+ end
860+ if vim .api .nvim_buf_is_valid (buf ) then
861+ pcall (vim .api .nvim_buf_delete , buf , { force = true })
862+ end
863+ require (' org-super-agenda' ).on_close ()
864+
865+ -- Switch to previous window and open file
866+ if prev_win and vim .api .nvim_win_is_valid (prev_win ) then
867+ vim .api .nvim_set_current_win (prev_win )
868+ end
814869 vim .cmd (' edit ' .. vim .fn .fnameescape (hl .file .filename ))
815870 vim .api .nvim_win_set_cursor (0 , { hl .position .start_line , 0 })
816- local filebuf = vim .api .nvim_get_current_buf ()
817- pcall (vim .api .nvim_buf_delete , agendabuf , { force = true })
818- vim .api .nvim_create_autocmd (' BufWinLeave' , {
819- buffer = filebuf ,
820- once = true ,
821- callback = function ()
822- vim .schedule (function ()
823- pcall (vim .api .nvim_buf_delete , filebuf , { force = true })
824- reopen (cur )
825- end )
826- end ,
827- })
828871 end )
829- end , { buffer = buf , silent = true })
872+ end
873+
874+ if cfg .keymaps [' goto' ] and cfg .keymaps [' goto' ] ~= ' ' then
875+ vim .keymap .set (' n' , cfg .keymaps [' goto' ], goto_headline , { buffer = buf , silent = true })
876+ end
830877
831878 -- reschedule / deadline (unchanged but undo-aware)
832879 vim .keymap .set (' n' , cfg .keymaps .reschedule , function ()
@@ -1097,12 +1144,21 @@ function A.set_keymaps(buf, win, line_map, reopen)
10971144 end , { buffer = buf , silent = true })
10981145 end
10991146
1100- -- <Tab>: toggle group fold on group header, otherwise preview item
1101- vim .keymap .set (' n' , ' <Tab>' , function ()
1102- if not toggle_group_on_cursor (line_map ) then
1147+ -- fold + fallback: toggle group fold on group header, otherwise run fold_item_action
1148+ local fold_actions = {
1149+ [' goto' ] = goto_headline ,
1150+ preview = function ()
11031151 preview_headline (line_map )
1104- end
1105- end , { buffer = buf , silent = true })
1152+ end ,
1153+ }
1154+ if cfg .keymaps .fold_or_action and cfg .keymaps .fold_or_action ~= ' ' then
1155+ vim .keymap .set (' n' , cfg .keymaps .fold_or_action , function ()
1156+ if not toggle_group_on_cursor (line_map ) then
1157+ local action = fold_actions [cfg .fold_item_action ] or fold_actions [' preview' ]
1158+ action ()
1159+ end
1160+ end , { buffer = buf , silent = true })
1161+ end
11061162
11071163 if cfg .keymaps .fold_all and cfg .keymaps .fold_all ~= ' ' then
11081164 vim .keymap .set (' n' , cfg .keymaps .fold_all , function ()
0 commit comments