aboutsummaryrefslogtreecommitdiff
path: root/src/text
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/text.rs25
-rw-r--r--src/text/rich.rs25
2 files changed, 32 insertions, 18 deletions
diff --git a/src/text.rs b/src/text.rs
index ad5c350..ff5d5a4 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -388,7 +388,7 @@ where
let click_position = cursor.position_in(bounds);
if viewport.intersection(&bounds).is_none()
- && state.selection == Selection::default()
+ && state.selection.is_empty()
&& state.dragging.is_none()
{
return;
@@ -466,7 +466,14 @@ where
state.selection.change_selection(new_end);
}
- Dragging::Word => {}
+ Dragging::Word => {
+ let new_end = SelectionEnd { line, index };
+
+ state.selection.change_selection_by_word(
+ new_end,
+ &state.paragraph,
+ );
+ }
Dragging::Line => {
state.selection.change_selection_by_line(
line,
@@ -491,7 +498,7 @@ where
}
keyboard::Key::Character("a")
if state.keyboard_modifiers.command()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
state.selection.select_all(&state.paragraph);
@@ -499,7 +506,7 @@ where
}
keyboard::Key::Named(key::Named::Home)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.jump() {
state.selection.select_beginning();
@@ -511,7 +518,7 @@ where
}
keyboard::Key::Named(key::Named::End)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.jump() {
state.selection.select_end(&state.paragraph);
@@ -523,7 +530,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowLeft)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_line_beginning();
@@ -539,7 +546,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowRight)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_line_end(&state.paragraph);
@@ -555,7 +562,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowUp)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_beginning();
@@ -569,7 +576,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowDown)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_end(&state.paragraph);
diff --git a/src/text/rich.rs b/src/text/rich.rs
index a30663b..5ca3051 100644
--- a/src/text/rich.rs
+++ b/src/text/rich.rs
@@ -600,7 +600,7 @@ where
let click_position = cursor.position_in(bounds);
if viewport.intersection(&bounds).is_none()
- && state.selection == Selection::default()
+ && state.selection.is_empty()
&& state.dragging.is_none()
{
return;
@@ -720,7 +720,14 @@ where
state.selection.change_selection(new_end);
}
- Dragging::Word => {}
+ Dragging::Word => {
+ let new_end = SelectionEnd { line, index };
+
+ state.selection.change_selection_by_word(
+ new_end,
+ &state.paragraph,
+ );
+ }
Dragging::Line => {
state.selection.change_selection_by_line(
line,
@@ -745,7 +752,7 @@ where
}
keyboard::Key::Character("a")
if state.keyboard_modifiers.command()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
state.selection.select_all(&state.paragraph);
@@ -753,7 +760,7 @@ where
}
keyboard::Key::Named(key::Named::Home)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.jump() {
state.selection.select_beginning();
@@ -765,7 +772,7 @@ where
}
keyboard::Key::Named(key::Named::End)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.jump() {
state.selection.select_end(&state.paragraph);
@@ -777,7 +784,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowLeft)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_line_beginning();
@@ -793,7 +800,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowRight)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_line_end(&state.paragraph);
@@ -809,7 +816,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowUp)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_beginning();
@@ -823,7 +830,7 @@ where
}
keyboard::Key::Named(key::Named::ArrowDown)
if state.keyboard_modifiers.shift()
- && state.selection != Selection::default() =>
+ && !state.selection.is_empty() =>
{
if state.keyboard_modifiers.macos_command() {
state.selection.select_end(&state.paragraph);