summaryrefslogtreecommitdiffstats
path: root/graphics
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-17 19:27:51 +0200
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2023-09-17 19:27:51 +0200
commit2897986f2ded7318894a52572bec3d62754ebfaa (patch)
treeb8179908780f022aaed37fe93fcfedd64caaa129 /graphics
parent23d00445ff1225b3e5ca99cb27966143cda8a2ce (diff)
downloadiced-2897986f2ded7318894a52572bec3d62754ebfaa.tar.gz
iced-2897986f2ded7318894a52572bec3d62754ebfaa.tar.bz2
iced-2897986f2ded7318894a52572bec3d62754ebfaa.zip
Notify `Highlighter` of topmost line change
Diffstat (limited to 'graphics')
-rw-r--r--graphics/src/text/editor.rs58
1 files changed, 40 insertions, 18 deletions
diff --git a/graphics/src/text/editor.rs b/graphics/src/text/editor.rs
index fbae287e..47c210bd 100644
--- a/graphics/src/text/editor.rs
+++ b/graphics/src/text/editor.rs
@@ -1,10 +1,12 @@
-use crate::core::text::editor::{self, Action, Cursor, Direction, Motion};
+use crate::core::text::editor::{
+ self, Action, Cursor, Direction, Edit, Motion,
+};
use crate::core::text::highlighter::{self, Highlighter};
use crate::core::text::LineHeight;
use crate::core::{Font, Pixels, Point, Rectangle, Size};
use crate::text;
-use cosmic_text::Edit;
+use cosmic_text::Edit as _;
use std::fmt;
use std::sync::{self, Arc};
@@ -370,22 +372,42 @@ impl editor::Editor for Editor {
}
// Editing events
- Action::Insert(c) => {
- editor
- .action(font_system.raw(), cosmic_text::Action::Insert(c));
- }
- Action::Paste(text) => {
- editor.insert_string(&text, None);
- }
- Action::Enter => {
- editor.action(font_system.raw(), cosmic_text::Action::Enter);
- }
- Action::Backspace => {
- editor
- .action(font_system.raw(), cosmic_text::Action::Backspace);
- }
- Action::Delete => {
- editor.action(font_system.raw(), cosmic_text::Action::Delete);
+ Action::Edit(edit) => {
+ match edit {
+ Edit::Insert(c) => {
+ editor.action(
+ font_system.raw(),
+ cosmic_text::Action::Insert(c),
+ );
+ }
+ Edit::Paste(text) => {
+ editor.insert_string(&text, None);
+ }
+ Edit::Enter => {
+ editor.action(
+ font_system.raw(),
+ cosmic_text::Action::Enter,
+ );
+ }
+ Edit::Backspace => {
+ editor.action(
+ font_system.raw(),
+ cosmic_text::Action::Backspace,
+ );
+ }
+ Edit::Delete => {
+ editor.action(
+ font_system.raw(),
+ cosmic_text::Action::Delete,
+ );
+ }
+ }
+
+ let cursor = editor.cursor();
+ let selection = editor.select_opt().unwrap_or(cursor);
+
+ internal.topmost_line_changed =
+ Some(cursor.min(selection).line);
}
// Mouse events