feat: add idx field to the file API

This commit is contained in:
sxyazi 2024-02-25 03:41:00 +08:00
parent b4d91df767
commit 42cbedbe42
No known key found for this signature in database
3 changed files with 3 additions and 2 deletions

View File

@ -31,6 +31,7 @@ impl File {
pub(super) fn register(lua: &Lua) -> mlua::Result<()> { pub(super) fn register(lua: &Lua) -> mlua::Result<()> {
lua.register_userdata_type::<Self>(|reg| { lua.register_userdata_type::<Self>(|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("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("cha", |lua, me| Cha::cast(lua, me.cha));
reg.add_field_method_get("link_to", |lua, me| { reg.add_field_method_get("link_to", |lua, me| {

View File

@ -22,7 +22,7 @@ impl Tabs {
pub(super) fn register(lua: &Lua) -> mlua::Result<()> { pub(super) fn register(lua: &Lua) -> mlua::Result<()> {
lua.register_userdata_type::<Self>(|reg| { lua.register_userdata_type::<Self>(|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())); reg.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.len()));

View File

@ -51,7 +51,7 @@ function Header:tabs()
if THEME.manager.tab_width > 2 then if THEME.manager.tab_width > 2 then
text = ya.truncate(text .. " " .. cx.tabs[i]:name(), THEME.manager.tab_width) text = ya.truncate(text .. " " .. cx.tabs[i]:name(), THEME.manager.tab_width)
end 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) spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_active)
else else
spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_inactive) spans[#spans + 1] = ui.Span(" " .. text .. " "):style(THEME.manager.tab_inactive)