mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
8d4ee2a9b7
commit
ff369f4d15
12 changed files with 118 additions and 171 deletions
|
|
@ -24,7 +24,6 @@ pub enum Event {
|
||||||
Files(FilesOp),
|
Files(FilesOp),
|
||||||
Pages(usize),
|
Pages(usize),
|
||||||
Mimetype(BTreeMap<Url, String>),
|
Mimetype(BTreeMap<Url, String>),
|
||||||
Peek(Option<(usize, Url)>),
|
|
||||||
Preview(PreviewLock),
|
Preview(PreviewLock),
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
|
|
@ -80,12 +79,6 @@ macro_rules! emit {
|
||||||
(Mimetype($mimes:expr)) => {
|
(Mimetype($mimes:expr)) => {
|
||||||
$crate::Event::Mimetype($mimes).emit();
|
$crate::Event::Mimetype($mimes).emit();
|
||||||
};
|
};
|
||||||
(Peek) => {
|
|
||||||
$crate::Event::Peek(None).emit();
|
|
||||||
};
|
|
||||||
(Peek($skip:expr, $url:expr)) => {
|
|
||||||
$crate::Event::Peek(Some(($skip, $url))).emit();
|
|
||||||
};
|
|
||||||
(Preview($lock:expr)) => {
|
(Preview($lock:expr)) => {
|
||||||
$crate::Event::Preview($lock).emit();
|
$crate::Event::Preview($lock).emit();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use yazi_config::{keymap::{Control, Key, KeymapLayer}, KEYMAP};
|
||||||
use yazi_shared::Term;
|
use yazi_shared::Term;
|
||||||
|
|
||||||
use super::HELP_MARGIN;
|
use super::HELP_MARGIN;
|
||||||
use crate::{emit, input::Input};
|
use crate::input::Input;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Help {
|
pub struct Help {
|
||||||
|
|
@ -35,7 +35,8 @@ impl Help {
|
||||||
self.offset = 0;
|
self.offset = 0;
|
||||||
self.cursor = 0;
|
self.cursor = 0;
|
||||||
|
|
||||||
emit!(Peek); // Show/hide preview for images
|
// TODO: Peek
|
||||||
|
// emit!(Peek); // Show/hide preview for images
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,24 +23,23 @@ impl Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hover(&mut self, opt: impl Into<Opt>) -> bool {
|
pub fn hover(&mut self, opt: impl Into<Opt>) -> bool {
|
||||||
|
// Re-peek
|
||||||
|
self.peek(0);
|
||||||
|
|
||||||
// Refresh watcher
|
// Refresh watcher
|
||||||
let mut to_watch = BTreeSet::new();
|
let mut to_watch = BTreeSet::new();
|
||||||
for tab in self.tabs.iter() {
|
for tab in self.tabs.iter() {
|
||||||
to_watch.insert(&tab.current.cwd);
|
to_watch.insert(&tab.current.cwd);
|
||||||
match tab.current.hovered() {
|
|
||||||
Some(h) if h.is_dir() => _ = to_watch.insert(&h.url),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
if let Some(ref p) = tab.parent {
|
if let Some(ref p) = tab.parent {
|
||||||
to_watch.insert(&p.cwd);
|
to_watch.insert(&p.cwd);
|
||||||
}
|
}
|
||||||
|
if let Some(h) = tab.current.hovered().filter(|&h| h.is_dir()) {
|
||||||
|
to_watch.insert(&h.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.watcher.watch(to_watch);
|
self.watcher.watch(to_watch);
|
||||||
|
|
||||||
// Trigger peek
|
// Hover on the file
|
||||||
emit!(Peek);
|
|
||||||
|
|
||||||
// Hover
|
|
||||||
let opt = opt.into() as Opt;
|
let opt = opt.into() as Opt;
|
||||||
self.current_mut().repos(opt.url)
|
self.current_mut().repos(opt.url)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,83 @@
|
||||||
use crate::manager::Manager;
|
use yazi_config::{keymap::{Exec, KeymapLayer}, MANAGER};
|
||||||
|
use yazi_shared::{Url, MIME_DIR};
|
||||||
|
|
||||||
|
use crate::{emit, manager::Manager};
|
||||||
|
|
||||||
|
pub struct Opt {
|
||||||
|
step: isize,
|
||||||
|
sequent: Option<Url>,
|
||||||
|
upper_bound: Option<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<&Exec> for Opt {
|
||||||
|
fn from(e: &Exec) -> Self {
|
||||||
|
Self {
|
||||||
|
step: e.args.first().and_then(|s| s.parse().ok()).unwrap_or(0),
|
||||||
|
sequent: e.named.get("sequent").map(Url::from),
|
||||||
|
upper_bound: e.named.get("upper-bound").and_then(|s| s.parse().ok()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<isize> for Opt {
|
||||||
|
fn from(step: isize) -> Self { Self { step, sequent: None, upper_bound: None } }
|
||||||
|
}
|
||||||
|
|
||||||
impl Manager {
|
impl Manager {
|
||||||
pub fn peek(&mut self, sequent: bool) -> bool {
|
#[inline]
|
||||||
let Some(hovered) = self.hovered().cloned() else {
|
pub fn _peek_upper_bound(bound: usize, sequent: &Url) {
|
||||||
|
emit!(Call(
|
||||||
|
Exec::call("peek", vec![])
|
||||||
|
.with("sequent", sequent.to_string())
|
||||||
|
.with("upper-bound", bound.to_string())
|
||||||
|
.vec(),
|
||||||
|
KeymapLayer::Manager
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn peek(&mut self, opt: impl Into<Opt>) -> bool {
|
||||||
|
let Some(hovered) = self.hovered() else {
|
||||||
return self.active_mut().preview.reset(|_| true);
|
return self.active_mut().preview.reset(|_| true);
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = &hovered.url;
|
let opt = opt.into() as Opt;
|
||||||
if hovered.is_dir() {
|
if matches!(opt.sequent, Some(ref u) if *u != hovered.url) {
|
||||||
let position = self.active().history(url).map(|f| (f.offset, f.files.len()));
|
|
||||||
self.active_mut().preview.folder(url, position, sequent);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(mime) = self.mimetype.get(url).cloned() else {
|
if hovered.is_dir() {
|
||||||
|
return self.peek_folder(opt, hovered.url.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
let Some(mime) = self.mimetype.get(&hovered.url).cloned() else {
|
||||||
return self.active_mut().preview.reset(|_| true);
|
return self.active_mut().preview.reset(|_| true);
|
||||||
};
|
};
|
||||||
|
|
||||||
if sequent {
|
let url = hovered.url.clone();
|
||||||
self.active_mut().preview.sequent(url, &mime);
|
self.active_mut().preview.arrow(opt.step, &mime);
|
||||||
} else {
|
if let Some(bound) = opt.upper_bound {
|
||||||
self.active_mut().preview.go(url, &mime);
|
self.active_mut().preview.apply_bound(bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.active_mut().preview.go(&url, &mime);
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
fn peek_folder(&mut self, opt: Opt, url: Url) -> bool {
|
||||||
|
let (skip, bound) = self
|
||||||
|
.active()
|
||||||
|
.history
|
||||||
|
.get(&url)
|
||||||
|
.map(|f| (f.offset, f.files.len().saturating_sub(MANAGER.layout.folder_height())))
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if opt.sequent.is_some() {
|
||||||
|
self.active_mut().preview.arrow(opt.step, MIME_DIR);
|
||||||
|
} else {
|
||||||
|
self.active_mut().preview.set_skip(skip);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.active_mut().preview.apply_bound(bound);
|
||||||
|
self.active_mut().preview.go_folder(url, opt.sequent.is_none());
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
use std::time::Duration;
|
use std::{mem, time::Duration};
|
||||||
|
|
||||||
use tokio::{pin, task::JoinHandle};
|
use tokio::{pin, task::JoinHandle};
|
||||||
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
|
||||||
use yazi_adaptor::ADAPTOR;
|
use yazi_adaptor::ADAPTOR;
|
||||||
use yazi_config::MANAGER;
|
use yazi_config::MANAGER;
|
||||||
use yazi_shared::{MimeKind, PeekError, Url, MIME_DIR};
|
use yazi_shared::{MimeKind, PeekError, Url};
|
||||||
|
|
||||||
use super::Provider;
|
use super::Provider;
|
||||||
use crate::{emit, files::{Files, FilesOp}, Highlighter};
|
use crate::{emit, files::{Files, FilesOp}, manager::Manager, Highlighter};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Preview {
|
pub struct Preview {
|
||||||
|
|
@ -19,7 +19,6 @@ pub struct Preview {
|
||||||
|
|
||||||
pub struct PreviewLock {
|
pub struct PreviewLock {
|
||||||
pub url: Url,
|
pub url: Url,
|
||||||
pub mime: String,
|
|
||||||
pub skip: usize,
|
pub skip: usize,
|
||||||
pub data: PreviewData,
|
pub data: PreviewData,
|
||||||
}
|
}
|
||||||
|
|
@ -33,119 +32,48 @@ pub enum PreviewData {
|
||||||
|
|
||||||
impl Preview {
|
impl Preview {
|
||||||
pub fn go(&mut self, url: &Url, mime: &str) {
|
pub fn go(&mut self, url: &Url, mime: &str) {
|
||||||
let kind = MimeKind::new(mime);
|
|
||||||
if self.same(url, mime) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.reset(|_| true);
|
self.reset(|_| true);
|
||||||
if !self.same_mime(url, mime) {
|
let (url, skip, kind) = (url.clone(), self.skip, MimeKind::new(mime));
|
||||||
self.skip = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let (url, mime, skip) = (url.clone(), mime.to_owned(), self.skip);
|
|
||||||
self.handle = Some(tokio::spawn(async move {
|
self.handle = Some(tokio::spawn(async move {
|
||||||
match Provider::auto(kind, &url, skip).await {
|
match Provider::auto(kind, &url, skip).await {
|
||||||
Ok(data) => {
|
Ok(data) => {
|
||||||
emit!(Preview(PreviewLock { url, mime, skip, data }));
|
emit!(Preview(PreviewLock { url, skip, data }));
|
||||||
}
|
}
|
||||||
Err(PeekError::Exceed(max)) => {
|
Err(PeekError::Exceed(max)) => {
|
||||||
emit!(Peek(max, url));
|
Manager::_peek_upper_bound(max, &url);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn folder(&mut self, url: &Url, position: Option<(usize, usize)>, sequent: bool) {
|
pub fn go_folder(&mut self, url: Url, in_chunks: bool) {
|
||||||
if let Some((_, len)) = position {
|
|
||||||
self.skip = self.skip.min(len.saturating_sub(MANAGER.layout.preview_height()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.same(url, MIME_DIR) {
|
|
||||||
return;
|
|
||||||
} else if !self.same_mime(url, MIME_DIR) {
|
|
||||||
self.skip = position.map(|(offset, _)| offset).unwrap_or(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.reset(|_| true);
|
self.reset(|_| true);
|
||||||
emit!(Preview(PreviewLock {
|
emit!(Preview(PreviewLock { url: url.clone(), skip: self.skip, data: PreviewData::Folder }));
|
||||||
url: url.clone(),
|
|
||||||
mime: MIME_DIR.to_owned(),
|
|
||||||
skip: self.skip,
|
|
||||||
data: PreviewData::Folder,
|
|
||||||
}));
|
|
||||||
|
|
||||||
if sequent {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let url = url.clone();
|
|
||||||
self.handle = Some(tokio::spawn(async move {
|
self.handle = Some(tokio::spawn(async move {
|
||||||
let Ok(rx) = Files::from_dir(&url).await else {
|
let Ok(rx) = Files::from_dir(&url).await else {
|
||||||
emit!(Files(FilesOp::IOErr(url)));
|
emit!(Files(FilesOp::IOErr(url.clone())));
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if position.is_some() {
|
if !in_chunks {
|
||||||
emit!(Files(FilesOp::Full(url, UnboundedReceiverStream::new(rx).collect().await)));
|
emit!(Files(FilesOp::Full(url.clone(), UnboundedReceiverStream::new(rx).collect().await)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rx = UnboundedReceiverStream::new(rx).chunks_timeout(10000, Duration::from_millis(500));
|
let stream =
|
||||||
pin!(rx);
|
UnboundedReceiverStream::new(rx).chunks_timeout(10000, Duration::from_millis(500));
|
||||||
|
pin!(stream);
|
||||||
|
|
||||||
let ticket = FilesOp::prepare(&url);
|
let ticket = FilesOp::prepare(&url);
|
||||||
while let Some(chunk) = rx.next().await {
|
while let Some(chunk) = stream.next().await {
|
||||||
emit!(Files(FilesOp::Part(url.clone(), ticket, chunk)));
|
emit!(Files(FilesOp::Part(url.clone(), ticket, chunk)));
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sequent(&mut self, url: &Url, mime: &str) {
|
|
||||||
let kind = MimeKind::new(mime);
|
|
||||||
if self.same(url, mime) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.handle.take().map(|h| h.abort());
|
|
||||||
Highlighter::abort();
|
|
||||||
|
|
||||||
let (url, mime, skip) = (url.clone(), mime.to_owned(), self.skip);
|
|
||||||
self.handle = Some(tokio::spawn(async move {
|
|
||||||
match Provider::auto(kind, &url, skip).await {
|
|
||||||
Ok(data) => {
|
|
||||||
emit!(Preview(PreviewLock { url, mime, skip, data }));
|
|
||||||
}
|
|
||||||
Err(PeekError::Exceed(max)) => {
|
|
||||||
emit!(Peek(max, url));
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn arrow(&mut self, step: isize) -> bool {
|
|
||||||
let Some(kind) = self.lock.as_ref().map(|l| MimeKind::new(&l.mime)) else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
let old = self.skip;
|
|
||||||
let size = Provider::step_size(kind, step.unsigned_abs());
|
|
||||||
|
|
||||||
self.skip = if step < 0 { old.saturating_sub(size) } else { old + size };
|
|
||||||
self.skip != old
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn arrow_max(&mut self, max: usize) -> bool {
|
|
||||||
if self.skip > max {
|
|
||||||
self.skip = max;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn reset<F: FnOnce(&PreviewLock) -> bool>(&mut self, f: F) -> bool {
|
pub fn reset<F: FnOnce(&PreviewLock) -> bool>(&mut self, f: F) -> bool {
|
||||||
self.handle.take().map(|h| h.abort());
|
self.handle.take().map(|h| h.abort());
|
||||||
Highlighter::abort();
|
Highlighter::abort();
|
||||||
|
|
@ -166,28 +94,25 @@ impl Preview {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Preview {
|
impl Preview {
|
||||||
|
// --- skip
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn same(&self, url: &Url, mime: &str) -> bool {
|
pub fn arrow(&mut self, step: isize, mime: &str) -> bool {
|
||||||
if let Some(ref lock) = self.lock {
|
let size = Provider::step_size(MimeKind::new(mime), step.unsigned_abs());
|
||||||
return &lock.url == url && lock.mime == mime && lock.skip == self.skip;
|
let skip = if step < 0 { self.skip.saturating_sub(size) } else { self.skip + size };
|
||||||
}
|
mem::replace(&mut self.skip, skip) != skip
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn same_mime(&self, url: &Url, mime: &str) -> bool {
|
pub fn set_skip(&mut self, skip: usize) -> bool { mem::replace(&mut self.skip, skip) != skip }
|
||||||
if let Some(ref lock) = self.lock {
|
|
||||||
return &lock.url == url && lock.mime == mime;
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn same_path(&self, url: &Url) -> bool {
|
pub fn apply_bound(&mut self, max: usize) -> bool {
|
||||||
if let Some(ref lock) = self.lock {
|
if self.skip <= max {
|
||||||
return &lock.url == url;
|
return false;
|
||||||
}
|
}
|
||||||
false
|
|
||||||
|
self.skip = max;
|
||||||
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_config::keymap::Exec;
|
||||||
|
|
||||||
use crate::{emit, tab::Tab};
|
use crate::{manager::Manager, tab::Tab};
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
pub fn hidden(&mut self, e: &Exec) -> bool {
|
pub fn hidden(&mut self, e: &Exec) -> bool {
|
||||||
|
|
@ -10,7 +10,7 @@ impl Tab {
|
||||||
_ => !self.conf.show_hidden,
|
_ => !self.conf.show_hidden,
|
||||||
};
|
};
|
||||||
if self.apply_files_attrs(false) {
|
if self.apply_files_attrs(false) {
|
||||||
emit!(Peek);
|
Manager::_hover(None);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
||||||
|
|
@ -47,18 +47,6 @@ impl From<&Url> for Tab {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
pub fn update_peek(&mut self, max: usize, url: Url) -> bool {
|
|
||||||
let Some(hovered) = self.current.hovered() else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
if url != hovered.url {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.preview.arrow_max(max)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn update_preview(&mut self, lock: PreviewLock) -> bool {
|
pub fn update_preview(&mut self, lock: PreviewLock) -> bool {
|
||||||
let Some(hovered) = self.current.hovered().map(|h| &h.url) else {
|
let Some(hovered) = self.current.hovered().map(|h| &h.url) else {
|
||||||
return self.preview.reset(|_| true);
|
return self.preview.reset(|_| true);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use yazi_config::keymap::Exec;
|
use yazi_config::keymap::Exec;
|
||||||
|
|
||||||
use crate::{emit, tasks::Tasks};
|
use crate::tasks::Tasks;
|
||||||
|
|
||||||
pub struct Opt;
|
pub struct Opt;
|
||||||
|
|
||||||
|
|
@ -14,7 +14,8 @@ impl From<()> for Opt {
|
||||||
impl Tasks {
|
impl Tasks {
|
||||||
pub fn toggle(&mut self, _: impl Into<Opt>) -> bool {
|
pub fn toggle(&mut self, _: impl Into<Opt>) -> bool {
|
||||||
self.visible = !self.visible;
|
self.visible = !self.visible;
|
||||||
emit!(Peek); // Show/hide preview for images
|
// TODO: Peek
|
||||||
|
// emit!(Peek); // Show/hide preview for images
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ impl Which {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn switch(&mut self, state: bool) {
|
fn switch(&mut self, state: bool) {
|
||||||
self.visible = state;
|
self.visible = state;
|
||||||
emit!(Peek); // Show/hide preview for images
|
// TODO: Peek
|
||||||
|
// emit!(Peek); // Show/hide preview for images
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,8 @@ impl App {
|
||||||
|
|
||||||
self.cx.manager.current_mut().set_page(true);
|
self.cx.manager.current_mut().set_page(true);
|
||||||
self.cx.manager.active_mut().preview.reset(|_| true);
|
self.cx.manager.active_mut().preview.reset(|_| true);
|
||||||
self.cx.manager.peek(true);
|
// TODO: Peek-trigger
|
||||||
|
// self.cx.manager.peek(true);
|
||||||
emit!(Render);
|
emit!(Render);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,15 +167,7 @@ impl App {
|
||||||
Event::Mimetype(mimes) => {
|
Event::Mimetype(mimes) => {
|
||||||
if manager.update_mimetype(mimes, tasks) {
|
if manager.update_mimetype(mimes, tasks) {
|
||||||
emit!(Render);
|
emit!(Render);
|
||||||
emit!(Peek);
|
manager.peek(0);
|
||||||
}
|
|
||||||
}
|
|
||||||
Event::Peek(sequent) => {
|
|
||||||
if let Some((max, url)) = sequent {
|
|
||||||
manager.active_mut().update_peek(max, url);
|
|
||||||
self.cx.manager.peek(true);
|
|
||||||
} else {
|
|
||||||
self.cx.manager.peek(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Preview(lock) => {
|
Event::Preview(lock) => {
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ impl<'a> Executor<'a> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
on!(MANAGER, peek);
|
||||||
on!(MANAGER, hover);
|
on!(MANAGER, hover);
|
||||||
on!(MANAGER, refresh);
|
on!(MANAGER, refresh);
|
||||||
on!(MANAGER, quit, &self.cx.tasks);
|
on!(MANAGER, quit, &self.cx.tasks);
|
||||||
|
|
@ -139,11 +140,6 @@ impl<'a> Executor<'a> {
|
||||||
on!(TABS, swap);
|
on!(TABS, swap);
|
||||||
|
|
||||||
match exec.cmd.as_bytes() {
|
match exec.cmd.as_bytes() {
|
||||||
b"peek" => {
|
|
||||||
let step = exec.args.first().and_then(|s| s.parse().ok()).unwrap_or(0);
|
|
||||||
self.cx.manager.active_mut().preview.arrow(step);
|
|
||||||
self.cx.manager.peek(true)
|
|
||||||
}
|
|
||||||
// Tasks
|
// Tasks
|
||||||
b"tasks_show" => self.cx.tasks.toggle(()),
|
b"tasks_show" => self.cx.tasks.toggle(()),
|
||||||
// Help
|
// Help
|
||||||
|
|
|
||||||
|
|
@ -14,17 +14,11 @@ impl<'a> Preview<'a> {
|
||||||
|
|
||||||
impl<'a> Widget for Preview<'a> {
|
impl<'a> Widget for Preview<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let manager = &self.cx.manager;
|
let Some(ref lock) = self.cx.manager.active().preview.lock else {
|
||||||
let Some(hovered) = manager.hovered().map(|h| &h.url) else {
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let preview = &manager.active().preview;
|
match &lock.data {
|
||||||
if !preview.same_path(hovered) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
match &preview.lock.as_ref().unwrap().data {
|
|
||||||
PreviewData::Folder => {
|
PreviewData::Folder => {
|
||||||
Folder::preview(self.cx).render(area, buf);
|
Folder::preview(self.cx).render(area, buf);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue