diff --git a/editor-test.sh b/editor-test.sh index 3ae5372..cb5a829 100755 --- a/editor-test.sh +++ b/editor-test.sh @@ -1 +1 @@ -RUST_LOG="cosmic_text=debug,editor_test=debug" cargo run --release --package editor-test -- "$@" +RUST_LOG="cosmic_text=debug,editor_test=debug" cargo run --release --package editor-test --features mono -- "$@" diff --git a/examples/editor-test/src/main.rs b/examples/editor-test/src/main.rs index 6a457d1..b20897f 100644 --- a/examples/editor-test/src/main.rs +++ b/examples/editor-test/src/main.rs @@ -135,15 +135,61 @@ fn main() { default_text.to_string() }; - for c in text.chars() { - match c { - '\r' => (), - '\n' => buffer.action(TextAction::Enter), - _ => { - buffer.action(TextAction::Insert(c)); + //TODO: support bidi + for line in text.lines() { + for c in line.chars() { + if c.is_control() { + log::warn!("Ignoring control character {:?}", c); + continue; } + + log::debug!("Insert {:?}", c); + + //TODO: ligatures break this, make cursor reference text lines not layout lines! + // Test backspace of character + { + let cursor = buffer.cursor(); + buffer.action(TextAction::Insert(c)); + buffer.action(TextAction::Backspace); + assert_eq!(cursor, buffer.cursor()); + } + + // Test delete of character (DOES NOT SUPPORT RTL) + { + let cursor = buffer.cursor(); + buffer.action(TextAction::Insert(c)); + buffer.action(TextAction::Left); + buffer.action(TextAction::Delete); + assert_eq!(cursor, buffer.cursor()); + } + + // Finally, normal insert of character + buffer.action(TextAction::Insert(c)); } + log::debug!("Line '{}': {:?}", line, line); + + // Test backspace of newline + { + let cursor = buffer.cursor(); + buffer.action(TextAction::Enter); + buffer.action(TextAction::Backspace); + assert_eq!(cursor, buffer.cursor()); + } + + // Test delete of newline + { + let cursor = buffer.cursor(); + buffer.action(TextAction::Enter); + buffer.action(TextAction::Up); + buffer.action(TextAction::End); + buffer.action(TextAction::Delete); + assert_eq!(cursor, buffer.cursor()); + } + + // Finally, normal enter + buffer.action(TextAction::Enter); + redraw(&mut window, &mut buffer); for event in window.events() { @@ -168,16 +214,4 @@ fn main() { } else { log::error!("{} lines did not match!", wrong); } - - redraw(&mut window, &mut buffer); - - loop { - for event in window.events() { - match event.to_option() { - EventOption::Quit(_) => process::exit(0), - _ => (), - } - } - thread::sleep(Duration::from_millis(1)); - } }