Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion yazi-actor/src/pick/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yazi_macro::mod_flat!(arrow close show);
yazi_macro::mod_flat!(arrow close select show);
31 changes: 31 additions & 0 deletions yazi-actor/src/pick/select.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use anyhow::Result;
use yazi_macro::{render, succ};
use yazi_parser::pick::SelectForm;
use yazi_shared::data::Data;

use crate::{Actor, Ctx};

pub struct Select;

impl Actor for Select {
type Form = SelectForm;

const NAME: &str = "select";

fn act(cx: &mut Ctx, opt: Self::Form) -> Result<Data> {
let pick = &mut cx.pick;
if opt.index >= pick.items.len() {
succ!();
}

if let Some(cb) = pick.callback.take() {
_ = cb.send(Some(opt.index));
}

pick.cursor = 0;
pick.offset = 0;
pick.visible = false;

succ!(render!());
}
}
10 changes: 10 additions & 0 deletions yazi-config/preset/keymap-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,16 @@ keymap = [
{ on = "<Up>", run = "arrow prev", desc = "Previous option" },
{ on = "<Down>", run = "arrow next", desc = "Next option" },

{ on = "1", run = "select 0", desc = "Select first option" },
{ on = "2", run = "select 1", desc = "Select second option" },
{ on = "3", run = "select 2", desc = "Select third option" },
{ on = "4", run = "select 3", desc = "Select fourth option" },
{ on = "5", run = "select 4", desc = "Select fifth option" },
{ on = "6", run = "select 5", desc = "Select sixth option" },
{ on = "7", run = "select 6", desc = "Select seventh option" },
{ on = "8", run = "select 7", desc = "Select eighth option" },
{ on = "9", run = "select 8", desc = "Select ninth option" },

# Help
{ on = "~", run = "help", desc = "Open help" },
{ on = "<F1>", run = "help", desc = "Open help" },
Expand Down
1 change: 1 addition & 0 deletions yazi-config/preset/yazi-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ quit_offset = [ 0, 0, 50, 15 ]
open_title = "Open with:"
open_origin = "hovered"
open_offset = [ 0, 1, 50, 7 ]
line_numbers = true

[which]
sort_by = "none"
Expand Down
7 changes: 4 additions & 3 deletions yazi-config/src/popup/pick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use super::{Offset, Origin};
#[derive(Deserialize, DeserializeOver2)]
pub struct Pick {
// open
pub open_title: String,
pub open_origin: Origin,
pub open_offset: Offset,
pub open_title: String,
pub open_origin: Origin,
pub open_offset: Offset,
pub line_numbers: bool,
}

impl Pick {
Expand Down
1 change: 1 addition & 0 deletions yazi-fm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ impl<'a> Executor<'a> {
}

on!(show);
on!(select);
on!(close);
on!(arrow);

Expand Down
15 changes: 10 additions & 5 deletions yazi-fm/src/pick/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ratatui::{buffer::Buffer, layout::{Margin, Rect}, widgets::{ListItem, Scrollbar, ScrollbarOrientation, ScrollbarState, StatefulWidget, Widget}};
use yazi_config::THEME;
use yazi_config::{THEME, YAZI};
use yazi_core::Core;
use yazi_widgets::Scrollable;

Expand Down Expand Up @@ -27,11 +27,16 @@ impl Widget for List<'_> {
// List content
let inner = area.inner(Margin::new(1, 0));
let items = pick.window().map(|(i, v)| {
if i == pick.cursor {
ListItem::new(format!(" {v}")).style(THEME.pick.active)
let (prefix, style) =
if i == pick.cursor { ("", THEME.pick.active) } else { (" ", THEME.pick.inactive) };

let index_str = if !YAZI.pick.line_numbers {
"".to_string()
} else {
ListItem::new(format!(" {v}")).style(THEME.pick.inactive)
}
if i < 9 { format!("{:>2}", i + 1) } else { " ".to_string() }
};

ListItem::new(format!("{prefix}{index_str} {v}")).style(style)
});
Widget::render(ratatui::widgets::List::new(items), inner, buf);
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-parser/src/pick/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
yazi_macro::mod_flat!(close show);
yazi_macro::mod_flat!(close select show);
23 changes: 23 additions & 0 deletions yazi-parser/src/pick/select.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use mlua::{ExternalError, FromLua, IntoLua, Lua, Value};
use yazi_shared::event::ActionCow;

#[derive(Debug)]
pub struct SelectForm {
pub index: usize,
}

impl From<ActionCow> for SelectForm {
fn from(c: ActionCow) -> Self { Self { index: c.first().unwrap_or(0) } }
}

impl From<usize> for SelectForm {
fn from(index: usize) -> Self { Self { index } }
}

impl FromLua for SelectForm {
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
}

impl IntoLua for SelectForm {
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
}
3 changes: 3 additions & 0 deletions yazi-parser/src/spark/spark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub enum Spark<'a> {
// Pick
PickArrow(crate::ArrowForm),
PickClose(crate::pick::CloseForm),
PickSelect(crate::pick::SelectForm),
PickShow(crate::pick::ShowForm),

// Spot
Expand Down Expand Up @@ -316,6 +317,7 @@ impl<'a> IntoLua for Spark<'a> {
// Pick
Self::PickArrow(b) => b.into_lua(lua),
Self::PickClose(b) => b.into_lua(lua),
Self::PickSelect(b) => b.into_lua(lua),
Self::PickShow(b) => b.into_lua(lua),

// Spot
Expand Down Expand Up @@ -432,6 +434,7 @@ try_from_spark!(crate::mgr::YankForm, mgr:yank);
try_from_spark!(crate::notify::PushForm, notify:push);
try_from_spark!(crate::notify::TickForm, notify:tick);
try_from_spark!(crate::pick::CloseForm, pick:close);
try_from_spark!(crate::pick::SelectForm, pick: select);
try_from_spark!(crate::pick::ShowForm, pick:show);
try_from_spark!(crate::spot::CopyForm, spot:copy);
try_from_spark!(crate::tasks::ProcessOpenForm, tasks:process_open);
Expand Down
Loading