More implementation of new buffer abstraction

This commit is contained in:
Jeremy Soller 2022-10-20 19:34:56 -06:00
parent 2bbacf5636
commit 441112b5e2
No known key found for this signature in database
GPG key ID: 87F211AF2BE4C2FE
7 changed files with 244 additions and 397 deletions

View file

@ -18,28 +18,6 @@ fn redraw(window: &mut Window, buffer: &mut TextBuffer<'_>) {
window.rect(x, y, w, h, Color { data: color });
});
let mut line_y = font_size;
let mut start_line_opt = None;
let mut end_line = TextLineIndex::new(0);
for (line_i, line) in buffer
.layout_lines()
.iter()
.skip(buffer.scroll() as usize)
.take(buffer.lines() as usize)
.enumerate()
{
if line_y >= window.height() as i32 {
break;
}
end_line = line.line_i;
if start_line_opt == None {
start_line_opt = Some(end_line);
}
line_y += line_height;
}
window.sync();
buffer.redraw = false;
@ -149,7 +127,6 @@ fn main() {
log::debug!("Insert {:?}", c);
//TODO: ligatures break this, make cursor reference text lines not layout lines!
// Test backspace of character
{
let cursor = buffer.cursor();
@ -158,6 +135,7 @@ fn main() {
assert_eq!(cursor, buffer.cursor());
}
/*TODO
// Test delete of character (DOES NOT SUPPORT RTL)
{
let cursor = buffer.cursor();
@ -166,6 +144,7 @@ fn main() {
buffer.action(TextAction::Delete);
assert_eq!(cursor, buffer.cursor());
}
*/
// Finally, normal insert of character
buffer.action(TextAction::Insert(c));
@ -179,6 +158,7 @@ fn main() {
assert_eq!(cursor, buffer.cursor());
}
/*TODO
// Test delete of newline
{
let cursor = buffer.cursor();
@ -188,6 +168,7 @@ fn main() {
buffer.action(TextAction::Delete);
assert_eq!(cursor, buffer.cursor());
}
*/
// Finally, normal enter
buffer.action(TextAction::Enter);
@ -219,4 +200,16 @@ fn main() {
} else {
log::error!("{} lines did not match!", wrong);
}
//TODO: make window not async?
loop {
for event in window.events() {
match event.to_option() {
EventOption::Quit(_) => process::exit(0),
_ => (),
}
}
thread::sleep(Duration::from_millis(1));
}
}