Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
sxyazi committed Dec 2, 2024
1 parent 6724ad4 commit 76b73d2
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 80 deletions.
4 changes: 2 additions & 2 deletions yazi-core/src/manager/commands/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::{borrow::Cow, ffi::OsString};
use tracing::error;
use yazi_boot::ARGS;
use yazi_config::{OPEN, PLUGIN, popup::PickCfg};
use yazi_fs::{File, Folder};
use yazi_fs::File;
use yazi_macro::emit;
use yazi_plugin::isolate;
use yazi_proxy::{ManagerProxy, TasksProxy, options::OpenDoOpt};
use yazi_shared::{MIME_DIR, event::{CmdCow, EventQuit}, url::Url};

use crate::{manager::Manager, tasks::Tasks};
use crate::{manager::Manager, tab::Folder, tasks::Tasks};

#[derive(Clone, Copy)]
struct Opt {
Expand Down
4 changes: 2 additions & 2 deletions yazi-core/src/manager/commands/update_files.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::borrow::Cow;

use yazi_fs::{FilesOp, Folder};
use yazi_fs::FilesOp;
use yazi_macro::render;
use yazi_proxy::ManagerProxy;
use yazi_shared::event::CmdCow;

use crate::{manager::{LINKED, Manager}, tab::Tab, tasks::Tasks};
use crate::{manager::{LINKED, Manager}, tab::{Folder, Tab}, tasks::Tasks};

pub struct Opt {
op: FilesOp,
Expand Down
3 changes: 1 addition & 2 deletions yazi-core/src/manager/commands/update_mimes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{borrow::Cow, collections::HashMap};

use tracing::error;
use yazi_config::LAYOUT;
use yazi_macro::render;
use yazi_shared::{event::CmdCow, url::Url};

Expand Down Expand Up @@ -46,7 +45,7 @@ impl Manager {

let affected: Vec<_> = self
.current()
.paginate(self.current().page, LAYOUT.get().current.height as usize)
.paginate(self.current().page)
.iter()
.filter(|&f| updates.contains_key(&f.url))
.cloned()
Expand Down
6 changes: 1 addition & 5 deletions yazi-core/src/manager/commands/update_paged.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use yazi_config::LAYOUT;
use yazi_shared::{event::{CmdCow, Data}, url::Url};

use crate::{manager::Manager, tasks::Tasks};
Expand Down Expand Up @@ -29,10 +28,7 @@ impl Manager {
return;
}

let targets = self
.current()
.paginate(opt.page.unwrap_or(self.current().page), LAYOUT.get().current.height as usize);

let targets = self.current().paginate(opt.page.unwrap_or(self.current().page));
tasks.fetch_paged(targets, &self.mimetype);
tasks.preload_paged(targets, &self.mimetype);
}
Expand Down
4 changes: 2 additions & 2 deletions yazi-core/src/manager/manager.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use ratatui::layout::Rect;
use yazi_adapter::Dimension;
use yazi_config::popup::{Origin, Position};
use yazi_fs::{File, Folder};
use yazi_fs::File;
use yazi_shared::{Id, url::Url};

use super::{Mimetype, Tabs, Watcher, Yanked};
use crate::tab::Tab;
use crate::tab::{Folder, Tab};

pub struct Manager {
pub tabs: Tabs,
Expand Down
3 changes: 2 additions & 1 deletion yazi-core/src/manager/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use tokio::{fs, pin, sync::{mpsc::{self, UnboundedReceiver}, watch}};
use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream};
use tracing::error;
use yazi_config::PLUGIN;
use yazi_fs::{Cha, File, Files, FilesOp, Folder, realname_unchecked};
use yazi_fs::{Cha, File, Files, FilesOp, realname_unchecked};
use yazi_plugin::isolate;
use yazi_proxy::WATCHER;
use yazi_shared::{RoCell, event::CmdCow, url::Url};

use super::Linked;
use crate::tab::Folder;

pub(crate) static WATCHED: RoCell<RwLock<HashSet<Url>>> = RoCell::new();
pub static LINKED: RoCell<RwLock<Linked>> = RoCell::new();
Expand Down
95 changes: 46 additions & 49 deletions yazi-fs/src/folder.rs → yazi-core/src/tab/folder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::mem;

use yazi_config::{LAYOUT, MANAGER};
use yazi_fs::{Cha, File, Files, FilesOp, FolderStage, Step};
use yazi_proxy::ManagerProxy;
use yazi_shared::url::{Url, Urn};

use super::FolderStage;
use crate::{Cha, File, Files, FilesOp, Step};

#[derive(Default)]
pub struct Folder {
pub url: Url,
Expand Down Expand Up @@ -92,78 +92,75 @@ impl Folder {
}

pub fn sync_page(&mut self, force: bool) {
todo!();
// let limit = LAYOUT.get().current.height as usize;
// if limit == 0 {
// return;
// }

// let new = self.cursor / limit;
// if mem::replace(&mut self.page, new) != new || force {
// ManagerProxy::update_paged_by(new, &self.url);
// }
let limit = LAYOUT.get().current.height as usize;
if limit == 0 {
return;
}

let new = self.cursor / limit;
if mem::replace(&mut self.page, new) != new || force {
ManagerProxy::update_paged_by(new, &self.url);
}
}

fn next(&mut self, step: Step) -> bool {
todo!();
// let old = (self.cursor, self.offset);
// let len = self.files.len();
let old = (self.cursor, self.offset);
let len = self.files.len();

// let limit = LAYOUT.get().current.height as usize;
// let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);
let limit = LAYOUT.get().current.height as usize;
let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);

// self.cursor = step.add(self.cursor, limit).min(len.saturating_sub(1));
// self.offset = if self.cursor < (self.offset +
// limit).min(len).saturating_sub(scrolloff) { self.offset.min(len.
// saturating_sub(1)) } else {
// len.saturating_sub(limit).min(self.offset + self.cursor - old.0)
// };
self.cursor = step.add(self.cursor, limit).min(len.saturating_sub(1));
self.offset = if self.cursor < (self.offset + limit).min(len).saturating_sub(scrolloff) {
self.offset.min(len.saturating_sub(1))
} else {
len.saturating_sub(limit).min(self.offset + self.cursor - old.0)
};

// old != (self.cursor, self.offset)
old != (self.cursor, self.offset)
}

fn prev(&mut self, step: Step) -> bool {
todo!();
// let old = (self.cursor, self.offset);
// let max = self.files.len().saturating_sub(1);
let old = (self.cursor, self.offset);
let max = self.files.len().saturating_sub(1);

// let limit = LAYOUT.get().current.height as usize;
// let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);
let limit = LAYOUT.get().current.height as usize;
let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);

// self.cursor = step.add(self.cursor, limit).min(max);
// self.offset = if self.cursor < self.offset + scrolloff {
// self.offset.saturating_sub(old.0 - self.cursor)
// } else {
// self.offset.min(max)
// };
self.cursor = step.add(self.cursor, limit).min(max);
self.offset = if self.cursor < self.offset + scrolloff {
self.offset.saturating_sub(old.0 - self.cursor)
} else {
self.offset.min(max)
};

// old != (self.cursor, self.offset)
old != (self.cursor, self.offset)
}

fn squeeze_offset(&mut self) -> bool {
todo!();
// let old = self.offset;
// let len = self.files.len();
let old = self.offset;
let len = self.files.len();

// let limit = LAYOUT.get().current.height as usize;
// let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);
let limit = LAYOUT.get().current.height as usize;
let scrolloff = (limit / 2).min(MANAGER.scrolloff as usize);

// self.offset = if self.cursor < (self.offset +
// limit).min(len).saturating_sub(scrolloff) { len.saturating_sub(limit).
// min(self.offset) } else {
// len.saturating_sub(limit).min(self.cursor.saturating_sub(limit) + 1 +
// scrolloff) };
self.offset = if self.cursor < (self.offset + limit).min(len).saturating_sub(scrolloff) {
len.saturating_sub(limit).min(self.offset)
} else {
len.saturating_sub(limit).min(self.cursor.saturating_sub(limit) + 1 + scrolloff)
};

// old != self.offset
old != self.offset
}
}

