mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
fix: shift of auto-wrap points in both code and JSON previewers (#3739)
This commit is contained in:
parent
9648d8a43b
commit
be91b4111c
15 changed files with 163 additions and 85 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use std::{borrow::Cow, path::PathBuf};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{Context, Result, bail};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -9,9 +9,6 @@ use yazi_shared::{SStr, timestamp_us};
|
|||
use super::PreviewWrap;
|
||||
use crate::normalize_path;
|
||||
|
||||
#[rustfmt::skip]
|
||||
const TABS: &[&str] = &["", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "];
|
||||
|
||||
#[derive(Debug, Deserialize, DeserializeOver2, Serialize)]
|
||||
pub struct Preview {
|
||||
pub wrap: PreviewWrap,
|
||||
|
|
@ -34,10 +31,15 @@ impl Preview {
|
|||
self.cache_dir.join(format!("{prefix}-{}", timestamp_us()))
|
||||
}
|
||||
|
||||
pub fn indent(&self) -> SStr { Self::indent_with(self.tab_size as usize) }
|
||||
pub fn indent(&self) -> SStr {
|
||||
#[rustfmt::skip]
|
||||
const TABS: &[&str] = &["", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "];
|
||||
|
||||
pub fn indent_with(n: usize) -> SStr {
|
||||
if let Some(s) = TABS.get(n) { Cow::Borrowed(s) } else { Cow::Owned(" ".repeat(n)) }
|
||||
if let Some(&s) = TABS.get(self.tab_size as usize) {
|
||||
s.into()
|
||||
} else {
|
||||
" ".repeat(self.tab_size as usize).into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,3 +6,12 @@ pub enum PreviewWrap {
|
|||
No,
|
||||
Yes,
|
||||
}
|
||||
|
||||
impl From<PreviewWrap> for Option<ratatui::widgets::Wrap> {
|
||||
fn from(wrap: PreviewWrap) -> Self {
|
||||
match wrap {
|
||||
PreviewWrap::No => None,
|
||||
PreviewWrap::Yes => Some(ratatui::widgets::Wrap { trim: false }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue