summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-18 19:07:41 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-18 19:07:41 +0200
commite7326f0af6f16cf2ff04fbac93bf296a044923f4 (patch)
tree05a309b7faf7a8b6f8c609c128dffa996660f1e4 /core
parent8446fe6de52fa68077d23d39f728f79a29b52f00 (diff)
downloadiced-e7326f0af6f16cf2ff04fbac93bf296a044923f4.tar.gz
iced-e7326f0af6f16cf2ff04fbac93bf296a044923f4.tar.bz2
iced-e7326f0af6f16cf2ff04fbac93bf296a044923f4.zip
Flesh out the `editor` example a bit more
Diffstat (limited to 'core')
-rw-r--r--core/src/renderer/null.rs4
-rw-r--r--core/src/text/editor.rs8
2 files changed, 12 insertions, 0 deletions
diff --git a/core/src/renderer/null.rs b/core/src/renderer/null.rs
index 21597c8e..da0f32de 100644
--- a/core/src/renderer/null.rs
+++ b/core/src/renderer/null.rs
@@ -125,6 +125,10 @@ impl text::Editor for () {
text::editor::Cursor::Caret(Point::ORIGIN)
}
+ fn cursor_position(&self) -> (usize, usize) {
+ (0, 0)
+ }
+
fn selection(&self) -> Option<String> {
None
}
diff --git a/core/src/text/editor.rs b/core/src/text/editor.rs
index 2144715f..13bafc3d 100644
--- a/core/src/text/editor.rs
+++ b/core/src/text/editor.rs
@@ -12,6 +12,8 @@ pub trait Editor: Sized + Default {
fn cursor(&self) -> Cursor;
+ fn cursor_position(&self) -> (usize, usize);
+
fn selection(&self) -> Option<String>;
fn line(&self, index: usize) -> Option<&str>;
@@ -52,6 +54,12 @@ pub enum Action {
Drag(Point),
}
+impl Action {
+ pub fn is_edit(&self) -> bool {
+ matches!(self, Self::Edit(_))
+ }
+}
+
#[derive(Debug, Clone, PartialEq)]
pub enum Edit {
Insert(char),