impl Folder {
#[inline]
pub fn hovered(&self) -> Option<&File> { self.files.get(self.cursor) }

pub fn paginate(&self, page: usize, limit: usize) -> &[File] {
pub fn paginate(&self, page: usize) -> &[File] {
let len = self.files.len();
let limit = LAYOUT.get().current.height as usize;

let start = (page.saturating_sub(1) * limit).min(len.saturating_sub(1));
let end = ((page + 2) * limit).min(len);
Expand Down
3 changes: 2 additions & 1 deletion yazi-core/src/tab/history.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{collections::HashMap, ops::{Deref, DerefMut}};

use yazi_fs::Folder;
use yazi_shared::url::Url;

use super::Folder;

#[derive(Default)]
pub struct History(HashMap<Url, Folder>);

Expand Down
2 changes: 1 addition & 1 deletion yazi-core/src/tab/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
yazi_macro::mod_pub!(commands);

yazi_macro::mod_flat!(backstack preference finder history mode preview selected tab);
yazi_macro::mod_flat!(backstack finder folder history mode preference preview selected tab);
4 changes: 2 additions & 2 deletions yazi-core/src/tab/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use ratatui::layout::Rect;
use tokio::task::JoinHandle;
use yazi_adapter::Dimension;
use yazi_config::{LAYOUT, popup::{Origin, Position}};
use yazi_fs::{File, Folder, FolderStage};
use yazi_fs::{File, FolderStage};
use yazi_macro::render;
use yazi_shared::{Id, Ids, url::Url};

use super::{Backstack, Finder, History, Mode, Preference, Preview};
use super::{Backstack, Finder, Folder, History, Mode, Preference, Preview};
use crate::{spot::Spot, tab::Selected};

pub struct Tab {
Expand Down
3 changes: 1 addition & 2 deletions yazi-fm/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use ratatui::layout::Rect;
use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, pick::Pick, tab::Tab, tasks::Tasks, which::Which};
use yazi_fs::Folder;
use yazi_core::{completion::Completion, confirm::Confirm, help::Help, input::Input, manager::Manager, notify::Notify, pick::Pick, tab::{Folder, Tab}, tasks::Tasks, which::Which};

pub struct Ctx {
pub manager: Manager,
Expand Down
6 changes: 3 additions & 3 deletions yazi-fm/src/lives/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::Ctx;

pub(super) struct File {
idx: usize,
folder: *const yazi_fs::Folder,
folder: *const yazi_core::tab::Folder,
tab: *const yazi_core::tab::Tab,
}

Expand All @@ -28,14 +28,14 @@ impl File {
#[inline]
pub(super) fn make(
idx: usize,
folder: &yazi_fs::Folder,
folder: &yazi_core::tab::Folder,
tab: &yazi_core::tab::Tab,
) -> mlua::Result<AnyUserData> {
Lives::scoped_userdata(Self { idx, folder, tab })
}

#[inline]
fn folder(&self) -> &yazi_fs::Folder { unsafe { &*self.folder } }
fn folder(&self) -> &yazi_core::tab::Folder { unsafe { &*self.folder } }

#[inline]
fn tab(&self) -> &yazi_core::tab::Tab { unsafe { &*self.tab } }
Expand Down
6 changes: 3 additions & 3 deletions yazi-fm/src/lives/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{File, Filter, Lives};

pub(super) struct Files {
window: Range<usize>,
folder: *const yazi_fs::Folder,
folder: *const yazi_core::tab::Folder,
tab: *const yazi_core::tab::Tab,
}

Expand All @@ -20,14 +20,14 @@ impl Files {
#[inline]
pub(super) fn make(
window: Range<usize>,
folder: &yazi_fs::Folder,
folder: &yazi_core::tab::Folder,
tab: &yazi_core::tab::Tab,
) -> mlua::Result<AnyUserData> {
Lives::scoped_userdata(Self { window, folder, tab })
}

#[inline]
fn folder(&self) -> &yazi_fs::Folder { unsafe { &*self.folder } }
fn folder(&self) -> &yazi_core::tab::Folder { unsafe { &*self.folder } }

#[inline]
fn tab(&self) -> &yazi_core::tab::Tab { unsafe { &*self.tab } }
Expand Down
6 changes: 3 additions & 3 deletions yazi-fm/src/lives/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use super::{File, Files, Lives};

pub(super) struct Folder {
window: Range<usize>,
inner: *const yazi_fs::Folder,
inner: *const yazi_core::tab::Folder,
tab: *const yazi_core::tab::Tab,
}

impl Deref for Folder {
type Target = yazi_fs::Folder;
type Target = yazi_core::tab::Folder;

fn deref(&self) -> &Self::Target { unsafe { &*self.inner } }
}
Expand All @@ -22,7 +22,7 @@ impl Folder {
#[inline]
pub(super) fn make(
window: Option<Range<usize>>,
inner: &yazi_fs::Folder,
inner: &yazi_core::tab::Folder,
tab: &yazi_core::tab::Tab,
) -> mlua::Result<AnyUserData> {
let window = match window {
Expand Down
4 changes: 2 additions & 2 deletions yazi-fs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#![allow(clippy::if_same_then_else)]
#![allow(clippy::if_same_then_else, clippy::option_map_unit_fn)]

yazi_macro::mod_flat!(cha file files filter fns folder op path sorter sorting stage step xdg);
yazi_macro::mod_flat!(cha file files filter fns op path sorter sorting stage step xdg);

0 comments on commit 76b73d2

Please sign in to comment.