Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 1 addition & 20 deletions helix-core/src/doc_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ pub struct TextFormat {
pub tab_width: u16,
pub max_wrap: u16,
pub max_indent_retain: u16,
pub wrap_indicator: Box<str>,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we would want to keep this field and just set it to "" for now? I'm not sure what we would use it for in the future but the document formatter is meant to be flexible enough to be used for reflowing and other uses than rendering

pub wrap_indicator_highlight: Option<Highlight>,
pub viewport_width: u16,
pub soft_wrap_at_text_width: bool,
Expand All @@ -161,7 +160,6 @@ impl Default for TextFormat {
tab_width: 4,
max_wrap: 3,
max_indent_retain: 4,
wrap_indicator: Box::from(" "),
viewport_width: 17,
wrap_indicator_highlight: None,
soft_wrap_at_text_width: false,
Expand Down Expand Up @@ -310,25 +308,8 @@ impl<'t> DocumentFormatter<'t> {
.virtual_lines_at(self.char_pos, self.visual_pos, self.line_pos);
self.visual_pos.col = indent_carry_over as usize;
self.visual_pos.row += 1 + virtual_lines;
let mut i = 0;
let mut word_width = 0;
let wrap_indicator = UnicodeSegmentation::graphemes(&*self.text_fmt.wrap_indicator, true)
.map(|g| {
i += 1;
let grapheme = GraphemeWithSource::new(
g.into(),
self.visual_pos.col + word_width,
self.text_fmt.tab_width,
GraphemeSource::VirtualText {
highlight: self.text_fmt.wrap_indicator_highlight,
},
);
word_width += grapheme.width();
grapheme
});
self.word_buf.splice(0..0, wrap_indicator);

for grapheme in &mut self.word_buf[i..] {
for grapheme in &mut self.word_buf {
let visual_x = self.visual_pos.col + word_width;
grapheme
.grapheme
Expand Down
29 changes: 14 additions & 15 deletions helix-core/src/doc_formatter/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ impl TextFormat {
tab_width: 2,
max_wrap: 3,
max_indent_retain: 4,
wrap_indicator: ".".into(),
wrap_indicator_highlight: None,
// use a prime number to allow lining up too often with repeat
viewport_width: 17,
Expand Down Expand Up @@ -59,11 +58,11 @@ fn softwrap_text(text: &str) -> String {
fn basic_softwrap() {
assert_eq!(
softwrap_text(&"foo ".repeat(10)),
"foo foo foo foo \n.foo foo foo foo \n.foo foo "
"foo foo foo foo \nfoo foo foo foo \nfoo foo "
);
assert_eq!(
softwrap_text(&"fooo ".repeat(10)),
"fooo fooo fooo \n.fooo fooo fooo \n.fooo fooo fooo \n.fooo "
"fooo fooo fooo \nfooo fooo fooo \nfooo fooo fooo \nfooo "
);

// check that we don't wrap unnecessarily
Expand All @@ -74,39 +73,39 @@ fn basic_softwrap() {
fn softwrap_indentation() {
assert_eq!(
softwrap_text("\t\tfoo1 foo2 foo3 foo4 foo5 foo6\n"),
" foo1 foo2 \n.....foo3 foo4 \n.....foo5 foo6 \n "
" foo1 foo2 \n....foo3 foo4 \n....foo5 foo6 \n "
);
assert_eq!(
softwrap_text("\t\t\tfoo1 foo2 foo3 foo4 foo5 foo6\n"),
" foo1 foo2 \n.foo3 foo4 foo5 \n.foo6 \n "
" foo1 foo2 \nfoo3 foo4 foo5 \nfoo6 \n "
);
}

#[test]
fn long_word_softwrap() {
assert_eq!(
softwrap_text("\t\txxxx1xxxx2xxxx3xxxx4xxxx5xxxx6xxxx7xxxx8xxxx9xxx\n"),
" xxxx1xxxx2xxx\n.....x3xxxx4xxxx5\n.....xxxx6xxxx7xx\n.....xx8xxxx9xxx \n "
softwrap_text("\t\txxxx1xxxx2xxxx3xxxx4xxxxx5xxxx6xxxx7xxx8xxxx9xxx\n"),
" xxxx1xxxx2xxx\n....x3xxxx4xxxxx5\n....xxxx6xxxx7xxx\n....8xxxx9xxx \n "
);
assert_eq!(
softwrap_text("xxxxxxxx1xxxx2xxx\n"),
"xxxxxxxx1xxxx2xxx\n. \n "
"xxxxxxxx1xxxx2xxx\n \n "
);
assert_eq!(
softwrap_text("\t\txxxx1xxxx 2xxxx3xxxx4xxxx5xxxx6xxxx7xxxx8xxxx9xxx\n"),
" xxxx1xxxx \n.....2xxxx3xxxx4x\n.....xxx5xxxx6xxx\n.....x7xxxx8xxxx9\n.....xxx \n "
softwrap_text("\t\txxxx1xxxx 2xxxx3xxxx4xxxx5xxxx6xxxx7xxxx8xxxxxxx9xxx\n"),
" xxxx1xxxx \n....2xxxx3xxxx4xx\n....xx5xxxx6xxxx7\n....xxxx8xxxxxxx9\n....xxx \n "
);
assert_eq!(
softwrap_text("\t\txxxx1xxx 2xxxx3xxxx4xxxx5xxxx6xxxx7xxxx8xxxx9xxx\n"),
" xxxx1xxx 2xxx\n.....x3xxxx4xxxx5\n.....xxxx6xxxx7xx\n.....xx8xxxx9xxx \n "
softwrap_text("\t\txxxx1xxx 2xxxx3xxxx4xxxxx5xxxx6xxxx7xxxxx8xxxx9xx\n"),
" xxxx1xxx 2xxx\n....x3xxxx4xxxxx5\n....xxxx6xxxx7xxx\n....xx8xxxx9xx \n "
);
}

#[test]
fn softwrap_multichar_grapheme() {
assert_eq!(
softwrap_text("xxxx xxxx xxx a\u{0301}bc\n"),
"xxxx xxxx xxx \n.ábc \n "
"xxxx xxxx xxx \nábc \n "
)
}

Expand Down Expand Up @@ -158,7 +157,7 @@ fn overlay() {
Overlay::new(16, "X"),
]
),
"fo f o foo \n.foo Xoo foo foo \n.foo foo foo "
"fo f o foo \nfoo Xoo foo foo \nfoo foo foo "
);
}

Expand All @@ -184,7 +183,7 @@ fn annotation() {
true,
&[InlineAnnotation::new(0, "foo ")]
),
"foo foo foo foo \n.foo foo foo foo \n.foo foo foo "
"foo foo foo foo \nfoo foo foo foo \nfoo foo foo "
);
}

Expand Down
1 change: 0 additions & 1 deletion helix-view/src/annotations/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl InlineDiagnosticsConfig {
tab_width: 4,
max_wrap: self.max_wrap.min(width / 4),
max_indent_retain: 0,
wrap_indicator: "".into(),
wrap_indicator_highlight: None,
viewport_width: width,
soft_wrap_at_text_width: true,
Expand Down
5 changes: 0 additions & 5 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2319,10 +2319,6 @@ impl Document {
.and_then(|soft_wrap| soft_wrap.max_indent_retain)
.or(editor_soft_wrap.max_indent_retain)
.unwrap_or(40);
let wrap_indicator = language_soft_wrap
.and_then(|soft_wrap| soft_wrap.wrap_indicator.clone())
.or_else(|| config.soft_wrap.wrap_indicator.clone())
.unwrap_or_else(|| "↪ ".into());
let tab_width = self.tab_width() as u16;
TextFormat {
soft_wrap: enable_soft_wrap && viewport_width > 10,
Expand All @@ -2332,7 +2328,6 @@ impl Document {
// avoid spinning forever when the window manager
// sets the size to something tiny
viewport_width,
wrap_indicator: wrap_indicator.into_boxed_str(),
wrap_indicator_highlight: theme
.and_then(|theme| theme.find_highlight("ui.virtual.wrap")),
soft_wrap_at_text_width,
Expand Down
13 changes: 11 additions & 2 deletions helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ pub fn line_numbers<'doc>(
.char_to_line(doc.selection(view.id).primary().cursor(text));

let line_number = editor.config().line_number;
let wrap_indicator = editor
.config()
.soft_wrap
.wrap_indicator
.as_ref()
.map_or_else(
|| "↪".into(),
|indicator| indicator.clone().chars().take(width).collect::<String>(),
);
let mode = editor.mode;

Box::new(
Expand Down Expand Up @@ -193,10 +202,10 @@ pub fn line_numbers<'doc>(
if first_visual_line {
write!(out, "{:>1$}", display_num, width).unwrap();
} else {
write!(out, "{:>1$}", " ", width).unwrap();
write!(out, "{:>1$}", wrap_indicator, width).unwrap();
}

first_visual_line.then_some(style)
Some(style)
}
},
)
Expand Down