Skip to content

Commit

Permalink
ran cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
janhrastnik committed Jun 19, 2021
1 parent ecb884d commit 97323dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
3 changes: 2 additions & 1 deletion helix-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub use diagnostic::Diagnostic;
pub use state::State;

pub use line_ending::{
auto_detect_line_ending, rope_slice_to_line_ending, LineEnding, DEFAULT_LINE_ENDING, get_line_ending
auto_detect_line_ending, get_line_ending, rope_slice_to_line_ending, LineEnding,
DEFAULT_LINE_ENDING,
};
pub use transaction::{Assoc, Change, ChangeSet, Operation, Transaction};
10 changes: 8 additions & 2 deletions helix-core/src/line_ending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,18 @@ pub fn auto_detect_line_ending(doc: &Rope) -> Option<LineEnding> {
/// Returns the passed line's line ending, if any.
pub fn get_line_ending(line: &RopeSlice) -> Option<LineEnding> {
// Last character as str.
let g1 = line.slice(line.len_chars().saturating_sub(1)..).as_str().unwrap();
let g1 = line
.slice(line.len_chars().saturating_sub(1)..)
.as_str()
.unwrap();

// Last two characters as str, or empty str if they're not contiguous.
// It's fine to punt on the non-contiguous case, because Ropey guarantees
// that CRLF is always contiguous.
let g2 = line.slice(line.len_chars().saturating_sub(2)..).as_str().unwrap_or("");
let g2 = line
.slice(line.len_chars().saturating_sub(2)..)
.as_str()
.unwrap_or("");

// First check the two-character case for CRLF, then check the single-character case.
str_to_line_ending(g2).or_else(|| str_to_line_ending(g1))
Expand Down
22 changes: 13 additions & 9 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use helix_core::{
comment, coords_at_pos, find_first_non_whitespace_char, find_root, graphemes, indent,
match_brackets,
comment, coords_at_pos, find_first_non_whitespace_char, find_root, get_line_ending, graphemes,
indent, match_brackets,
movement::{self, Direction},
object, pos_at_coords,
regex::{self, Regex},
register::{self, Register, Registers},
search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeSlice, Selection, get_line_ending,
search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeSlice, Selection,
SmallVec, Tendril, Transaction,
};

Expand Down Expand Up @@ -183,9 +183,11 @@ pub fn move_line_end(cx: &mut Context) {
let text = doc.text();
let line = text.char_to_line(range.head);

let pos = text
.line_to_char(line + 1)
.saturating_sub(get_line_ending(&text.line(line)).map(|le| le.len_chars()).unwrap_or(0));
let pos = text.line_to_char(line + 1).saturating_sub(
get_line_ending(&text.line(line))
.map(|le| le.len_chars())
.unwrap_or(0),
);

Range::new(pos, pos)
});
Expand Down Expand Up @@ -606,9 +608,11 @@ pub fn extend_line_end(cx: &mut Context) {
let text = doc.text();
let line = text.char_to_line(range.head);

let pos = text
.line_to_char(line + 1)
.saturating_sub(get_line_ending(&text.line(line)).map(|le| le.len_chars()).unwrap_or(0));
let pos = text.line_to_char(line + 1).saturating_sub(
get_line_ending(&text.line(line))
.map(|le| le.len_chars())
.unwrap_or(0),
);

Range::new(range.anchor, pos)
});
Expand Down

0 comments on commit 97323dc

Please sign in to comment.