feat: show keywords when in search mode (#152)

This commit is contained in:
三咲雅 · Misaki Masa 2023-09-13 23:57:58 +08:00 committed by GitHub
parent e6fccf9d17
commit 4c98a351c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View File

@ -19,11 +19,11 @@ impl<'a> Widget for Layout<'a> {
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
.split(area);
let current = &self.cx.manager.current();
let location = if current.cwd.is_search() {
format!("{} (search)", readable_path(&current.cwd))
let cwd = &self.cx.manager.current().cwd;
let location = if cwd.is_search() {
format!("{} (search: {})", readable_path(cwd), cwd.frag().unwrap())
} else {
readable_path(&current.cwd)
readable_path(cwd)
};
Paragraph::new(location).style(Style::new().fg(Color::Cyan)).render(chunks[0], buf);

View File

@ -289,7 +289,7 @@ impl Tab {
handle.abort();
}
let cwd = self.current.cwd.to_search();
let mut cwd = self.current.cwd.clone();
let hidden = self.show_hidden;
self.search = Some(tokio::spawn(async move {
@ -297,6 +297,7 @@ impl Tab {
bail!("canceled")
};
cwd = cwd.into_search(subject.clone());
let rx = if grep {
external::rg(external::RgOpt { cwd: cwd.clone(), hidden, subject })
} else {

View File

@ -4,6 +4,7 @@ use std::{ffi::{OsStr, OsString}, fmt::{Debug, Formatter}, ops::{Deref, DerefMut
pub struct Url {
scheme: UrlScheme,
path: PathBuf,
frag: Option<String>,
}
#[derive(Clone, Copy, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
@ -114,11 +115,12 @@ impl Url {
pub fn is_search(&self) -> bool { self.scheme == UrlScheme::Search }
#[inline]
pub fn to_search(&self) -> Self { self.clone().into_search() }
pub fn to_search(&self, frag: String) -> Self { self.clone().into_search(frag) }
#[inline]
pub fn into_search(mut self) -> Self {
pub fn into_search(mut self, frag: String) -> Self {
self.scheme = UrlScheme::Search;
self.frag = Some(frag);
self
}
@ -137,4 +139,8 @@ impl Url {
// --- Path
#[inline]
pub fn set_path(&mut self, path: PathBuf) { self.path = path; }
// --- Frag
#[inline]
pub fn frag(&self) -> Option<&str> { self.frag.as_deref() }
}