on master help sign in
ran cargo fmt
commit97323dc2f90f81afc82bd929d111abda540bebe5 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateSat 19 Jun 2021, 14:05 (5 years ago) parentecb884d
3 files changed+23−12
helix-core/src/lib.rs+2−1 helix-core/src/line_ending.rs+8−2 helix-term/src/commands.rs+13−9
helix-core/src/lib.rs+2−1
@@ -111,6 +111,7 @@ pub use diagnostic::Diagnostic;
111111pub use state::State;
112112
113113pub use line_ending::{
114− auto_detect_line_ending, rope_slice_to_line_ending, LineEnding, DEFAULT_LINE_ENDING, get_line_ending
114+ auto_detect_line_ending, get_line_ending, rope_slice_to_line_ending, LineEnding,
115+ DEFAULT_LINE_ENDING,
115116};
116117pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};
helix-core/src/line_ending.rs+8−2
@@ -95,12 +95,18 @@ pub fn auto_detect_line_ending(doc: &Rope) -> Option<LineEnding> {
9595/// Returns the passed line's line ending, if any.
9696pub fn get_line_ending(line: &RopeSlice) -> Option<LineEnding> {
9797 // Last character as str.
98− let g1 = line.slice(line.len_chars().saturating_sub(1)..).as_str().unwrap();
98+ let g1 = line
99+ .slice(line.len_chars().saturating_sub(1)..)
100+ .as_str()
101+ .unwrap();
99102
100103 // Last two characters as str, or empty str if they're not contiguous.
101104 // It's fine to punt on the non-contiguous case, because Ropey guarantees
102105 // that CRLF is always contiguous.
103− let g2 = line.slice(line.len_chars().saturating_sub(2)..).as_str().unwrap_or("");
106+ let g2 = line
107+ .slice(line.len_chars().saturating_sub(2)..)
108+ .as_str()
109+ .unwrap_or("");
104110
105111 // First check the two-character case for CRLF, then check the single-character case.
106112 str_to_line_ending(g2).or_else(|| str_to_line_ending(g1))
helix-term/src/commands.rs+13−9
@@ -1,11 +1,11 @@
11use helix_core::{
2− comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes, indent,
3− match_brackets,
2+ comment, coords_at_pos, find_first_non_whitespace_char, find_root, get_line_ending, graphemes,
3+ indent, match_brackets,
44 movement::{self, Direction},
55 object, pos_at_coords,
66 regex::{self, Regex},
77 register::{self, Register, Registers},
8− search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeSlice, Selection, get_line_ending,
8+ search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeSlice, Selection,
99 SmallVec, Tendril, Transaction,
1010};
1111
@@ -183,9 +183,11 @@ pub fn move_line_end(cx: &mut Context) {
183183 let text = doc.text();
184184 let line = text.char_to_line(range.head);
185185
186− let pos = text
187− .line_to_char(line + 1)
188− .saturating_sub(get_line_ending(&text.line(line)).map(|le| le.len_chars()).unwrap_or(0));
186+ let pos = text.line_to_char(line + 1).saturating_sub(
187+ get_line_ending(&text.line(line))
188+ .map(|le| le.len_chars())
189+ .unwrap_or(0),
190+ );
189191
190192 Range::new(pos, pos)
191193 });
@@ -606,9 +608,11 @@ pub fn extend_line_end(cx: &mut Context) {
606608 let text = doc.text();
607609 let line = text.char_to_line(range.head);
608610
609− let pos = text
610− .line_to_char(line + 1)
611− .saturating_sub(get_line_ending(&text.line(line)).map(|le| le.len_chars()).unwrap_or(0));
611+ let pos = text.line_to_char(line + 1).saturating_sub(
612+ get_line_ending(&text.line(line))
613+ .map(|le| le.len_chars())
614+ .unwrap_or(0),
615+ );
612616
613617 Range::new(range.anchor, pos)
614618 });