-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
yazi.toggle()
to continue from the last hovered file (#230)
This commit adds a new function `yazi.toggle()` that can be used to pseudo resume the previous yazi session. An example mapping is added to the README to show how to use it. Note that this requires a very new yazi right now, sxyazi/yazi#1305 from 2024-07-18 You also need to set `use_ya_for_events_reading` and `use_yazi_client_id_flag` to true in your config.
- Loading branch information
1 parent
305a6a5
commit dbddef0
Showing
10 changed files
with
170 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
integration-tests/cypress/e2e/using-ya-to-read-events/toggling.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { startNeovimWithYa } from "./startNeovimWithYa" | ||
|
||
describe("toggling yazi to pseudo-continue the previous session", () => { | ||
beforeEach(() => { | ||
cy.visit("http://localhost:5173") | ||
}) | ||
|
||
function hoverAnotherFileToEnsureHoverEventIsReceivedInCI(file: string) { | ||
// select another file (hacky) | ||
cy.typeIntoTerminal("gg") | ||
|
||
// select the desired file so that a new hover event is sent | ||
cy.typeIntoTerminal(`/${file}{enter}`) | ||
} | ||
|
||
it("can highlight the buffer when hovered", () => { | ||
startNeovimWithYa().then((dir) => { | ||
// wait until text on the start screen is visible | ||
cy.contains("If you see this text, Neovim is ready!") | ||
|
||
// start yazi | ||
cy.typeIntoTerminal("{upArrow}") | ||
|
||
// select another file. This should send a hover event, which should be | ||
// saved as the "last hovered file" | ||
|
||
hoverAnotherFileToEnsureHoverEventIsReceivedInCI( | ||
dir.contents["test.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") | ||
|
||
// 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) | ||
}) | ||
}) | ||
|
||
it("can start yazi even if no previous session exists", () => { | ||
startNeovimWithYa().then((dir) => { | ||
// wait until text on the start screen is visible | ||
cy.contains("If you see this text, Neovim is ready!") | ||
|
||
// toggle yazi | ||
cy.typeIntoTerminal("{control+upArrow}") | ||
|
||
// yazi should be visible, showing other files | ||
cy.contains(dir.contents["test.lua"].name) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
---@class YaziProcessApi | ||
---@field private config YaziConfig | ||
---@field private yazi_id string | ||
local YaziProcessApi = {} | ||
|
||
---@param config YaziConfig | ||
---@param yazi_id string | ||
function YaziProcessApi.new(config, yazi_id) | ||
local self = setmetatable({}, YaziProcessApi) | ||
self.config = config | ||
self.yazi_id = yazi_id | ||
return self | ||
end | ||
|
||
---@param path string | ||
function YaziProcessApi:cd(path) | ||
if | ||
self.config.use_ya_for_events_reading == true | ||
and self.config.use_yazi_client_id_flag == true | ||
then | ||
-- ya pub --str "/" dds-cd 1760127405452166 | ||
assert(path, 'path is required') | ||
vim.system( | ||
{ 'ya', 'pub', '--str', path, 'dds-cd', self.yazi_id }, | ||
{ timeout = 1000 } | ||
) | ||
end | ||
end | ||
|
||
return YaziProcessApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters