sort of fix text editing (better but still bad)
This commit is contained in:
@@ -63,18 +63,23 @@ impl Text {
|
|||||||
|
|
||||||
match &mut self.cursor {
|
match &mut self.cursor {
|
||||||
Cursor::None => (),
|
Cursor::None => (),
|
||||||
Cursor::Select { line, col } => {
|
Cursor::Select { col, .. } => {
|
||||||
*col += 1;
|
*col += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.update_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn backspace(&mut self) {
|
pub fn backspace(&mut self) {
|
||||||
if let Some(i) = self.update_cursor().checked_sub(1) {
|
if let Some(i) = self
|
||||||
|
.update_cursor()
|
||||||
|
.checked_sub(1)
|
||||||
|
.map(|i| self.content.floor_char_boundary(i))
|
||||||
|
{
|
||||||
self.content.remove(i);
|
self.content.remove(i);
|
||||||
match &mut self.cursor {
|
match &mut self.cursor {
|
||||||
Cursor::None => (),
|
Cursor::None => (),
|
||||||
Cursor::Select { line, col } => {
|
Cursor::Select { col, .. } => {
|
||||||
*col -= 1;
|
*col -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,6 +94,7 @@ impl Text {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_cursor(&mut self, dir: Dir) {
|
pub fn move_cursor(&mut self, dir: Dir) {
|
||||||
|
self.update_cursor();
|
||||||
if let Cursor::Select { line, col } = &mut self.cursor {
|
if let Cursor::Select { line, col } = &mut self.cursor {
|
||||||
match dir {
|
match dir {
|
||||||
Dir::LEFT => *col -= 1,
|
Dir::LEFT => *col -= 1,
|
||||||
@@ -114,13 +120,13 @@ impl Text {
|
|||||||
let mut l = 0;
|
let mut l = 0;
|
||||||
let mut c = 0;
|
let mut c = 0;
|
||||||
let mut cur_len = 0;
|
let mut cur_len = 0;
|
||||||
for (i, ch) in self.content.chars().enumerate() {
|
for (i, ch) in self.content.char_indices() {
|
||||||
if ch == '\n' {
|
if ch == '\n' {
|
||||||
l += 1;
|
l += 1;
|
||||||
c = 0;
|
c = 0;
|
||||||
} else {
|
} else {
|
||||||
if l == *line {
|
if l == *line {
|
||||||
cur_len = i as isize + 1;
|
cur_len = c + 1;
|
||||||
if c == *col {
|
if c == *col {
|
||||||
idx = i;
|
idx = i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ pub struct TextAttrs {
|
|||||||
pub family: Family<'static>,
|
pub family: Family<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default, Debug, Copy, Clone)]
|
||||||
pub enum Cursor {
|
pub enum Cursor {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#![feature(const_from)]
|
#![feature(const_from)]
|
||||||
#![feature(map_try_insert)]
|
#![feature(map_try_insert)]
|
||||||
#![feature(trait_alias)]
|
#![feature(trait_alias)]
|
||||||
|
#![feature(round_char_boundary)]
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
|
|||||||
Reference in New Issue
Block a user