on master help sign in
Address PR comments.
0a5580aNathan Vegdahl
helix-core/src/chars.rsnew file+41
@@ -0,0 +1,41 @@
1+/// Determine whether a character is a line break.
2+pub fn char_is_linebreak(c: char) -> bool {
3+ matches!(
4+ c,
5+ '\u{000A}' | // LineFeed
6+ '\u{000B}' | // VerticalTab
7+ '\u{000C}' | // FormFeed
8+ '\u{000D}' | // CarriageReturn
9+ '\u{0085}' | // NextLine
10+ '\u{2028}' | // Line Separator
11+ '\u{2029}' // ParagraphSeparator
12+ )
13+}
14+
15+/// Determine whether a character qualifies as (non-line-break)
16+/// whitespace.
17+pub fn char_is_whitespace(c: char) -> bool {
18+ // TODO: this is a naive binary categorization of whitespace
19+ // characters. For display, word wrapping, etc. we'll need a better
20+ // categorization based on e.g. breaking vs non-breaking spaces
21+ // and whether they're zero-width or not.
22+ match c {
23+ //'\u{1680}' | // Ogham Space Mark (here for completeness, but usually displayed as a dash, not as whitespace)
24+ '\u{0009}' | // Character Tabulation
25+ '\u{0020}' | // Space
26+ '\u{00A0}' | // No-break Space
27+ '\u{180E}' | // Mongolian Vowel Separator
28+ '\u{202F}' | // Narrow No-break Space
29+ '\u{205F}' | // Medium Mathematical Space
30+ '\u{3000}' | // Ideographic Space
31+ '\u{FEFF}' // Zero Width No-break Space
32+ => true,
33+
34+ // En Quad, Em Quad, En Space, Em Space, Three-per-em Space,
35+ // Four-per-em Space, Six-per-em Space, Figure Space,
36+ // Punctuation Space, Thin Space, Hair Space, Zero Width Space.
37+ c if ('\u{2000}' ..= '\u{200B}').contains(&c) => true,
38+
39+ _ => false,
40+ }
41+}
helix-core/src/lib.rs+1
@@ -1,5 +1,6 @@
1#![allow(unused)]
1#![allow(unused)]
2pub mod auto_pairs;
2pub mod auto_pairs;
3+pub mod chars;
3pub mod comment;
4pub mod comment;
4pub mod diagnostic;
5pub mod diagnostic;
5pub mod graphemes;
6pub mod graphemes;
helix-view/src/document.rs+2−50
@@ -5,6 +5,7 @@ use std::path::{Component, Path, PathBuf};
5use std::sync::Arc;
5use std::sync::Arc;
6
6
7use helix_core::{
7use helix_core::{
8+ chars::{char_is_linebreak, char_is_whitespace},
8 history::History,
9 history::History,
9 syntax::{LanguageConfiguration, LOADER},
10 syntax::{LanguageConfiguration, LOADER},
10 ChangeSet, Diagnostic, Rope, Selection, State, Syntax, Transaction,
11 ChangeSet, Diagnostic, Rope, Selection, State, Syntax, Transaction,
@@ -277,55 +278,6 @@ impl Document {
277 }
278 }
278
279
279 fn detect_indent_style(&mut self) {
280 fn detect_indent_style(&mut self) {
280− // Determine whether a character is a line break.
281− //
282− // TODO: this is probably a generally useful utility function. Where
283− // should we put it?
284− fn char_is_linebreak(c: char) -> bool {
285− [
286− '\u{000A}', // LineFeed
287− '\u{000B}', // VerticalTab
288− '\u{000C}', // FormFeed
289− '\u{000D}', // CarriageReturn
290− '\u{0085}', // NextLine
291− '\u{2028}', // Line Separator
292− '\u{2029}', // ParagraphSeparator
293− ]
294− .contains(&c)
295− }
296−
297− // Determine whether a character qualifies as (non-line-break)
298− // whitespace.
299− //
300− // TODO: this is probably a generally useful utility function. Where
301− // should we put it?
302− //
303− // TODO: this is a naive binary categorization of whitespace
304− // characters. For display, word wrapping, etc. we'll need a better
305− // categorization based on e.g. breaking vs non-breaking spaces
306− // and whether they're zero-width or not.
307− pub fn char_is_whitespace(c: char) -> bool {
308− match c {
309− //'\u{1680}' | // Ogham Space Mark (here for completeness, but usually displayed as a dash, not as whitespace)
310− '\u{0009}' | // Character Tabulation
311− '\u{0020}' | // Space
312− '\u{00A0}' | // No-break Space
313− '\u{180E}' | // Mongolian Vowel Separator
314− '\u{202F}' | // Narrow No-break Space
315− '\u{205F}' | // Medium Mathematical Space
316− '\u{3000}' | // Ideographic Space
317− '\u{FEFF}' // Zero Width No-break Space
318− => true,
319−
320− // En Quad, Em Quad, En Space, Em Space, Three-per-em Space,
321− // Four-per-em Space, Six-per-em Space, Figure Space,
322− // Punctuation Space, Thin Space, Hair Space, Zero Width Space.
323− c if ('\u{2000}' ..= '\u{200B}').contains(&c) => true,
324−
325− _ => false,
326− }
327− }
328−
329 // Build a histogram of the indentation *increases* between
281 // Build a histogram of the indentation *increases* between
330 // subsequent lines, ignoring lines that are all whitespace.
282 // subsequent lines, ignoring lines that are all whitespace.
331 //
283 //
@@ -689,7 +641,7 @@ impl Document {
689 ///
641 ///
690 /// TODO: we might not need this function anymore, since the information
642 /// TODO: we might not need this function anymore, since the information
691 /// is conveniently available in `Document::indent_style` now.
643 /// is conveniently available in `Document::indent_style` now.
692− pub fn indent_unit(&self) -> &str {
644+ pub fn indent_unit(&self) -> &'static str {
693 match self.indent_style {
645 match self.indent_style {
694 IndentStyle::Tabs => "\t",
646 IndentStyle::Tabs => "\t",
695 IndentStyle::Spaces(1) => " ",
647 IndentStyle::Spaces(1) => " ",