aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs8
-rw-r--r--helix-view/src/editor.rs7
-rw-r--r--helix-view/src/view.rs7
3 files changed, 9 insertions, 13 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 8fdf7d98..a04af94d 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -1088,7 +1088,7 @@ impl Document {
impl Default for Document {
fn default() -> Self {
- let text = Rope::from(DEFAULT_LINE_ENDING.as_str());
+ let text = Rope::from("");
Self::from(text, None)
}
}
@@ -1213,11 +1213,7 @@ mod test {
#[test]
fn test_line_ending() {
- if cfg!(windows) {
- assert_eq!(Document::default().text().to_string(), "\r\n");
- } else {
- assert_eq!(Document::default().text().to_string(), "\n");
- }
+ assert_eq!(Document::default().text().to_string(), "");
}
macro_rules! test_decode {
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index cd9d0a92..1cd0af02 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -141,12 +141,11 @@ impl Editor {
let (view, doc) = current!(self);
// initialize selection for view
- let selection = doc
- .selections
+ doc.selections
.entry(view.id)
.or_insert_with(|| Selection::point(0));
// TODO: reuse align_view
- let pos = selection.cursor();
+ let pos = doc.selection(view.id).cursor(doc.text().slice(..));
let line = doc.text().char_to_line(pos);
view.first_line = line.saturating_sub(view.area.height as usize / 2);
@@ -296,7 +295,7 @@ impl Editor {
const OFFSET: u16 = 7; // 1 diagnostic + 5 linenr + 1 gutter
let view = view!(self);
let doc = &self.documents[view.doc];
- let cursor = doc.selection(view.id).cursor();
+ let cursor = doc.selection(view.id).cursor(doc.text().slice(..));
if let Some(mut pos) = view.screen_coords_at_pos(doc, doc.text().slice(..), cursor) {
pos.col += view.area.x as usize + OFFSET as usize;
pos.row += view.area.y as usize;
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 24df7a4f..67585ed3 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -84,7 +84,7 @@ impl View {
}
pub fn ensure_cursor_in_view(&mut self, doc: &Document) {
- let cursor = doc.selection(self.id).cursor();
+ let cursor = doc.selection(self.id).cursor(doc.text().slice(..));
let pos = coords_at_pos(doc.text().slice(..), cursor);
let line = pos.row;
let col = pos.col;
@@ -119,8 +119,9 @@ impl View {
pub fn last_line(&self, doc: &Document) -> usize {
let height = self.area.height.saturating_sub(1); // - 1 for statusline
std::cmp::min(
- self.first_line + height as usize,
- doc.text().len_lines() - 1,
+ // Saturating subs to make it inclusive zero indexing.
+ (self.first_line + height as usize).saturating_sub(1),
+ doc.text().len_lines().saturating_sub(1),
)
}