From c5e94126734ce3490ca8565643aba49b622f505e Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 25 Oct 2022 10:17:09 -0600 Subject: [PATCH] Do delete test using EGCs --- examples/editor-test/Cargo.toml | 1 + examples/editor-test/src/main.rs | 31 +++++++++++++++++-------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/examples/editor-test/Cargo.toml b/examples/editor-test/Cargo.toml index 0cafe02..3342022 100644 --- a/examples/editor-test/Cargo.toml +++ b/examples/editor-test/Cargo.toml @@ -12,6 +12,7 @@ env_logger = "0.9" fontdb = "0.9" log = "0.4" orbclient = "0.3.35" +unicode-segmentation = "1.7" [features] mono = [] diff --git a/examples/editor-test/src/main.rs b/examples/editor-test/src/main.rs index 99c35f3..2753b8d 100644 --- a/examples/editor-test/src/main.rs +++ b/examples/editor-test/src/main.rs @@ -3,6 +3,7 @@ use cosmic_text::{FontSystem, TextAction, TextBuffer, TextMetrics}; use orbclient::{Color, EventOption, Renderer, Window, WindowFlag}; use std::{env, fs, process, thread, time::{Duration, Instant}}; +use unicode_segmentation::UnicodeSegmentation; fn redraw(window: &mut Window, buffer: &mut TextBuffer<'_>) { let bg_color = Color::rgb(0x34, 0x34, 0x34); @@ -109,30 +110,32 @@ fn main() { for line in text.lines() { log::debug!("Line {:?}", line); - for c in line.chars() { - log::trace!("Insert {:?}", c); + for grapheme in line.graphemes(true) { + for c in grapheme.chars() { + log::trace!("Insert {:?}", c); - // Test backspace of character - { - let cursor = buffer.cursor(); + // Test backspace of character + { + let cursor = buffer.cursor(); + buffer.action(TextAction::Insert(c)); + buffer.action(TextAction::Backspace); + assert_eq!(cursor, buffer.cursor()); + } + + // Finally, normal insert of character buffer.action(TextAction::Insert(c)); - buffer.action(TextAction::Backspace); - assert_eq!(cursor, buffer.cursor()); } - /*TODO: Delete will remove whole EGC - // Test delete of character + // Test delete of EGC { let cursor = buffer.cursor(); - buffer.action(TextAction::Insert(c)); buffer.action(TextAction::Previous); buffer.action(TextAction::Delete); + for c in grapheme.chars() { + buffer.action(TextAction::Insert(c)); + } assert_eq!(cursor, buffer.cursor()); } - */ - - // Finally, normal insert of character - buffer.action(TextAction::Insert(c)); } // Test backspace of newline