This commit is contained in:
sxyazi 2023-08-25 13:15:26 +08:00
parent 395c04a852
commit c4f76bd778
No known key found for this signature in database
2 changed files with 10 additions and 6 deletions

View file

@ -19,6 +19,9 @@ keymap = [
{ on = [ "H" ], exec = "back" },
{ on = [ "L" ], exec = "forward" },
{ on = [ "<C-k>" ], exec = "peek -5" },
{ on = [ "<C-j>" ], exec = "peek 5" },
{ on = [ "<Up>" ], exec = "arrow -1" },
{ on = [ "<Down>" ], exec = "arrow 1" },
{ on = [ "<Left>" ], exec = "leave" },

View file

@ -106,27 +106,28 @@ impl Provider {
let mut buf = String::new();
let mut i = 0;
let mut limit = MANAGER.layout.preview_height();
while limit > 0 && h.reader.read_line(&mut line)? > 0 {
let limit = MANAGER.layout.preview_height();
while h.reader.read_line(&mut line)? > 0 {
if tick != INCR.load(Ordering::Relaxed) {
return Err("Preview cancelled".into());
}
i += 1;
if i <= skip {
if i > skip + limit {
break;
} else if i <= skip {
line.clear();
continue;
}
limit -= 1;
line = line.replace('\t', &spaces);
let regions = h.highlight_lines.highlight_line(&line, syntaxes).map_err(|e| anyhow!(e))?;
buf.push_str(&as_24_bit_terminal_escaped(&regions, false));
line.clear();
}
if buf.is_empty() {
return Err(PagedError::Exceed(i));
if skip > 0 && i < skip + limit {
return Err(PagedError::Exceed(i.saturating_sub(limit)));
}
buf.push_str("\x1b[0m");