From 3c69104d338da5a9ef6f50adeb169f6d247d754a Mon Sep 17 00:00:00 2001 From: sxyazi Date: Mon, 5 Aug 2024 13:18:10 +0800 Subject: [PATCH] nit --- yazi-fm/src/input/input.rs | 4 ++-- yazi-plugin/src/external/highlighter.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yazi-fm/src/input/input.rs b/yazi-fm/src/input/input.rs index 9500c221..c4b7cf8c 100644 --- a/yazi-fm/src/input/input.rs +++ b/yazi-fm/src/input/input.rs @@ -3,7 +3,7 @@ use std::ops::Range; use anyhow::{bail, Result}; use ratatui::{buffer::Buffer, layout::Rect, text::Line, widgets::{Block, BorderType, Paragraph, Widget}}; use syntect::easy::HighlightLines; -use yazi_config::THEME; +use yazi_config::{PREVIEW, THEME}; use yazi_core::input::InputMode; use yazi_plugin::external::Highlighter; @@ -25,7 +25,7 @@ impl<'a> Input<'a> { if let Some(syntax) = syntaxes.find_syntax_by_name("Bourne Again Shell (bash)") { let mut h = HighlightLines::new(syntax, theme); let regions = h.highlight_line(self.cx.input.value(), syntaxes)?; - return Ok(Highlighter::to_line_widget(regions)); + return Ok(Highlighter::to_line_widget(regions, &" ".repeat(PREVIEW.tab_size as usize))); } bail!("Failed to find syntax") } diff --git a/yazi-plugin/src/external/highlighter.rs b/yazi-plugin/src/external/highlighter.rs index 59b0d6cd..3def21ff 100644 --- a/yazi-plugin/src/external/highlighter.rs +++ b/yazi-plugin/src/external/highlighter.rs @@ -121,6 +121,7 @@ impl Highlighter { h.highlight_line(&line, syntaxes).map_err(|e| anyhow!(e))?; } + let indent = " ".repeat(PREVIEW.tab_size as usize); let mut lines = Vec::with_capacity(after.len()); for line in after { if ticket != INCR.load(Ordering::Relaxed) { @@ -128,7 +129,7 @@ impl Highlighter { } let regions = h.highlight_line(&line, syntaxes).map_err(|e| anyhow!(e))?; - lines.push(Self::to_line_widget(regions)); + lines.push(Self::to_line_widget(regions, &indent)); } Ok(Text::from(lines)) @@ -181,8 +182,7 @@ impl Highlighter { } } - pub fn to_line_widget(regions: Vec<(highlighting::Style, &str)>) -> Line<'static> { - let indent = " ".repeat(PREVIEW.tab_size as usize); + pub fn to_line_widget(regions: Vec<(highlighting::Style, &str)>, indent: &str) -> Line<'static> { let spans: Vec<_> = regions .into_iter() .map(|(style, s)| { @@ -198,7 +198,7 @@ impl Highlighter { } Span { - content: s.replace('\t', &indent).into(), + content: s.replace('\t', indent).into(), style: ratatui::style::Style { fg: Self::to_ansi_color(style.foreground), // bg: Self::to_ansi_color(style.background),