aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorNathan Vegdahl2021-06-20 22:09:10 +0000
committerNathan Vegdahl2021-06-20 22:33:02 +0000
commit4efd6713c5b30b33c497a1f85b77a7b0a7fd17e0 (patch)
tree7661f09f2279a3f9ae6a8f76770a69fd08f95981 /helix-term/src
parent5d22e3c4e574eb24260966de7f20f582e6184e24 (diff)
Work on moving code over to LineEnding instead of assuming '\n'.
Also some general cleanup and some minor fixes along the way.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs12
-rw-r--r--helix-term/src/ui/markdown.rs2
2 files changed, 9 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 8124c17a..b006504b 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1,6 +1,6 @@
use helix_core::{
comment, coords_at_pos, find_first_non_whitespace_char, find_root, get_line_ending, graphemes,
- indent, line_end, match_brackets,
+ indent, line_end_char_index, match_brackets,
movement::{self, Direction},
object, pos_at_coords,
regex::{self, Regex},
@@ -342,7 +342,7 @@ fn move_line_end(cx: &mut Context) {
let text = doc.text();
let line = text.char_to_line(range.head);
- let pos = line_end(&text.slice(..), line);
+ let pos = line_end_char_index(&text.slice(..), line);
Range::new(pos, pos)
});
@@ -490,6 +490,8 @@ where
let count = cx.count();
// need to wait for next key
+ // TODO: should this be done by grapheme rather than char? For example,
+ // we can't properly handle the line-ending case here in terms of char.
cx.on_next_key(move |cx, event| {
let ch = match event {
KeyEvent {
@@ -623,7 +625,7 @@ fn replace(cx: &mut Context) {
KeyEvent {
code: KeyCode::Enter,
..
- } => Some('\n'), // TODO: replace this with DEFAULT_LINE_ENDING
+ } => Some('\n'), // TODO: use the document's default line ending.
_ => None,
};
@@ -763,7 +765,7 @@ fn extend_line_end(cx: &mut Context) {
let text = doc.text();
let line = text.char_to_line(range.head);
- let pos = line_end(&text.slice(..), line);
+ let pos = line_end_char_index(&text.slice(..), line);
Range::new(range.anchor, pos)
});
@@ -1642,7 +1644,7 @@ fn append_to_line(cx: &mut Context) {
let selection = doc.selection(view.id).transform(|range| {
let text = doc.text();
let line = text.char_to_line(range.head);
- let pos = line_end(&text.slice(..), line);
+ let pos = line_end_char_index(&text.slice(..), line);
Range::new(pos, pos)
});
doc.set_selection(view.id, selection);
diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs
index be113747..3ce3a5b8 100644
--- a/helix-term/src/ui/markdown.rs
+++ b/helix-term/src/ui/markdown.rs
@@ -110,6 +110,8 @@ fn parse<'a>(contents: &'a str, theme: Option<&Theme>) -> tui::text::Text<'a> {
// TODO: replace tabs with indentation
let mut slice = &text[start..end];
+ // TODO: do we need to handle all unicode line endings
+ // here, or is just '\n' okay?
while let Some(end) = slice.find('\n') {
// emit span up to newline
let text = &slice[..end];