Skip to content

Commit

Permalink
Newline fixes WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Oct 2, 2024
1 parent 41821d4 commit 5ec65c8
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions examples/vello_editor/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use parley::layout::cursor::{Selection, VisualMode};
use parley::layout::Affinity;
use parley::{layout::PositionedLayoutItem, FontContext};
use peniko::{kurbo::Affine, Color, Fill};
use winit::keyboard::SmolStr;
use std::time::Instant;
use vello::Scene;
use winit::{
Expand Down Expand Up @@ -248,15 +249,41 @@ impl Editor {
}
_ => {
if let Some(text) = &event.text {
let text = if text == "\r" || text == "\r\n" {
&SmolStr::new_inline("\n")
} else {
text
};

let affinity = if code == KeyCode::Enter {
Affinity::Downstream
} else {
Affinity::Upstream
};


dbg!(code);
dbg!(affinity);
dbg!(text);
dbg!(text.len());

let start = self
.delete_current_selection()
.unwrap_or_else(|| self.selection.focus().text_range().start);
self.buffer.insert_str(start, text);


let index = if code == KeyCode::Enter {
start + text.len()
} else {
start + text.len()
};

self.update_layout(self.width, 1.0);
self.selection = Selection::from_index(
&self.layout,
start + text.len() - 1,
Affinity::Upstream,
index,
affinity,
);
}
}
Expand Down

0 comments on commit 5ec65c8

Please sign in to comment.