-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't open duplicate tabs when opening files (#367)
Problem: With a split window setup of two files (a and b) like this `a|a|b`, when the split `b` was focused, yazi.nvim would open 3 yazi tabs instead of 2. Solution: Add a function to remove duplicates from the list of files to open.
- Loading branch information
1 parent
24e9f61
commit 1c1ac86
Showing
4 changed files
with
88 additions
and
2 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
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,72 @@ | ||
local assert = require("luassert") | ||
local ya_process = require("yazi.process.ya_process") | ||
|
||
describe("the get_yazi_command() function", function() | ||
it("specifies opening multiple tabs when enabled in the config", function() | ||
local config = require("yazi.config").default() | ||
config.open_multiple_tabs = true | ||
config.chosen_file_path = "/tmp/chosen_file_path" | ||
|
||
local ya = ya_process.new(config, "yazi_id_123") | ||
|
||
local paths = { | ||
{ filename = "file1" }, | ||
{ filename = "file2" }, | ||
} | ||
|
||
local command = ya:get_yazi_command(paths) | ||
|
||
assert.are.same( | ||
"yazi 'file1' 'file2' --chooser-file /tmp/chosen_file_path", | ||
command | ||
) | ||
end) | ||
|
||
it( | ||
"does not specify opening multiple tabs when disabled in the config", | ||
function() | ||
local config = require("yazi.config").default() | ||
config.open_multiple_tabs = false | ||
config.chosen_file_path = "/tmp/chosen_file_path" | ||
|
||
local ya = ya_process.new(config, "yazi_id_123") | ||
|
||
local paths = { | ||
{ filename = "file1" }, | ||
{ filename = "file2" }, | ||
} | ||
|
||
local command = ya:get_yazi_command(paths) | ||
|
||
assert.are.same( | ||
"yazi 'file1' --chooser-file /tmp/chosen_file_path", | ||
command | ||
) | ||
end | ||
) | ||
|
||
it("doesn't open duplicate tabs", function() | ||
local config = require("yazi.config").default() | ||
config.open_multiple_tabs = true | ||
config.chosen_file_path = "/tmp/chosen_file_path" | ||
|
||
local ya = ya_process.new(config, "yazi_id_123") | ||
|
||
local paths = { | ||
{ filename = "file1" }, | ||
{ filename = "file1" }, | ||
|
||
{ filename = "file2" }, | ||
{ filename = "file2" }, | ||
|
||
{ filename = "file3" }, | ||
} | ||
|
||
local command = ya:get_yazi_command(paths) | ||
|
||
assert.are.same( | ||
"yazi 'file1' 'file2' 'file3' --chooser-file /tmp/chosen_file_path", | ||
command | ||
) | ||
end) | ||
end) |
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