diff --git a/yazi-binding/src/elements/highlight.rs b/yazi-binding/src/elements/highlight.rs index e94dc8da..57d454d1 100644 --- a/yazi-binding/src/elements/highlight.rs +++ b/yazi-binding/src/elements/highlight.rs @@ -1,19 +1,19 @@ -use mlua::{ - ExternalError, FromLua, IntoLua, Lua, Result as LuaResult, Table, UserData, UserDataMethods, - Value, -}; +use mlua::{ExternalError, FromLua, IntoLua, Lua, Result as LuaResult, Value}; const EXPECTED: &str = "expected a table containing a line and a length"; #[derive(Clone, Debug)] pub struct HighlightPosition { pub line: usize, + pub col: usize, pub length: usize, } impl HighlightPosition { pub fn compose(lua: &Lua) -> LuaResult { - let new = lua.create_function(|_, (line, length): (usize, usize)| Ok(Self { line, length }))?; + let new = lua.create_function(|_, (line, col, length): (usize, usize, usize)| { + Ok(Self { line, col, length }) + })?; let tbl = lua.create_table_from([("new", new)])?; tbl.into_lua(lua) @@ -23,7 +23,11 @@ impl HighlightPosition { impl FromLua for HighlightPosition { fn from_lua(value: Value, _: &Lua) -> mlua::Result { match value { - Value::Table(tbl) => Ok(Self { line: tbl.raw_get("line")?, length: tbl.raw_get("length")? }), + Value::Table(tbl) => Ok(Self { + line: tbl.raw_get("line")?, + col: tbl.raw_get("col")?, + length: tbl.raw_get("length")?, + }), _ => Err(EXPECTED.into_lua_err()), } } @@ -33,6 +37,7 @@ impl IntoLua for HighlightPosition { fn into_lua(self, lua: &Lua) -> LuaResult { let tbl = lua.create_table()?; tbl.set("line", self.line)?; + tbl.set("col", self.col)?; tbl.set("length", self.length)?; Ok(Value::Table(tbl)) } diff --git a/yazi-core/src/highlighter.rs b/yazi-core/src/highlighter.rs index 046d3667..99f2bd83 100644 --- a/yazi-core/src/highlighter.rs +++ b/yazi-core/src/highlighter.rs @@ -54,6 +54,8 @@ impl Highlighter { let path = path.into(); let (theme, syntaxes) = CACHE.get_or_init(Self::load); + // tracing::debug!("{:?}", theme); + Ok(Self { reader: BufReader::new(std::fs::File::open(&path)?), path, @@ -82,6 +84,7 @@ impl Highlighter { let mut lines = Vec::with_capacity(self.size.height as usize); let mut inspected = 0u16; while self.reader.read_until(b'\n', &mut buf).is_ok_and(|n| n > 0) { + // tracing::debug!("{:?}", buf); if Self::is_binary(&buf, &mut inspected) { Err(anyhow!("Binary file"))?; } diff --git a/yazi-plugin/src/external/rg.rs b/yazi-plugin/src/external/rg.rs index 82f9cd22..cf9ef811 100644 --- a/yazi-plugin/src/external/rg.rs +++ b/yazi-plugin/src/external/rg.rs @@ -19,8 +19,7 @@ pub struct RgOpt { pub fn rg(opt: RgOpt) -> Result> { let mut child = Command::new("rg") - .args(["--color=never", "--no-heading", "--column", "--smart-case"]) - // .args(["--color=never", "--files-with-matches", "--smart-case"]) + .args(["--color=never", "--no-heading", "--column", "--smart-case"]) .arg(if opt.hidden { "--hidden" } else { "--no-hidden" }) .args(opt.args) .arg(opt.subject) diff --git a/yazi-plugin/src/utils/preview.rs b/yazi-plugin/src/utils/preview.rs index 2a3fc8fe..4cf50b2c 100644 --- a/yazi-plugin/src/utils/preview.rs +++ b/yazi-plugin/src/utils/preview.rs @@ -18,18 +18,22 @@ impl Utils { pub(super) fn preview_code(lua: &Lua) -> mlua::Result { lua.create_async_function(|lua, t: Table| async move { let area: Area = t.raw_get("area")?; - // let position: Option = t.raw_get("position").ok(); + let position: Option = t.raw_get("position").ok(); + + tracing::debug!("{:?}", position); let mut lock = PreviewLock::try_from(t)?; let path = lock.url.as_url().unified_path(); - // let skip = position.map(|p| p.line).unwrap_or(lock.skip); - let size = area.size(); + let search_subject = lock.url.as_url().scheme().domain(); - // tracing::debug!("skip size: {size}"); + tracing::debug!("search subject{:?}", search_subject); - let inner = match Highlighter::oneshot(path, lock.skip, size).await { - Ok(text) => text, + let inner = match Highlighter::oneshot(path, lock.skip, area.size()).await { + Ok(text) => { + // tracing::debug!("{:?}", text); + text + } Err(e @ PeekError::Exceeded(max)) => return (e, max).into_lua_multi(&lua), Err(e) => { return e.into_lua_multi(&lua);