Skip to content

Commit

Permalink
fix: opening multiple files in a directory with spaces (#347)
Browse files Browse the repository at this point in the history
Closes #346
  • Loading branch information
mikavilpas authored Aug 9, 2024
1 parent 4e54912 commit f7be6c1
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 53 deletions.
12 changes: 12 additions & 0 deletions integration-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { constants } from "fs"
import { access, mkdir, mkdtemp, readdir, readFile, rm } from "fs/promises"
import path from "path"
import { fileURLToPath } from "url"
import type { TestDirectory } from "./server/application/neovim/testEnvironmentTypes"

const __dirname = fileURLToPath(new URL(".", import.meta.resolve(".")))

Expand Down Expand Up @@ -77,6 +78,16 @@ export default defineConfig({
stem: "initial-file",
extension: ".txt",
},
"dir with spaces/file1.txt": {
name: "file1.txt",
stem: "file1",
extension: ".txt",
},
"dir with spaces/file2.txt": {
name: "file2.txt",
stem: "file2",
extension: ".txt",
},
"test-setup.lua": {
name: "test-setup.lua",
stem: "test-setup",
Expand Down Expand Up @@ -126,6 +137,7 @@ export default defineConfig({
execSync(
`cp ./test-environment/test-setup.lua ${dir}/test-setup.lua`,
)
execSync(`cp -r "./test-environment/dir with spaces" ${dir}/`)
execSync(`cp -r ./test-environment/subdirectory ${dir}/`)
execSync(`cp -r ./test-environment/other-subdirectory ${dir}/`)
execSync(`cp -r ./test-environment/config-modifications/ ${dir}/`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ describe("opening files", () => {
// the copied path should be relative to the file/directory yazi was
// started in (the initial file)

cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
cy.contains("If you see this text, Neovim is ready!")

cy.typeIntoTerminal("{upArrow}")
Expand Down Expand Up @@ -253,7 +253,7 @@ describe("opening files", () => {
// similarly, the copied path should be relative to the file/directory yazi
// was started in (the initial file)

cy.startNeovim().then((dir) => {
startNeovimWithYa().then((dir) => {
cy.contains("If you see this text, Neovim is ready!")

cy.typeIntoTerminal("{upArrow}")
Expand Down Expand Up @@ -292,4 +292,23 @@ describe("opening files", () => {
)
})
})

it("can open multiple files in a directory whose name contains a space character", () => {
startNeovimWithYa({ filename: "dir with spaces/file1.txt" }).then((dir) => {
cy.contains("this is file1.txt")

cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["dir with spaces/file2.txt"].name)

// select all files and open them
cy.typeIntoTerminal("{control+a}")
cy.typeIntoTerminal("{enter}")

cy.typeIntoTerminal(":buffers{enter}")

// all files should now be visible
cy.contains("dir with spaces/file1.txt" satisfies IntegrationTestFile)
cy.contains("dir with spaces/file2.txt" satisfies IntegrationTestFile)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { TestDirectory } from "server/application/neovim/testDirectory"
import type { StartNeovimArguments } from "server/application/neovim/testEnvironmentTypes"
import type {
StartNeovimArguments,
TestDirectory,
} from "server/application/neovim/testEnvironmentTypes"

/** NOTE: always uses the `modify_yazi_config_to_use_ya_as_event_reader.lua` as
* that is implied by the name of the function.
Expand Down
6 changes: 4 additions & 2 deletions integration-tests/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
// }

import "../../client/__global.ts"
import type { TestDirectory } from "../../server/application/neovim/testDirectory"
import type { StartNeovimArguments } from "../../server/application/neovim/testEnvironmentTypes"
import type {
StartNeovimArguments,
TestDirectory,
} from "../../server/application/neovim/testEnvironmentTypes"

Cypress.Commands.add("startNeovim", (startArguments?: StartNeovimArguments) => {
cy.window().then((win) => {
Expand Down
45 changes: 0 additions & 45 deletions integration-tests/server/application/neovim/testDirectory.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ export const multipleFiles = z.object({

export const testDirectoryFile = z.enum([
"initial-file.txt",
"file.txt",
"test-setup.lua",
"modify_yazi_config_to_use_ya_as_event_reader.lua",
"subdirectory/subdirectory-file.txt",
"other-subdirectory/other-sub-file.txt",
"dir with spaces/file1.txt",
"dir with spaces/file2.txt",
"routes/posts.$postId/route.tsx",
"routes/posts.$postId/adjacent-file.txt",
"routes/posts.$postId/should-be-excluded-file.txt",
Expand Down Expand Up @@ -60,4 +63,38 @@ export const startNeovimServerArguments = z.intersection(
startNeovimArguments,
)

export {}
export type FileEntry = {
/** The name of the file and its extension.
* @example "file.txt"
*/
name: string

/** The name of the file without its extension.
* @example "file"
*/
stem: string

/** The extension of the file.
* @example ".txt"
*/
extension: string
}

/** Describes the contents of the test directory, which is a blueprint for
* files and directories. Tests can create a unique, safe environment for
* interacting with the contents of such a directory.
*
* Having strong typing for the test directory contents ensures that tests can
* be written with confidence that the files and directories they expect are
* actually found. Otherwise the tests are brittle and can break easily.
*/
export type TestDirectory = {
/** The path to the unique test directory (the root). */
rootPathAbsolute: string

/** The path to the unique test directory, relative to the root of the
* test-environment directory. */
rootPathRelativeToTestEnvironmentDir: string

contents: Record<TestDirectoryFile, FileEntry>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is file2.txt
3 changes: 2 additions & 1 deletion lua/yazi/openers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ end

---@param chosen_files string[]
function M.open_multiple_files(chosen_files)
vim.cmd("args" .. table.concat(chosen_files, " "))
local quoted = vim.tbl_map(vim.fn.fnameescape, chosen_files)
vim.cmd("args" .. table.concat(quoted, " "))
end

---@param chosen_files string[]
Expand Down

0 comments on commit f7be6c1

Please sign in to comment.