initial commit
This commit is contained in:
commit
a1c91f6d4e
14 changed files with 1633 additions and 0 deletions
22
src/actions/delete.rs
Normal file
22
src/actions/delete.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use super::ActionRunner;
|
||||
|
||||
pub(crate) struct DeleteContentBackward;
|
||||
pub(crate) struct DeleteContentForward;
|
||||
|
||||
impl ActionRunner for DeleteContentBackward {
|
||||
fn run(&self, start: usize, _end: usize, _data: Option<String>, mut doc: String) -> String {
|
||||
if start > 0 {
|
||||
doc.remove(start - 1);
|
||||
}
|
||||
doc
|
||||
}
|
||||
}
|
||||
|
||||
impl ActionRunner for DeleteContentForward {
|
||||
fn run(&self, start: usize, _end: usize, _data: Option<String>, mut doc: String) -> String {
|
||||
if doc.len() > start {
|
||||
doc.remove(start);
|
||||
}
|
||||
doc
|
||||
}
|
||||
}
|
18
src/actions/insert.rs
Normal file
18
src/actions/insert.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use super::ActionRunner;
|
||||
|
||||
pub(crate) struct InsertText;
|
||||
|
||||
impl ActionRunner for InsertText {
|
||||
fn run(&self, start: usize, end: usize, data: Option<String>, mut doc: String) -> String {
|
||||
if doc.len() < start || data.is_none() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
if start < end {
|
||||
doc.replace_range(start..end, "");
|
||||
}
|
||||
|
||||
doc.insert_str(start, &data.unwrap());
|
||||
doc
|
||||
}
|
||||
}
|
12
src/actions/linebreak.rs
Normal file
12
src/actions/linebreak.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use super::ActionRunner;
|
||||
|
||||
pub(crate) struct InsertLineBreak;
|
||||
|
||||
impl ActionRunner for InsertLineBreak {
|
||||
fn run(&self, start: usize, _end: usize, _data: Option<String>, mut doc: String) -> String {
|
||||
if doc.len() >= start {
|
||||
doc.insert(start, '\n');
|
||||
}
|
||||
doc
|
||||
}
|
||||
}
|
8
src/actions/mod.rs
Normal file
8
src/actions/mod.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
pub(crate) mod delete;
|
||||
pub(crate) mod insert;
|
||||
pub(crate) mod linebreak;
|
||||
pub(crate) mod paste;
|
||||
|
||||
pub(crate) trait ActionRunner {
|
||||
fn run(&self, start: usize, end: usize, data: Option<String>, doc: String) -> String;
|
||||
}
|
18
src/actions/paste.rs
Normal file
18
src/actions/paste.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use super::ActionRunner;
|
||||
|
||||
pub(crate) struct InsertFromPaste;
|
||||
|
||||
impl ActionRunner for InsertFromPaste {
|
||||
fn run(&self, start: usize, end: usize, data: Option<String>, mut doc: String) -> String {
|
||||
if doc.len() < start || data.is_none() {
|
||||
return doc;
|
||||
}
|
||||
|
||||
if start < end {
|
||||
doc.replace_range(start..end, "");
|
||||
}
|
||||
|
||||
doc.insert_str(start, &data.unwrap());
|
||||
doc
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue