aboutsummaryrefslogtreecommitdiff
path: root/src/text/rich.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/text/rich.rs37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/text/rich.rs b/src/text/rich.rs
index ae8bbab..93cefa2 100644
--- a/src/text/rich.rs
+++ b/src/text/rich.rs
@@ -16,7 +16,7 @@ use crate::core::{
Rectangle, Shell, Size, Vector, Widget,
};
use crate::selection::{Selection, SelectionEnd};
-use crate::text::{Catalog, Style, StyleFn};
+use crate::text::{Catalog, Dragging, Style, StyleFn};
/// A bunch of [`Rich`] text.
pub struct Rich<
@@ -184,7 +184,7 @@ struct State<Link> {
paragraph: Paragraph,
is_hovered: bool,
selection: Selection,
- is_dragging: bool,
+ dragging: Option<Dragging>,
last_click: Option<mouse::Click>,
keyboard_modifiers: keyboard::Modifiers,
}
@@ -239,7 +239,7 @@ where
paragraph: Paragraph::default(),
is_hovered: false,
selection: Selection::default(),
- is_dragging: false,
+ dragging: None,
last_click: None,
keyboard_modifiers: keyboard::Modifiers::default(),
})
@@ -475,7 +475,7 @@ where
if viewport.intersection(&bounds).is_none()
&& state.selection == Selection::default()
- && !state.is_dragging
+ && state.dragging.is_none()
{
return;
}
@@ -524,10 +524,10 @@ where
if state.keyboard_modifiers.shift() {
state.selection.change_selection(new_end);
- state.is_dragging = true;
+ state.dragging = Some(Dragging::Grapheme);
} else if state.span_pressed.is_none() {
state.selection.select_range(new_end, new_end);
- state.is_dragging = true;
+ state.dragging = Some(Dragging::Grapheme);
}
}
mouse::click::Kind::Double => {
@@ -536,11 +536,11 @@ where
index,
&state.paragraph,
);
- state.is_dragging = false;
+ state.dragging = None;
}
mouse::click::Kind::Triple => {
state.selection.select_line(line, &state.paragraph);
- state.is_dragging = false;
+ state.dragging = Some(Dragging::Line);
}
}
} else {
@@ -550,7 +550,7 @@ where
Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left))
| Event::Touch(touch::Event::FingerLifted { .. })
| Event::Touch(touch::Event::FingerLost { .. }) => {
- state.is_dragging = false;
+ state.dragging = None;
if !matches!(
event,
Event::Touch(touch::Event::FingerLost { .. })
@@ -578,15 +578,26 @@ where
Event::Mouse(mouse::Event::CursorMoved { .. })
| Event::Touch(touch::Event::FingerMoved { .. }) => {
if let Some(position) = click_position
- && state.is_dragging
+ && let Some(dragging) = state.dragging
{
let (line, index) = state
.grapheme_line_and_index(position)
.unwrap_or((0, 0));
- let new_end = SelectionEnd { line, index };
+ match dragging {
+ Dragging::Grapheme => {
+ let new_end = SelectionEnd { line, index };
- state.selection.change_selection(new_end);
+ state.selection.change_selection(new_end);
+ }
+ Dragging::Word => {}
+ Dragging::Line => {
+ state.selection.change_selection_by_line(
+ line,
+ &state.paragraph,
+ );
+ }
+ };
}
}
Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => {
@@ -695,7 +706,7 @@ where
shell.capture_event();
}
keyboard::Key::Named(key::Named::Escape) => {
- state.is_dragging = false;
+ state.dragging = None;
state.selection = Selection::default();
state.keyboard_modifiers =