Skip to content

Commit c7d9265

Browse files
authored
fix: missing a repeek on unyanking files in the hovered folder (#1988)
1 parent 2771aef commit c7d9265

File tree

28 files changed

+71
-64
lines changed

28 files changed

+71
-64
lines changed

.github/DISCUSSION_TEMPLATE/1-q-a.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ body:
4545
Add any other context about the problem here. You can attach screenshots by clicking
4646
this area to highlight it and then drag the files in.
4747
- type: checkboxes
48-
id: validations
48+
id: checklist
4949
attributes:
50-
label: Validations
50+
label: Checklist
5151
description: Before submitting the post, please make sure you have completed the following
5252
options:
5353
- label: I have searched the existing discussions/issues

.github/ISSUE_TEMPLATE/bug.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ body:
5858
Add any other context about the problem here. You can attach screenshots by clicking
5959
this area to highlight it and then drag the files in.
6060
- type: checkboxes
61-
id: validations
61+
id: checklist
6262
attributes:
63-
label: Validations
63+
label: Checklist
6464
description: Before submitting the issue, please make sure you have completed the following
6565
options:
6666
- label: I tried the [latest nightly build](https://yazi-rs.github.io/docs/installation#official-binaries), and the issue is still reproducible

.github/ISSUE_TEMPLATE/feature.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ body:
3838
label: Additional context
3939
description: Add any other context or screenshots about the feature request here.
4040
- type: checkboxes
41-
id: validations
41+
id: checklist
4242
attributes:
43-
label: Validations
43+
label: Checklist
4444
description: Before submitting the issue, please make sure you have completed the following
4545
options:
4646
- label: I have searched the existing issues/discussions

yazi-core/src/manager/commands/open.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ impl Manager {
4343
let (mut done, mut todo) = (Vec::with_capacity(selected.len()), vec![]);
4444
for u in selected {
4545
if self.mimetype.contains(u) {
46-
done.push((u.clone(), String::new()));
46+
done.push((u.clone(), Cow::Borrowed("")));
4747
} else if self.guess_folder(u) {
48-
done.push((u.clone(), MIME_DIR.to_owned()));
48+
done.push((u.clone(), Cow::Borrowed(MIME_DIR)));
4949
} else {
5050
todo.push(u.clone());
5151
}
@@ -64,7 +64,7 @@ impl Manager {
6464
}
6565
}
6666

67-
done.extend(files.iter().map(|f| (f.url_owned(), String::new())));
67+
done.extend(files.iter().map(|f| (f.url_owned(), Cow::Borrowed(""))));
6868
for (fetcher, files) in PLUGIN.mime_fetchers(files) {
6969
if let Err(e) = isolate::fetch(CmdCow::from(&fetcher.run), files).await {
7070
error!("Fetch mime failed on opening: {e}");
@@ -81,7 +81,7 @@ impl Manager {
8181
.targets
8282
.into_iter()
8383
.filter_map(|(u, m)| {
84-
Some(m).filter(|m| !m.is_empty()).or_else(|| self.mimetype.get_owned(&u)).map(|m| (u, m))
84+
Some(m).filter(|m| !m.is_empty()).or_else(|| self.mimetype.by_url_owned(&u)).map(|m| (u, m))
8585
})
8686
.collect();
8787

yazi-core/src/manager/commands/peek.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl Manager {
3535
return self.active_mut().preview.reset_image();
3636
}
3737

38-
let mime = self.mimetype.get_owned(&hovered.url).unwrap_or_default();
38+
let mime = self.mimetype.by_file_owned(&hovered).unwrap_or_default();
3939
let folder = self.active().hovered_folder().map(|f| (f.offset, f.cha));
4040

4141
if !self.active().preview.same_url(&hovered.url) {
@@ -61,7 +61,7 @@ impl Manager {
6161
if hovered.is_dir() {
6262
self.active_mut().preview.go_folder(hovered, folder.map(|(_, cha)| cha), opt.force);
6363
} else {
64-
self.active_mut().preview.go(hovered, mime.into(), opt.force);
64+
self.active_mut().preview.go(hovered, mime, opt.force);
6565
}
6666
}
6767
}

yazi-core/src/manager/commands/seek.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use yazi_config::PLUGIN;
22
use yazi_plugin::isolate;
3-
use yazi_shared::{MIME_DIR, event::{CmdCow, Data}};
3+
use yazi_shared::event::{CmdCow, Data};
44

55
use crate::manager::Manager;
66

@@ -20,11 +20,7 @@ impl Manager {
2020
return self.active_mut().preview.reset();
2121
};
2222

23-
let mime = if hovered.is_dir() {
24-
MIME_DIR
25-
} else if let Some(s) = self.mimetype.get(&hovered.url) {
26-
s
27-
} else {
23+
let Some(mime) = self.mimetype.by_file(hovered) else {
2824
return self.active_mut().preview.reset();
2925
};
3026

yazi-core/src/manager/commands/spot.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::borrow::Cow;
2-
3-
use yazi_shared::{MIME_DIR, event::{CmdCow, Data}};
1+
use yazi_shared::event::{CmdCow, Data};
42

53
use crate::manager::Manager;
64

@@ -19,12 +17,7 @@ impl Manager {
1917
return;
2018
};
2119

22-
let mime = if hovered.is_dir() {
23-
Cow::Borrowed(MIME_DIR)
24-
} else {
25-
Cow::Owned(self.mimetype.get_owned(&hovered.url).unwrap_or_default())
26-
};
27-
20+
let mime = self.mimetype.by_file_owned(&hovered).unwrap_or_default();
2821
// if !self.active().spot.same_file(&hovered, &mime) {
2922
// self.active_mut().spot.reset();
3023
// }

yazi-core/src/manager/commands/unyank.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ impl From<()> for Opt {
1515
impl Manager {
1616
#[yazi_codegen::command]
1717
pub fn unyank(&mut self, _: Opt) {
18+
let repeek = self.hovered().is_some_and(|f| f.is_dir() && self.yanked.contains_in(&f.url));
1819
self.yanked.clear();
20+
1921
render!(self.yanked.catchup_revision(false));
22+
if repeek {
23+
self.peek(true);
24+
}
2025
}
2126
}

yazi-core/src/manager/commands/update_mimes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl Manager {
2929
.updates
3030
.into_iter()
3131
.map(|(url, mime)| (Url::from(url.into_owned()), mime))
32-
.filter(|(url, mime)| self.mimetype.get(url) != Some(mime))
32+
.filter(|(url, mime)| self.mimetype.by_url(url) != Some(mime))
3333
.fold(HashMap::new(), |mut map, (u, m)| {
3434
for u in linked.from_file(&u) {
3535
map.insert(u, m.clone());

yazi-core/src/manager/mimetype.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1-
use std::{collections::HashMap, path::PathBuf};
1+
use std::{borrow::Cow, collections::HashMap, path::PathBuf};
22

3-
use yazi_shared::url::{Url, UrlScheme};
3+
use yazi_fs::File;
4+
use yazi_shared::{MIME_DIR, url::{Url, UrlScheme}};
45

56
#[derive(Default)]
67
pub struct Mimetype(HashMap<PathBuf, String>);
78

89
impl Mimetype {
910
#[inline]
10-
pub fn get(&self, url: &Url) -> Option<&str> {
11-
let s = match url.scheme() {
11+
pub fn by_url(&self, url: &Url) -> Option<&str> {
12+
match url.scheme() {
1213
UrlScheme::Regular => self.0.get(url.as_path()),
1314
UrlScheme::Search => None,
1415
UrlScheme::SearchItem => self.0.get(url.as_path()),
1516
UrlScheme::Archive => None,
16-
};
17-
s.map(|s| s.as_str())
17+
}
18+
.map(|s| s.as_str())
19+
}
20+
21+
#[inline]
22+
pub fn by_url_owned(&self, url: &Url) -> Option<Cow<'static, str>> {
23+
self.by_url(url).map(|s| Cow::Owned(s.to_owned()))
1824
}
1925

2026
#[inline]
21-
pub fn get_owned(&self, url: &Url) -> Option<String> { self.get(url).map(|s| s.to_owned()) }
27+
pub fn by_file(&self, file: &File) -> Option<&str> {
28+
if file.is_dir() { Some(MIME_DIR) } else { self.by_url(&file.url) }
29+
}
30+
31+
#[inline]
32+
pub fn by_file_owned(&self, file: &File) -> Option<Cow<'static, str>> {
33+
if file.is_dir() { Some(Cow::Borrowed(MIME_DIR)) } else { self.by_url_owned(&file.url) }
34+
}
2235

2336
#[inline]
2437
pub fn contains(&self, url: &Url) -> bool {

0 commit comments

Comments
 (0)