Vi-style editor and other editor improvements (#40)

* WIP VI wrapper for editor

* WIP: block cursor

* Create Edit trait, run CI on all feature options

* Add prints describing build steps to ci.sh

* Custom rendering for Vi editor

* Clippy fixes

* More clippy fixes

* Show clippy results in CI

* Fix for Redox

* Fix clippy lint

* Add vi feature to enable vi-style editor

* Add escape to libcosmic text box
This commit is contained in:
Jeremy Soller 2022-11-15 12:26:59 -07:00 committed by GitHub
parent 271ca5cf7a
commit ee54e7626b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 982 additions and 616 deletions

View file

@ -12,3 +12,8 @@ env_logger = "0.9"
fontdb = "0.9"
log = "0.4"
orbclient = "0.3.35"
unicode-segmentation = "1.7"
[features]
default = []
vi = ["cosmic-text/vi"]

View file

@ -4,6 +4,7 @@ use cosmic_text::{
Action,
Attrs,
Buffer,
Edit,
Family,
FontSystem,
Metrics,
@ -60,12 +61,16 @@ fn main() {
let mut font_size_i = font_size_default;
let line_x = 8 * display_scale;
let mut editor = SyntaxEditor::new(
Buffer::new(&font_system, font_sizes[font_size_i]),
&syntax_system,
"base16-eighties.dark"
).unwrap();
#[cfg(feature = "vi")]
let mut editor = cosmic_text::ViEditor::new(editor);
editor.buffer_mut().set_size(
window.width() as i32 - line_x * 2,
window.height() as i32
@ -89,13 +94,14 @@ fn main() {
let mut mouse_left = false;
loop {
editor.shape_as_needed();
if editor.buffer_mut().redraw {
if editor.buffer().redraw() {
let instant = Instant::now();
let bg = editor.background_color();
window.set(orbclient::Color::rgb(bg.r(), bg.g(), bg.b()));
editor.draw(&mut swash_cache, |x, y, w, h, color| {
let fg = editor.foreground_color();
editor.draw(&mut swash_cache, fg, |x, y, w, h, color| {
window.rect(line_x + x, y, w, h, orbclient::Color { data: color.0 })
});
@ -127,7 +133,7 @@ fn main() {
window.sync();
editor.buffer_mut().redraw = false;
editor.buffer_mut().set_redraw(false);
log::debug!("redraw: {:?}", instant.elapsed());
}
@ -148,6 +154,7 @@ fn main() {
orbclient::K_END if event.pressed => editor.action(Action::End),
orbclient::K_PGUP if event.pressed => editor.action(Action::PageUp),
orbclient::K_PGDN if event.pressed => editor.action(Action::PageDown),
orbclient::K_ESC if event.pressed => editor.action(Action::Escape),
orbclient::K_ENTER if event.pressed => editor.action(Action::Enter),
orbclient::K_BKSP if event.pressed => editor.action(Action::Backspace),
orbclient::K_DEL if event.pressed => editor.action(Action::Delete),