Skip to content

Commit

Permalink
feat: allow cycle_open_buffers (tab) to work for a single file (#451)
Browse files Browse the repository at this point in the history
* feat: allow cycle_open_buffers (`tab`) to work for a single file

Issue
=====

Using `tab` to cycle through open buffers does not work when only one
buffer is open. I disabled it because I thought it was not useful in
that case, but actually it can still be useful in the following case:

- you have opened yazi and have a single buffer open in neovim (no
  splits)
- you have navigated to a different directory in the file explorer
- you have gotten lost
- you want to get back to the beginning with `tab`

Solution
========

Enable `tab` to cd to the single buffer's directory.

Solves #447

* fixup! feat: allow cycle_open_buffers (`tab`) to work for a single file
  • Loading branch information
mikavilpas committed Sep 11, 2024
1 parent ff28ad2 commit 2d80e92
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions integration-tests/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default defineConfig({
},
})
},
experimentalRunAllSpecs: true,
retries: {
runMode: 2,
openMode: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,24 @@ describe("'cd' to another buffer's directory", () => {
isHoveredInNeovim(view.rightFile.text)
})
})

it("can tab to the directory of just a single buffer", () => {
cy.startNeovim({
filename: "file.txt",
}).then((dir) => {
cy.contains("Hello")

cy.typeIntoTerminal("{upArrow}")
cy.contains("initial-file.txt")

cy.typeIntoTerminal(`/routes{enter}`, { delay: 1 })
cy.contains("posts.$postId")

// enter the directory and make sure its contents are shown
cy.typeIntoTerminal("l")
cy.contains(dir.contents["routes/posts.$postId/route.tsx"].name)

cy.typeIntoTerminal("{control+i}")
})
})
})
6 changes: 5 additions & 1 deletion lua/yazi/keybinding_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ function YaziOpenerActions.cycle_open_buffers(context)
~= current_cycle_position.filename
end)

if #visible_buffers == 1 then
next_buffer = buffer
end

if not next_buffer then
Log:debug(
string.format(
'Could not find next buffer for path: "%s", probably only one is open.',
'Could not find next buffer for path: "%s".',
context.input_path
)
)
Expand Down

0 comments on commit 2d80e92

Please sign in to comment.