diff --git a/integration-tests/client/testEnvironmentTypes.ts b/integration-tests/client/testEnvironmentTypes.ts index 5a730e6..fa276a2 100644 --- a/integration-tests/client/testEnvironmentTypes.ts +++ b/integration-tests/client/testEnvironmentTypes.ts @@ -65,7 +65,7 @@ export type TestDirectory = { contents: { ["initial-file.txt"]: FileEntry - ["test.lua"]: FileEntry + ["test-setup.lua"]: FileEntry ["file.txt"]: FileEntry ["modify_yazi_config_to_use_ya_as_event_reader.lua"]: FileEntry ["subdirectory/subdirectory-file.txt"]: FileEntry diff --git a/integration-tests/cypress.config.ts b/integration-tests/cypress.config.ts index 654b5c9..045c5d7 100644 --- a/integration-tests/cypress.config.ts +++ b/integration-tests/cypress.config.ts @@ -78,9 +78,9 @@ export default defineConfig({ stem: "initial-file", extension: ".txt", }, - "test.lua": { - name: "test.lua", - stem: "test", + "test-setup.lua": { + name: "test-setup.lua", + stem: "test-setup", extension: ".lua", }, "file.txt": { @@ -119,7 +119,9 @@ export default defineConfig({ execSync(`cp ./test-environment/initial-file.txt ${dir}/`) execSync(`cp ./test-environment/file.txt ${dir}/`) - execSync(`cp ./test-environment/test-setup.lua ${dir}/test.lua`) + execSync( + `cp ./test-environment/test-setup.lua ${dir}/test-setup.lua`, + ) execSync(`cp -r ./test-environment/subdirectory ${dir}/`) execSync(`cp -r ./test-environment/other-subdirectory ${dir}/`) execSync(`cp -r ./test-environment/config-modifications/ ${dir}/`) diff --git a/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-directories.cy.ts b/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-directories.cy.ts index 914fe1e..db457d9 100644 --- a/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-directories.cy.ts +++ b/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-directories.cy.ts @@ -7,8 +7,43 @@ describe("opening directories", () => { filename: ".", }).then((dir) => { // yazi should now be visible, showing the names of adjacent files - cy.contains(dir.contents["file.txt"].name) + cy.contains(dir.contents["test-setup.lua"].name) + }) + }) + + it("can open a directory with `:edit .`", () => { + cy.visit("http://localhost:5173") + cy.startNeovim().then((dir) => { + // yazi should now be visible, showing the names of adjacent files + cy.contains(dir.contents["initial-file.txt"].name) + + // open the current directory using a command + cy.typeIntoTerminal(":edit .{enter}") + + // yazi should now be visible, showing the names of adjacent files + cy.contains(dir.contents["test-setup.lua"].name) + }) + }) + + it("can open a directory when pressing enter on a directory in yazi", () => { + cy.visit("http://localhost:5173") + cy.startNeovim().then((dir) => { + // yazi should now be visible, showing the names of adjacent files cy.contains(dir.contents["initial-file.txt"].name) + + cy.typeIntoTerminal("{upArrow}") + cy.contains(dir.contents["test-setup.lua"].name) + + // select a directory + cy.typeIntoTerminal("/routes{enter}") + // the contents of the directory should now be visible + cy.contains("posts.$postId") + + // open the directory + cy.typeIntoTerminal("{enter}") + + // yazi should now be visible in the new directory + cy.contains(dir.contents["routes/posts.$postId/route.tsx"].name) }) }) }) diff --git a/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-files.cy.ts b/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-files.cy.ts index 99d790c..940fda8 100644 --- a/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-files.cy.ts +++ b/integration-tests/cypress/e2e/using-shell-redirection-to-read-events/opening-files.cy.ts @@ -10,7 +10,7 @@ describe("opening files", () => { cy.typeIntoTerminal("{upArrow}") // yazi should now be visible, showing the names of adjacent files - cy.contains(dir.contents["test.lua"].name) // an adjacent file + cy.contains(dir.contents["test-setup.lua"].name) // an adjacent file }) }) @@ -31,15 +31,15 @@ describe("opening files", () => { it("can open a file in a vertical split", () => { cy.startNeovim().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) - cy.typeIntoTerminal("/test.lua{enter}") + cy.contains(dir.contents["test-setup.lua"].name) + cy.typeIntoTerminal("/test-setup.lua{enter}") cy.typeIntoTerminal("{control+v}") // yazi should now be closed cy.contains("-- TERMINAL --").should("not.exist") // the file path must be visible at the bottom - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) cy.contains(dir.contents["initial-file.txt"].name) }) }) @@ -47,15 +47,15 @@ describe("opening files", () => { it("can open a file in a horizontal split", () => { cy.startNeovim().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) - cy.typeIntoTerminal("/test.lua{enter}") + cy.contains(dir.contents["test-setup.lua"].name) + cy.typeIntoTerminal("/test-setup.lua{enter}") cy.typeIntoTerminal("{control+x}") // yazi should now be closed cy.contains("-- TERMINAL --").should("not.exist") // the file path must be visible at the bottom - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) cy.contains(dir.contents["initial-file.txt"].name) }) }) @@ -63,8 +63,8 @@ describe("opening files", () => { it("can open a file in a new tab", () => { cy.startNeovim().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) - cy.typeIntoTerminal("/test.lua{enter}") + cy.contains(dir.contents["test-setup.lua"].name) + cy.typeIntoTerminal("/test-setup.lua{enter}") cy.typeIntoTerminal("{control+t}") // yazi should now be closed @@ -75,7 +75,7 @@ describe("opening files", () => { cy.contains("If you see this text, Neovim is ready!") - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) cy.contains(dir.contents["initial-file.txt"].name) }) }) @@ -85,7 +85,7 @@ describe("opening files", () => { cy.typeIntoTerminal("{upArrow}") // wait for yazi to open - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) // select the initial file, the cursor moves one line down to the next file cy.typeIntoTerminal(" ") @@ -104,7 +104,7 @@ describe("opening files", () => { it("can open files with complex characters in their name", () => { cy.startNeovim().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) // enter the routes/ directory cy.typeIntoTerminal("/routes{enter}") diff --git a/integration-tests/cypress/e2e/using-ya-to-read-events/hover-highlights.cy.ts b/integration-tests/cypress/e2e/using-ya-to-read-events/hover-highlights.cy.ts index af1fbcd..4d4e895 100644 --- a/integration-tests/cypress/e2e/using-ya-to-read-events/hover-highlights.cy.ts +++ b/integration-tests/cypress/e2e/using-ya-to-read-events/hover-highlights.cy.ts @@ -73,7 +73,7 @@ describe("highlighting the buffer with 'hover' events", () => { cy.typeIntoTerminal("{upArrow}") // yazi is shown and adjacent files should be visible now - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) hoverAnotherFileToEnsureHoverEventIsReceivedInCI( dir.contents["initial-file.txt"].name, @@ -85,7 +85,7 @@ describe("highlighting the buffer with 'hover' events", () => { isHovered("If you see this text, Neovim is ready!") // hover another file - the highlight should be removed - cy.typeIntoTerminal(`/^${dir.contents["test.lua"].name}{enter}`) + cy.typeIntoTerminal(`/^${dir.contents["test-setup.lua"].name}{enter}`) isNotHovered("If you see this text, Neovim is ready!") }) @@ -100,7 +100,7 @@ describe("highlighting the buffer with 'hover' events", () => { // wait until text on the start screen is visible isNotHovered("f you see this text, Neovim is ready!") - const testFile = dir.contents["test.lua"].name + const testFile = dir.contents["test-setup.lua"].name // open an adjacent file and wait for it to be displayed cy.typeIntoTerminal( `:vsplit ${dir.rootPathAbsolute}/${testFile}{enter}`, @@ -139,7 +139,7 @@ describe("highlighting the buffer with 'hover' events", () => { cy.typeIntoTerminal("{upArrow}") hoverAnotherFileToEnsureHoverEventIsReceivedInCI( - dir.contents["test.lua"].name, + dir.contents["test-setup.lua"].name, ) // yazi is shown and adjacent files should be visible now @@ -172,7 +172,7 @@ describe("highlighting the buffer with 'hover' events", () => { cy.typeIntoTerminal("{upArrow}") hoverAnotherFileToEnsureHoverEventIsReceivedInCI( - dir.contents["test.lua"].name, + dir.contents["test-setup.lua"].name, ) // yazi is shown and adjacent files should be visible now diff --git a/integration-tests/cypress/e2e/using-ya-to-read-events/mouse.cy.ts b/integration-tests/cypress/e2e/using-ya-to-read-events/mouse.cy.ts index de3f49c..0b14de5 100644 --- a/integration-tests/cypress/e2e/using-ya-to-read-events/mouse.cy.ts +++ b/integration-tests/cypress/e2e/using-ya-to-read-events/mouse.cy.ts @@ -14,15 +14,15 @@ describe("mouse support", () => { cy.typeIntoTerminal("{upArrow}") // yazi should be showing adjacent files - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) // click outside of the yazi floating window. This should close it // because it's designed to close when it loses focus - cy.contains("-- TERMINAL --").click() + cy.contains("If you see this text, Neovim is ready!").click() // clicking outside of the yazi window should close it, after which - // Neovim should not be showing the TERMINAL buffer any longer - cy.contains("-- TERMINAL --").should("not.exist") + // Neovim should not be showing adjacent files + cy.contains(dir.contents["test-setup.lua"].name).should("not.exist") }) }) }) diff --git a/integration-tests/cypress/e2e/using-ya-to-read-events/opening-directories.cy.ts b/integration-tests/cypress/e2e/using-ya-to-read-events/opening-directories.cy.ts index 47b887e..2bf4ee8 100644 --- a/integration-tests/cypress/e2e/using-ya-to-read-events/opening-directories.cy.ts +++ b/integration-tests/cypress/e2e/using-ya-to-read-events/opening-directories.cy.ts @@ -9,8 +9,45 @@ describe("opening directories", () => { filename: ".", }).then((dir) => { // yazi should now be visible, showing the names of adjacent files - cy.contains(dir.contents["file.txt"].name) + cy.contains(dir.contents["test-setup.lua"].name) + + cy.typeIntoTerminal("{downArrow}") + }) + }) + + it("can open a directory with `:edit .`", () => { + cy.visit("http://localhost:5173") + startNeovimWithYa().then((dir) => { + // yazi should now be visible, showing the names of adjacent files cy.contains(dir.contents["initial-file.txt"].name) + + // open the current directory using a command + cy.typeIntoTerminal(":edit .{enter}") + + // yazi should now be visible, showing the names of adjacent files + cy.contains(dir.contents["test-setup.lua"].name) + }) + }) + + it("can open a directory when pressing enter on a directory in yazi", () => { + cy.visit("http://localhost:5173") + startNeovimWithYa().then((dir) => { + // yazi should now be visible, showing the names of adjacent files + cy.contains(dir.contents["initial-file.txt"].name) + + cy.typeIntoTerminal("{upArrow}") + cy.contains(dir.contents["test-setup.lua"].name) + + // select a directory + cy.typeIntoTerminal("/routes{enter}") + // the contents of the directory should now be visible + cy.contains("posts.$postId") + + // open the directory + cy.typeIntoTerminal("{enter}") + + // yazi should now be visible in the new directory + cy.contains(dir.contents["routes/posts.$postId/route.tsx"].name) }) }) }) diff --git a/integration-tests/cypress/e2e/using-ya-to-read-events/opening-files.cy.ts b/integration-tests/cypress/e2e/using-ya-to-read-events/opening-files.cy.ts index 6d51f4a..43ca25a 100644 --- a/integration-tests/cypress/e2e/using-ya-to-read-events/opening-files.cy.ts +++ b/integration-tests/cypress/e2e/using-ya-to-read-events/opening-files.cy.ts @@ -12,7 +12,7 @@ describe("opening files", () => { cy.typeIntoTerminal("{upArrow}") // yazi should now be visible, showing the names of adjacent files - cy.contains(dir.contents["test.lua"].name) // an adjacent file + cy.contains(dir.contents["test-setup.lua"].name) // an adjacent file }) }) @@ -33,15 +33,15 @@ describe("opening files", () => { it("can open a file in a vertical split", () => { startNeovimWithYa().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) - cy.typeIntoTerminal("/test.lua{enter}") + cy.contains(dir.contents["test-setup.lua"].name) + cy.typeIntoTerminal("/test-setup.lua{enter}") cy.typeIntoTerminal("{control+v}") // yazi should now be closed cy.contains("-- TERMINAL --").should("not.exist") // the file path must be visible at the bottom - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) cy.contains(dir.contents["initial-file.txt"].name) }) }) @@ -49,15 +49,15 @@ describe("opening files", () => { it("can open a file in a horizontal split", () => { startNeovimWithYa().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) - cy.typeIntoTerminal("/test.lua{enter}") + cy.contains(dir.contents["test-setup.lua"].name) + cy.typeIntoTerminal("/test-setup.lua{enter}") cy.typeIntoTerminal("{control+x}") // yazi should now be closed cy.contains("-- TERMINAL --").should("not.exist") // the file path must be visible at the bottom - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) cy.contains(dir.contents["initial-file.txt"].name) }) }) @@ -65,8 +65,8 @@ describe("opening files", () => { it("can open a file in a new tab", () => { startNeovimWithYa().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) - cy.typeIntoTerminal("/test.lua{enter}") + cy.contains(dir.contents["test-setup.lua"].name) + cy.typeIntoTerminal("/test-setup.lua{enter}") cy.typeIntoTerminal("{control+t}") // yazi should now be closed @@ -77,7 +77,7 @@ describe("opening files", () => { cy.contains("If you see this text, Neovim is ready!") - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) cy.contains(dir.contents["initial-file.txt"].name) }) }) @@ -87,7 +87,7 @@ describe("opening files", () => { cy.typeIntoTerminal("{upArrow}") // wait for yazi to open - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) // select the initial file, the cursor moves one line down to the next file cy.typeIntoTerminal(" ") @@ -113,7 +113,7 @@ describe("opening files", () => { // file. // - Finally, yazi should rename the files to match the new names. cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) cy.typeIntoTerminal("{control+a}r") // yazi should now have opened an embedded Neovim. The file name should say @@ -135,7 +135,7 @@ describe("opening files", () => { it("can rename a buffer that's open in Neovim", () => { startNeovimWithYa().then((dir) => { cy.typeIntoTerminal("{upArrow}") - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) // select only the current file to make the test easier cy.typeIntoTerminal("v") cy.typeIntoTerminal("r") // start renaming diff --git a/integration-tests/cypress/e2e/using-ya-to-read-events/toggling.cy.ts b/integration-tests/cypress/e2e/using-ya-to-read-events/toggling.cy.ts index 4ac16cc..42fd16f 100644 --- a/integration-tests/cypress/e2e/using-ya-to-read-events/toggling.cy.ts +++ b/integration-tests/cypress/e2e/using-ya-to-read-events/toggling.cy.ts @@ -25,20 +25,20 @@ describe("toggling yazi to pseudo-continue the previous session", () => { // saved as the "last hovered file" hoverAnotherFileToEnsureHoverEventIsReceivedInCI( - dir.contents["test.lua"].name, + dir.contents["test-setup.lua"].name, ) // close yazi cy.typeIntoTerminal("q") // the hovered file should not be visible any longer - cy.contains(dir.contents["test.lua"].name).should("not.exist") + cy.contains(dir.contents["test-setup.lua"].name).should("not.exist") // start yazi again by toggling it cy.typeIntoTerminal("{control+upArrow}") // the previously hovered file should be visible again - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) }) }) @@ -51,7 +51,7 @@ describe("toggling yazi to pseudo-continue the previous session", () => { cy.typeIntoTerminal("{control+upArrow}") // yazi should be visible, showing other files - cy.contains(dir.contents["test.lua"].name) + cy.contains(dir.contents["test-setup.lua"].name) }) }) }) diff --git a/lua/yazi/window.lua b/lua/yazi/window.lua index 66e1aaa..62b42e7 100644 --- a/lua/yazi/window.lua +++ b/lua/yazi/window.lua @@ -1,3 +1,5 @@ +local Log = require('yazi.log') + local M = {} ---@class (exact) YaziFloatingWindow @@ -38,6 +40,13 @@ function YaziFloatingWindow:close() if vim.api.nvim_win_is_valid(self.win) then vim.api.nvim_win_close(self.win, true) + Log:debug( + string.format( + 'YaziFloatingWindow closing (content_buffer: %s, win: %s)', + self.content_buffer, + self.win + ) + ) end end @@ -77,6 +86,13 @@ function YaziFloatingWindow:open_and_display() local win = vim.api.nvim_open_win(yazi_buffer, true, opts) self.win = win self.content_buffer = yazi_buffer + Log:debug( + string.format( + 'YaziFloatingWindow opening (content_buffer: %s, win: %s)', + self.content_buffer, + self.win + ) + ) vim.bo[yazi_buffer].filetype = 'yazi' @@ -86,7 +102,7 @@ function YaziFloatingWindow:open_and_display() vim.cmd('setlocal winhl=NormalFloat:YaziFloat') vim.cmd('set winblend=' .. self.config.yazi_floating_window_winblend) - vim.api.nvim_create_autocmd({ 'WinLeave', 'TermLeave' }, { + vim.api.nvim_create_autocmd({ 'WinLeave' }, { buffer = yazi_buffer, callback = function() self:close()