mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: overlong single-line text containing escape sequences was not being properly escaped (#1497)
This commit is contained in:
parent
4112bf451f
commit
374c6a8891
1 changed files with 9 additions and 16 deletions
25
yazi-plugin/src/external/highlighter.rs
vendored
25
yazi-plugin/src/external/highlighter.rs
vendored
|
|
@ -60,9 +60,9 @@ impl Highlighter {
|
||||||
let mut reader = BufReader::new(File::open(&self.path).await?);
|
let mut reader = BufReader::new(File::open(&self.path).await?);
|
||||||
|
|
||||||
let syntax = Self::find_syntax(&self.path).await;
|
let syntax = Self::find_syntax(&self.path).await;
|
||||||
let mut plain = syntax.is_err() as u8;
|
let mut plain = syntax.is_err();
|
||||||
|
|
||||||
let mut before = Vec::with_capacity(if plain == 0 { skip } else { 0 });
|
let mut before = Vec::with_capacity(if plain { 0 } else { skip });
|
||||||
let mut after = Vec::with_capacity(limit);
|
let mut after = Vec::with_capacity(limit);
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
@ -73,11 +73,8 @@ impl Highlighter {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if plain == 0 && buf.len() > 5000 {
|
if !plain && (buf.len() > 5000 || buf.contains(&0x1b)) {
|
||||||
plain = 1;
|
plain = true;
|
||||||
drop(mem::take(&mut before));
|
|
||||||
} else if plain == 0 && buf.contains(&0x1b) {
|
|
||||||
plain = 2;
|
|
||||||
drop(mem::take(&mut before));
|
drop(mem::take(&mut before));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +86,7 @@ impl Highlighter {
|
||||||
|
|
||||||
if i > skip {
|
if i > skip {
|
||||||
after.push(String::from_utf8_lossy(&buf).into_owned());
|
after.push(String::from_utf8_lossy(&buf).into_owned());
|
||||||
} else if plain == 0 {
|
} else if !plain {
|
||||||
before.push(String::from_utf8_lossy(&buf).into_owned());
|
before.push(String::from_utf8_lossy(&buf).into_owned());
|
||||||
}
|
}
|
||||||
buf.clear();
|
buf.clear();
|
||||||
|
|
@ -99,15 +96,11 @@ impl Highlighter {
|
||||||
return Err(PeekError::Exceed(i.saturating_sub(limit)));
|
return Err(PeekError::Exceed(i.saturating_sub(limit)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if plain == 0 {
|
Ok(if plain {
|
||||||
Self::highlight_with(before, after, syntax.unwrap()).await
|
Text::from(after.join("").replace('\x1b', "^[").replace('\t', &PREVIEW.indent()))
|
||||||
} else if plain == 1 {
|
|
||||||
Ok(Text::from(after.join("").replace('\t', &PREVIEW.indent())))
|
|
||||||
} else if plain == 2 {
|
|
||||||
Ok(Text::from(after.join("").replace('\x1b', "^[").replace('\t', &PREVIEW.indent())))
|
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
Self::highlight_with(before, after, syntax.unwrap()).await?
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn highlight_with(
|
async fn highlight_with(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue