on master help sign in
simplify.
a924ad2Blaž Hrastnik
helix-core/src/selection.rs+1
@@ -184,6 +184,7 @@ impl Selection {
184 Self::single(pos, pos)
184 Self::single(pos, pos)
185 }
185 }
186
186
187+ // TODO: consume an iterator or a vec to reduce allocations?
187 #[must_use]
188 #[must_use]
188 pub fn new(ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Self {
189 pub fn new(ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Self {
189 fn normalize(mut ranges: SmallVec<[Range; 1]>, mut primary_index: usize) -> Selection {
190 fn normalize(mut ranges: SmallVec<[Range; 1]>, mut primary_index: usize) -> Selection {
helix-term/src/ui/editor.rs+23−17
@@ -69,15 +69,15 @@ impl EditorView {
69 is_focused: bool,
69 is_focused: bool,
70 ) {
70 ) {
71 // TODO: inefficient, should feed chunks.iter() to tree_sitter.parse_with(|offset, pos|)
71 // TODO: inefficient, should feed chunks.iter() to tree_sitter.parse_with(|offset, pos|)
72− let source_code = view.doc.text().to_string();
72+ let text = view.doc.text();
73+ let source_code = text.to_string();
73
74
74 let last_line = view.last_line();
75 let last_line = view.last_line();
75
76
76 let range = {
77 let range = {
77 // calculate viewport byte ranges
78 // calculate viewport byte ranges
78− let start = view.doc.text().line_to_byte(view.first_line);
79+ let start = text.line_to_byte(view.first_line);
79− let end = view.doc.text().line_to_byte(last_line)
80+ let end = text.line_to_byte(last_line) + text.line(last_line).len_bytes();
80− + view.doc.text().line(last_line).len_bytes();
81
81
82 start..end
82 start..end
83 };
83 };
@@ -126,10 +126,12 @@ impl EditorView {
126 HighlightEvent::Source { start, end } => {
126 HighlightEvent::Source { start, end } => {
127 // TODO: filter out spans out of viewport for now..
127 // TODO: filter out spans out of viewport for now..
128
128
129− let start = view.doc.text().byte_to_char(start);
129+ // TODO: do these before iterating
130− let end = view.doc.text().byte_to_char(end); // <-- index 744, len 743
130+ let text = view.doc.text();
131+ let start = text.byte_to_char(start);
132+ let end = text.byte_to_char(end);
131
133
132− let text = view.doc.text().slice(start..end);
134+ let text = text.slice(start..end);
133
135
134 use helix_core::graphemes::{grapheme_width, RopeGraphemes};
136 use helix_core::graphemes::{grapheme_width, RopeGraphemes};
135
137
@@ -141,6 +143,7 @@ impl EditorView {
141 // TODO: we could render the text to a surface, then cache that, that
143 // TODO: we could render the text to a surface, then cache that, that
142 // way if only the selection/cursor changes we can copy from cache
144 // way if only the selection/cursor changes we can copy from cache
143 // and paint the new cursor.
145 // and paint the new cursor.
146+ // We could keep a single resizable surface on the View for that.
144
147
145 let mut char_index = start;
148 let mut char_index = start;
146
149
@@ -159,6 +162,13 @@ impl EditorView {
159 } else if grapheme == "\t" {
162 } else if grapheme == "\t" {
160 visual_x += (TAB_WIDTH as u16);
163 visual_x += (TAB_WIDTH as u16);
161 } else {
164 } else {
165+ if visual_x >= viewport.width {
166+ // if we're offscreen just keep going until we hit a new line
167+ // TODO: will need tweaking when we also take into account
168+ // horizontal scrolling
169+ continue;
170+ }
171+
162 // Cow will prevent allocations if span contained in a single slice
172 // Cow will prevent allocations if span contained in a single slice
163 // which should really be the majority case
173 // which should really be the majority case
164 let grapheme = Cow::from(grapheme);
174 let grapheme = Cow::from(grapheme);
@@ -198,16 +208,12 @@ impl EditorView {
198
208
199 // TODO: paint cursor heads except primary
209 // TODO: paint cursor heads except primary
200
210
201− // HAXX: we don't render the char if it's offscreen. This should be
202− // skipped in a better way much earlier
203− if visual_x < viewport.width {
204− surface.set_string(
211+ surface.set_string(
205− viewport.x + visual_x,
212+ viewport.x + visual_x,
206− viewport.y + line,
213+ viewport.y + line,
207− grapheme,
214+ grapheme,
208− style,
215+ style,
209− );
216+ );
210− }
211
217
212 visual_x += width;
218 visual_x += width;
213 }
219 }
helix-view/src/tree.rs+6
@@ -57,6 +57,12 @@ impl Container {
57 }
57 }
58}
58}
59
59
60+impl Default for Container {
61+ fn default() -> Self {
62+ Self::new()
63+ }
64+}
65+
60impl Tree {
66impl Tree {
61 pub fn new(area: Rect) -> Self {
67 pub fn new(area: Rect) -> Self {
62 let root = Node::container();
68 let root = Node::container();