Path comparison fails in api2.2 (or how to compare same paths of diff tabs)
Opened this issue · 0 comments
Thew newer 2.2 api version adds a new Path
class https://marta.sh/api/marta/path.type/ that's supposed to be Equatable
, so I thought identical path would compare to each other.
But then this plugin fails (open a few identical tabs and run Tab: Path comparison bug
command - in 2.1 it will show a popup that there are identical tabs, in 2.2 it will fail and show a popup that no identical paths are found)
Maybe I misunderstand all this equatable stuff, but I thought if I store a path
in a different var and later compare via ==
to the same path from another tab, it should be the same since it's supposed to compare rawValues
due to Implements _eq, comparing rawValues.
marta.expose()
marta.plugin({id="bug", name="path comparison bug", apiVersion="2.1"})
marta.action({id="id_tab_pathcomp21", name="Tab: Path comparison bug 2.1"
,apply=function(ctxA) tabPathComparison({ctxA=ctxA}); end})
local std = {}
-- Print contents of `tbl`, with indentation `indent`, to string
function std.t2str(tbl, indent, out)
if not indent then indent = 0 end
if not out then out = '' end
for k, v in pairs(tbl) do
key = string.rep(" ",indent)..k..": "
if type(v) == "table" then out = out..key ..'\n'; out=std.t2str(v,indent+1,out)
elseif type(v) == "boolean" then out = out..key..tostring(v)..'\n'
elseif type(v) == "string" then out = out..key.. v ..'\n'
else out = out..key..tostring(v)..'\n' end
end
return out
end
function tabPathComparison(arg)
local ctxA = arg.ctxA
local ctxW = ctxA.window
local tabMan = ctxW.tabs
local paneMan = ctxW.panes
local tabA = paneMan.activePane
local tabPos = tabMan:getPosition(tabA) -- Get the tab position --(tab:PaneContext):Option<TabPosition>
local tabCount = tabMan:getCount (tabPos ) -- tab count for a given position --(pos: Option<TabPosition>):Int
local i = 0
print("tabCount = "..tabCount)
local prev = nil
local dupe = false
local path_list = {}
while (i < tabCount) do
local tab = tabMan:getTab(tabPos, i)
↓ this fails
local path = tab.model.folder.path -- FAILS
replacing ↑ with ↓ succeeds since we store strings, but I thought Implements _eq, comparing rawValues
should do the same when we don't do the conversion and use ==
directly on path
s?
-- local path = tab.model.folder.path.rawValue -- WORKS
if (path == prev) then
martax.alert("DUPE path" .. tostring(i).. tostring(path))
dupe = true
end
path_list[i] = path
prev = path
i = i + 1
end
if not dupe then
martax.alert("NO dupes in paths" .. std.t2str(path_list))
end
end