From 42cbedbe42936f61170d049f1b77541a5ab66e3d Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 25 Feb 2024 03:41:00 +0800 Subject: [PATCH] feat: add `idx` field to the file API --- yazi-fm/src/lives/file.rs | 1 + yazi-fm/src/lives/tabs.rs | 2 +- yazi-plugin/preset/components/header.lua | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/yazi-fm/src/lives/file.rs b/yazi-fm/src/lives/file.rs index 615ea1ea..98aebb26 100644 --- a/yazi-fm/src/lives/file.rs +++ b/yazi-fm/src/lives/file.rs @@ -31,6 +31,7 @@ impl File { pub(super) fn register(lua: &Lua) -> mlua::Result<()> { lua.register_userdata_type::(|reg| { + reg.add_field_method_get("idx", |_, me| Ok(me.idx + 1)); reg.add_field_method_get("url", |lua, me| Url::cast(lua, me.url.clone())); reg.add_field_method_get("cha", |lua, me| Cha::cast(lua, me.cha)); reg.add_field_method_get("link_to", |lua, me| { diff --git a/yazi-fm/src/lives/tabs.rs b/yazi-fm/src/lives/tabs.rs index 40f2ba3d..73f46f99 100644 --- a/yazi-fm/src/lives/tabs.rs +++ b/yazi-fm/src/lives/tabs.rs @@ -22,7 +22,7 @@ impl Tabs { pub(super) fn register(lua: &Lua) -> mlua::Result<()> { lua.register_userdata_type::(|reg| { - reg.add_field_method_get("idx", |_, me| Ok(me.idx)); + reg.add_field_method_get("idx", |_, me| Ok(me.idx + 1)); reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len())); diff --git a/yazi-plugin/preset/components/header.lua b/yazi-plugin/preset/components/header.lua index f0f84bf4..8f02c035 100644 --- a/yazi-plugin/preset/components/header.lua +++ b/yazi-plugin/preset/components/header.lua @@ -51,7 +51,7 @@ function Header:tabs() if THEME.manager.tab_width > 2 then text = ya.truncate(text .. " " .. cx.tabs[i]:name(), THEME.manager.tab_width) end - if i == cx.tabs.idx + 1 then + if i == cx.tabs.idx then spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_active) else spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_inactive)