From 00bc4d1e889d44fa73a597a1f446314ce0ead46b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 4 Jan 2023 20:02:00 -0700 Subject: [PATCH] Fix tests --- src/buffer.rs | 2 +- src/edit/editor.rs | 7 +++---- src/edit/syntect.rs | 10 +++++++--- src/edit/vi.rs | 5 +++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 8a2fb89..07d3612 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -86,7 +86,7 @@ impl<'a> LayoutRun<'a> { x_end = Some(self.glyphs.last().map_or(0., |glyph| glyph.x + glyph.w * ltr_factor)); } if let Some(x_start) = x_start { - let x_end = x_end.unwrap(); + let x_end = x_end.expect("end of cursor not found"); let (x_start, x_end) = if x_start < x_end { (x_start, x_end) } else { (x_end, x_start) }; Some((x_start, x_end - x_start)) } else { diff --git a/src/edit/editor.rs b/src/edit/editor.rs index d06df91..0e7df62 100644 --- a/src/edit/editor.rs +++ b/src/edit/editor.rs @@ -1,9 +1,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 #[cfg(not(feature = "std"))] -use alloc::string::{String, ToString}; -use core::cmp; -use std::iter::once; +use alloc::string::String; +use core::{cmp, iter::once}; use unicode_segmentation::UnicodeSegmentation; use crate::{Action, AttrsList, Buffer, BufferLine, Cursor, Edit, LayoutCursor}; @@ -227,7 +226,7 @@ impl<'a> Edit<'a> for Editor<'a> { if let Some(data_line) = lines_iter.next() { let mut these_attrs = final_attrs.split_off(data_line.len()); remaining_split_len -= data_line.len(); - std::mem::swap(&mut these_attrs, &mut final_attrs); + core::mem::swap(&mut these_attrs, &mut final_attrs); line.append(BufferLine::new(data_line.strip_suffix(char::is_control).unwrap_or(data_line), these_attrs)); } else { panic!("str::lines() did not yield any elements"); diff --git a/src/edit/syntect.rs b/src/edit/syntect.rs index 8414506..0c7aea1 100644 --- a/src/edit/syntect.rs +++ b/src/edit/syntect.rs @@ -33,7 +33,7 @@ use crate::{ Edit, Editor, Style, - Weight, + Weight, Wrap, }; @@ -161,7 +161,7 @@ impl<'a> Edit<'a> for SyntaxEditor<'a> { fn select_opt(&self) -> Option { self.editor.select_opt() } - + fn set_select_opt(&mut self, select_opt: Option) { self.editor.set_select_opt(select_opt); } @@ -247,7 +247,7 @@ impl<'a> Edit<'a> for SyntaxEditor<'a> { if highlighted > 0 { buffer.set_redraw(true); #[cfg(feature = "std")] - log::debug!("Syntax highlighted {} lines in {:?}", highlighted, now.elapsed()); + log::debug!("Syntax highlighted {} lines in {:?}", highlighted, now.elapsed()); } self.editor.shape_as_needed(); @@ -261,6 +261,10 @@ impl<'a> Edit<'a> for SyntaxEditor<'a> { self.editor.delete_selection() } + fn insert_string(&mut self, data: &str, attrs_list: Option) { + self.editor.insert_string(data, attrs_list); + } + fn action(&mut self, action: Action) { self.editor.action(action); } diff --git a/src/edit/vi.rs b/src/edit/vi.rs index 1b38f00..3a3b1b1 100644 --- a/src/edit/vi.rs +++ b/src/edit/vi.rs @@ -4,6 +4,7 @@ use unicode_segmentation::UnicodeSegmentation; use crate::{ Action, + AttrsList, Buffer, Color, Cursor, @@ -83,6 +84,10 @@ impl<'a> Edit<'a> for ViEditor<'a> { self.editor.delete_selection() } + fn insert_string(&mut self, data: &str, attrs_list: Option) { + self.editor.insert_string(data, attrs_list); + } + fn action(&mut self, action: Action) { let old_mode = self.mode;