A simple CPU rendered GUI IDE experience.
add home/end
bendn 7 months ago
parent 4590567 · commit ae84ab5
-rw-r--r--src/main.rs2
-rw-r--r--src/text.rs26
2 files changed, 28 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 99ccab7..8425ea5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -158,6 +158,8 @@ pub(crate) fn entry(event_loop: EventLoop<()>) {
Named(Backspace) => text.backspace(),
Named(ArrowLeft) =>
text.left(),
+ Named(Home) => text.home(),
+ Named(End) => text.end(),
Named(ArrowRight)=> text.right(),
Named(ArrowUp) => text.up(),
Named(ArrowDown) => text.down(),
diff --git a/src/text.rs b/src/text.rs
index f2e3c42..af0c07b 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -61,6 +61,32 @@ impl TextArea {
self.setc();
}
+ #[implicit_fn::implicit_fn]
+ pub fn home(&mut self) {
+ let beg =
+ self.rope.line_to_char(self.rope.char_to_line(self.cursor));
+ let i = self.cursor - beg;
+ let l = self.rope.line(self.rope.char_to_line(self.cursor));
+ let whitespaces = l.chars().take_while(_.is_whitespace()).count();
+ if i == whitespaces {
+ self.cursor = beg;
+ self.column = 0;
+ } else {
+ self.cursor = whitespaces + beg;
+ self.column = whitespaces;
+ }
+ }
+
+ pub fn end(&mut self) {
+ let i = self.rope.char_to_line(self.cursor);
+ let beg = self.rope.line_to_char(i);
+
+ let l = self.rope.line(self.rope.char_to_line(self.cursor));
+ self.cursor = beg + l.len_chars()
+ - self.rope.get_line(i + 1).map(|_| 1).unwrap_or(0);
+ self.setc();
+ }
+
#[lower::apply(saturating)]
pub fn right(&mut self) {
self.cursor += 1;