Fix tests

This commit is contained in:
Jeremy Soller 2023-01-04 20:02:00 -07:00
parent 210ca61f13
commit 00bc4d1e88
4 changed files with 16 additions and 8 deletions

View file

@ -86,7 +86,7 @@ impl<'a> LayoutRun<'a> {
x_end = Some(self.glyphs.last().map_or(0., |glyph| glyph.x + glyph.w * ltr_factor)); x_end = Some(self.glyphs.last().map_or(0., |glyph| glyph.x + glyph.w * ltr_factor));
} }
if let Some(x_start) = x_start { 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) }; 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)) Some((x_start, x_end - x_start))
} else { } else {

View file

@ -1,9 +1,8 @@
// SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-License-Identifier: MIT OR Apache-2.0
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
use alloc::string::{String, ToString}; use alloc::string::String;
use core::cmp; use core::{cmp, iter::once};
use std::iter::once;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use crate::{Action, AttrsList, Buffer, BufferLine, Cursor, Edit, LayoutCursor}; 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() { if let Some(data_line) = lines_iter.next() {
let mut these_attrs = final_attrs.split_off(data_line.len()); let mut these_attrs = final_attrs.split_off(data_line.len());
remaining_split_len -= 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)); line.append(BufferLine::new(data_line.strip_suffix(char::is_control).unwrap_or(data_line), these_attrs));
} else { } else {
panic!("str::lines() did not yield any elements"); panic!("str::lines() did not yield any elements");

View file

@ -33,7 +33,7 @@ use crate::{
Edit, Edit,
Editor, Editor,
Style, Style,
Weight, Weight,
Wrap, Wrap,
}; };
@ -161,7 +161,7 @@ impl<'a> Edit<'a> for SyntaxEditor<'a> {
fn select_opt(&self) -> Option<Cursor> { fn select_opt(&self) -> Option<Cursor> {
self.editor.select_opt() self.editor.select_opt()
} }
fn set_select_opt(&mut self, select_opt: Option<Cursor>) { fn set_select_opt(&mut self, select_opt: Option<Cursor>) {
self.editor.set_select_opt(select_opt); self.editor.set_select_opt(select_opt);
} }
@ -247,7 +247,7 @@ impl<'a> Edit<'a> for SyntaxEditor<'a> {
if highlighted > 0 { if highlighted > 0 {
buffer.set_redraw(true); buffer.set_redraw(true);
#[cfg(feature = "std")] #[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(); self.editor.shape_as_needed();
@ -261,6 +261,10 @@ impl<'a> Edit<'a> for SyntaxEditor<'a> {
self.editor.delete_selection() self.editor.delete_selection()
} }
fn insert_string(&mut self, data: &str, attrs_list: Option<AttrsList>) {
self.editor.insert_string(data, attrs_list);
}
fn action(&mut self, action: Action) { fn action(&mut self, action: Action) {
self.editor.action(action); self.editor.action(action);
} }

View file

@ -4,6 +4,7 @@ use unicode_segmentation::UnicodeSegmentation;
use crate::{ use crate::{
Action, Action,
AttrsList,
Buffer, Buffer,
Color, Color,
Cursor, Cursor,
@ -83,6 +84,10 @@ impl<'a> Edit<'a> for ViEditor<'a> {
self.editor.delete_selection() self.editor.delete_selection()
} }
fn insert_string(&mut self, data: &str, attrs_list: Option<AttrsList>) {
self.editor.insert_string(data, attrs_list);
}
fn action(&mut self, action: Action) { fn action(&mut self, action: Action) {
let old_mode = self.mode; let old_mode = self.mode;