aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Steinberg <dstein64@users.noreply.github.com>2022-05-22 12:03:56 -0400
committerGitHub <noreply@github.com>2022-05-22 09:03:56 -0700
commit3fe6bf3a1e50299dbdd6314afbb18e468eb7ce08 (patch)
treea815a4105c547262faa2218e89bf410478c4ec34
parentb863c150c91a3621cdeb2efae54a4f0fe3328c09 (diff)
downloadrneovim-3fe6bf3a1e50299dbdd6314afbb18e468eb7ce08.tar.gz
rneovim-3fe6bf3a1e50299dbdd6314afbb18e468eb7ce08.tar.bz2
rneovim-3fe6bf3a1e50299dbdd6314afbb18e468eb7ce08.zip
fix(mksession): don't store floats in session #18635
Problem: If there are floating windows when `:mksession` runs, the session cannot be properly restored. Solution: Change `:mksession` to skip floating windows. This matches Vim's treatment of popup windows. An alternative approach could have `:mksession` save floating windows that can be _properly_ restored (rather than skip them entirely, which is what this PR does). While that would seemingly be a more complete fix, that could present additional issues since floating windows are ordinarily created by plugins, and they may no longer be properly under a plugin's control when restored. closes #18432
-rw-r--r--src/nvim/ex_session.c4
-rw-r--r--test/functional/ex_cmds/mksession_spec.lua34
2 files changed, 38 insertions, 0 deletions
diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c
index dfdb8c1eac..3b6f7b90bf 100644
--- a/src/nvim/ex_session.c
+++ b/src/nvim/ex_session.c
@@ -181,6 +181,10 @@ static bool ses_do_frame(const frame_T *fr)
/// @return non-zero if window "wp" is to be stored in the Session.
static int ses_do_win(win_T *wp)
{
+ // Skip floating windows to avoid issues when restoring the Session. #18432
+ if (wp->w_floating) {
+ return false;
+ }
if (wp->w_buffer->b_fname == NULL
// When 'buftype' is "nofile" can't restore the window contents.
|| (!wp->w_buffer->terminal && bt_nofile(wp->w_buffer))) {
diff --git a/test/functional/ex_cmds/mksession_spec.lua b/test/functional/ex_cmds/mksession_spec.lua
index c1b4777d16..8323d40e10 100644
--- a/test/functional/ex_cmds/mksession_spec.lua
+++ b/test/functional/ex_cmds/mksession_spec.lua
@@ -13,6 +13,7 @@ local matches = helpers.matches
local pesc = helpers.pesc
local rmdir = helpers.rmdir
local sleep = helpers.sleep
+local meths = helpers.meths
local file_prefix = 'Xtest-functional-ex_cmds-mksession_spec'
@@ -166,4 +167,37 @@ describe(':mksession', function()
-- Verify that the terminal's working directory is "/".
screen:expect(expected_screen)
end)
+
+ it('restores a session when there is a float #18432', function()
+ local tmpfile = file_prefix .. '-tmpfile-float'
+
+ command('edit ' .. tmpfile)
+ local buf = meths.create_buf(false, true)
+ local config = {
+ relative = 'editor',
+ focusable = false,
+ width = 10,
+ height = 3,
+ row = 0,
+ col = 1,
+ style = 'minimal'
+ }
+ meths.open_win(buf, false, config)
+ local cmdheight = meths.get_option('cmdheight')
+ command('mksession ' .. session_file)
+
+ -- Create a new test instance of Nvim.
+ clear()
+
+ command('source ' .. session_file)
+
+ eq(tmpfile, funcs.expand('%'))
+ -- Check that there is only a single window, which indicates the floating
+ -- window was not restored.
+ eq(1, funcs.winnr('$'))
+ -- The command-line height should remain the same as it was.
+ eq(cmdheight, meths.get_option('cmdheight'))
+
+ os.remove(tmpfile)
+ end)
end)