summaryrefslogtreecommitdiffstats
path: root/src/line.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/line.rs')
-rw-r--r--src/line.rs23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/line.rs b/src/line.rs
index 2b6c894..9877c48 100644
--- a/src/line.rs
+++ b/src/line.rs
@@ -65,7 +65,6 @@ impl Editor {
65 let width = terminal_width(); 65 let width = terminal_width();
66 let (cursor_row, _) = layout(prompt, &buffer, cursor, width); 66 let (cursor_row, _) = layout(prompt, &buffer, cursor, width);
67 state.cursor_row = cursor_row; 67 state.cursor_row = cursor_row;
68 state.rows = layout(prompt, &buffer, buffer.len(), width).0 + 1;
69 } 68 }
70 Event::Key(key) if key.kind == KeyEventKind::Press => { 69 Event::Key(key) if key.kind == KeyEventKind::Press => {
71 match handle_key(key, &mut buffer, &mut cursor, self) { 70 match handle_key(key, &mut buffer, &mut cursor, self) {
@@ -271,17 +270,16 @@ fn layout(prompt: &str, buffer: &[char], upto: usize, width: usize) -> (usize, u
271 pending_wrap = false; 270 pending_wrap = false;
272 continue; 271 continue;
273 } 272 }
273 let cells = cells(ch, col);
274 if cells == 0 {
275 // Combining marks draw on top of the previous cell and never wrap.
276 continue;
277 }
274 if pending_wrap { 278 if pending_wrap {
275 row += 1; 279 row += 1;
276 col = 0; 280 col = 0;
277 pending_wrap = false; 281 pending_wrap = false;
278 } 282 }
279
280 let cells = cells(ch, col);
281 if cells == 0 {
282 // Combining marks draw on top of the previous cell.
283 continue;
284 }
285 if col + cells > width { 283 if col + cells > width {
286 row += 1; 284 row += 1;
287 col = 0; 285 col = 0;
@@ -310,7 +308,6 @@ fn cells(ch: char, col: usize) -> usize {
310/// that row, not by the number of rows the block occupies. 308/// that row, not by the number of rows the block occupies.
311#[derive(Default, Clone, Copy)] 309#[derive(Default, Clone, Copy)]
312struct DrawState { 310struct DrawState {
313 rows: usize,
314 cursor_row: usize, 311 cursor_row: usize,
315} 312}
316 313
@@ -358,7 +355,6 @@ fn draw_to<W: Write>(
358 } 355 }
359 execute!(out, MoveToColumn(clamp(cursor_col)))?; 356 execute!(out, MoveToColumn(clamp(cursor_col)))?;
360 357
361 state.rows = end_row + 1;
362 state.cursor_row = cursor_row; 358 state.cursor_row = cursor_row;
363 Ok(()) 359 Ok(())
364} 360}
@@ -503,6 +499,15 @@ mod tests {
503 } 499 }
504 500
505 #[test] 501 #[test]
502 fn a_combining_mark_at_the_wrap_boundary_does_not_wrap() {
503 let text: Vec<char> = ['a', 'b', '\u{0301}'].to_vec();
504 // width 2: 'b' fills the last column (pending wrap), the mark must not
505 // consume that pending wrap and move to a new row.
506 let (row, col) = layout("", &text, 3, 2);
507 assert_eq!((row, col), (0, 1));
508 }
509
510 #[test]
506 fn layout_counts_wide_and_combining_characters() { 511 fn layout_counts_wide_and_combining_characters() {
507 let wide: Vec<char> = "日本語".chars().collect(); 512 let wide: Vec<char> = "日本語".chars().collect();
508 assert_eq!(layout("> ", &wide, 3, 20), (0, 8)); 513 assert_eq!(layout("> ", &wide, 3, 20), (0, 8));