Skip to content

Commit

Permalink
fix: avoid "E13: File exists" error after renaming a file (#560)
Browse files Browse the repository at this point in the history
Fixes #556
  • Loading branch information
mikavilpas authored Nov 13, 2024
1 parent a85a86d commit 58f1227
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 457 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { flavors } from "@catppuccin/palette"
import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities"
import type { MyTestDirectoryFile } from "MyTestDirectory"

describe("reading events", () => {
Expand Down Expand Up @@ -103,8 +105,13 @@ describe("'rename' events", () => {
cy.contains(dir.contents["initial-file.txt"].name)
cy.contains("If you see this text, Neovim is ready!")

// start yazi
// start yazi and wait for the current file to be highlighted
cy.typeIntoTerminal("{upArrow}")
cy.contains(dir.contents["initial-file.txt"].name).should(
"have.css",
"background-color",
rgbify(flavors.macchiato.colors.text.rgb),
)

// start file renaming
cy.typeIntoTerminal("r")
Expand All @@ -122,6 +129,10 @@ describe("'rename' events", () => {

// the buffer name should now be updated
cy.contains(newFileName)

// the file should be saveable
cy.typeIntoTerminal(":w{enter}")
cy.contains("E13").should("not.exist")
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { flavors } from "@catppuccin/palette"
import { rgbify } from "./hover-utils"
import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities"

const darkTheme = flavors.macchiato.colors

Expand Down
3 changes: 1 addition & 2 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"prettier-plugin-organize-imports": "4.1.0",
"tinycolor2": "1.6.0",
"type-fest": "4.26.1",
"typescript": "5.6.3",
"vite": "5.4.10"
"typescript": "5.6.3"
}
}
2 changes: 2 additions & 0 deletions lua/yazi/renameable_buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function RenameableBuffer:matches_exactly(path)
end

---@param path string
---@return boolean
function RenameableBuffer:matches_parent(path)
path = remove_trailing_slash(path)
local found = plenary_iterators
Expand All @@ -57,6 +58,7 @@ end
--- When hovering over a file or a directory `other`, return true if this
--- buffer is in the same directory as `other`.
---@param other string
---@return boolean
function RenameableBuffer:is_sibling_of_hovered(other)
other = remove_trailing_slash(other)
local utils = require("yazi.utils")
Expand Down
5 changes: 5 additions & 0 deletions lua/yazi/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ function M.rename_or_close_buffer(instruction)
pcall(function()
vim.api.nvim_buf_set_name(instruction.bufnr, instruction.path.filename)
end)
vim.schedule(function()
vim.api.nvim_buf_call(instruction.bufnr, function()
vim.cmd("edit!")
end)
end)
end

---@param prev_win integer
Expand Down
Loading

0 comments on commit 58f1227

Please sign in to comment.