aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ui
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2024-01-19 14:51:10 -0600
committerGitHub <noreply@github.com>2024-01-19 14:51:10 -0600
commitd3a8e9217f39c59dd7762bd22a76b8bd03ca85ff (patch)
tree176bbcf0793bab5338614f717f003c385f9c3878 /test/functional/ui
parent5a8fe0769cc9c5d8323b073d5c45ee37ce91c049 (diff)
downloadrneovim-d3a8e9217f39c59dd7762bd22a76b8bd03ca85ff.tar.gz
rneovim-d3a8e9217f39c59dd7762bd22a76b8bd03ca85ff.tar.bz2
rneovim-d3a8e9217f39c59dd7762bd22a76b8bd03ca85ff.zip
feat(ui): add chdir UI event (#27093)
When an embedded Nvim instance changes its current directory a "chdir" UI event is emitted. Attached UIs can use this information however they wish. In the TUI it is used to synchronize the cwd of the TUI process with the cwd of the embedded Nvim process.
Diffstat (limited to 'test/functional/ui')
-rw-r--r--test/functional/ui/embed_spec.lua50
-rw-r--r--test/functional/ui/screen.lua6
2 files changed, 55 insertions, 1 deletions
diff --git a/test/functional/ui/embed_spec.lua b/test/functional/ui/embed_spec.lua
index e655ee1b54..f6bdd2215d 100644
--- a/test/functional/ui/embed_spec.lua
+++ b/test/functional/ui/embed_spec.lua
@@ -171,6 +171,56 @@ describe('--embed UI', function()
}
eq({ [16711935] = true }, seen) -- we only saw the last one, despite 16777215 was set internally earlier
end)
+
+ it('updates cwd of attached UI #21771', function()
+ clear { args_rm = { '--headless' } }
+
+ local screen = Screen.new(40, 8)
+ screen:attach()
+
+ screen:expect {
+ condition = function()
+ eq(helpers.paths.test_source_path, screen.pwd)
+ end,
+ }
+
+ -- Change global cwd
+ helpers.command(string.format('cd %s/src/nvim', helpers.paths.test_source_path))
+
+ screen:expect {
+ condition = function()
+ eq(string.format('%s/src/nvim', helpers.paths.test_source_path), screen.pwd)
+ end,
+ }
+
+ -- Split the window and change the cwd in the split
+ helpers.command('new')
+ helpers.command(string.format('lcd %s/test', helpers.paths.test_source_path))
+
+ screen:expect {
+ condition = function()
+ eq(string.format('%s/test', helpers.paths.test_source_path), screen.pwd)
+ end,
+ }
+
+ -- Move to the original window
+ helpers.command('wincmd p')
+
+ screen:expect {
+ condition = function()
+ eq(string.format('%s/src/nvim', helpers.paths.test_source_path), screen.pwd)
+ end,
+ }
+
+ -- Change global cwd again
+ helpers.command(string.format('cd %s', helpers.paths.test_source_path))
+
+ screen:expect {
+ condition = function()
+ eq(helpers.paths.test_source_path, screen.pwd)
+ end,
+ }
+ end)
end)
describe('--embed --listen UI', function()
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 644ee910b6..07333f2e21 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -140,6 +140,7 @@ function Screen.new(width, height)
suspended = false,
mode = 'normal',
options = {},
+ pwd = '',
popupmenu = nil,
cmdline = {},
cmdline_block = {},
@@ -212,7 +213,6 @@ function Screen:attach(options, session)
if options.ext_linegrid == nil then
options.ext_linegrid = true
end
-
self._session = session
self._options = options
self._clear_attrs = (not options.ext_linegrid) and {} or nil
@@ -1108,6 +1108,10 @@ function Screen:_handle_option_set(name, value)
self.options[name] = value
end
+function Screen:_handle_chdir(path)
+ self.pwd = vim.fs.normalize(path, { expand_env = false })
+end
+
function Screen:_handle_popupmenu_show(items, selected, row, col, grid)
self.popupmenu = { items = items, pos = selected, anchor = { grid, row, col } }
end