aboutsummaryrefslogtreecommitdiff
path: root/src/text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/text.rs')
-rw-r--r--src/text.rs67
1 files changed, 30 insertions, 37 deletions
diff --git a/src/text.rs b/src/text.rs
index f911a39..b407cd5 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -18,28 +18,28 @@
//! |`Shift + Opt + End`<br>`Shift + Cmd + Down Arrow`|`Shift + Ctrl + End`|Selects to the end of the paragraph|
mod rich;
-use iced_widget::{
- core::{
- self, Color, Element, Event, Font, Layout, Length, Pixels, Point, Size,
- Theme, Widget, alignment, clipboard,
- keyboard::{self, key},
- layout,
- mouse::{self, click},
- renderer,
- text::{self, Paragraph as _},
- touch,
- widget::{
- Operation,
- text::Format,
- tree::{self, Tree},
- },
- },
- graphics::text::Paragraph,
-};
+use iced_widget::graphics::text::Paragraph;
pub use rich::Rich;
use text::{Alignment, LineHeight, Shaping, Wrapping};
pub use text::{Fragment, Highlighter, IntoFragment, Span};
+use crate::core::alignment;
+use crate::core::clipboard;
+use crate::core::keyboard::{self, key};
+use crate::core::layout;
+use crate::core::mouse;
+use crate::core::mouse::click;
+use crate::core::renderer;
+use crate::core::text;
+use crate::core::text::paragraph::Paragraph as _;
+use crate::core::touch;
+use crate::core::widget::Operation;
+use crate::core::widget::text::Format;
+use crate::core::widget::tree::{self, Tree};
+use crate::core::{
+ self, Color, Element, Event, Font, Layout, Length, Pixels, Point, Size,
+ Theme, Widget,
+};
use crate::selection::{Selection, SelectionEnd};
/// A bunch of text.
@@ -262,7 +262,7 @@ where
let state = tree.state.downcast_mut::<State>();
let bounds = layout.bounds();
- let click_position = cursor.position_over(bounds);
+ let click_position = cursor.position_in(bounds);
if viewport.intersection(&bounds).is_none()
&& state.selection == Selection::default()
@@ -278,24 +278,18 @@ where
match event {
Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left))
| Event::Touch(touch::Event::FingerPressed { .. }) => {
- if let Some(cursor_position) = click_position {
- let target =
- cursor_position - core::Vector::new(bounds.x, bounds.y);
-
+ if let Some(position) = click_position {
let click = mouse::Click::new(
- cursor_position,
+ position,
mouse::Button::Left,
state.last_click,
);
match click.kind() {
click::Kind::Single => {
- let (line, index) = if target != Point::ORIGIN {
- state.grapheme_line_and_index(target)
- } else {
- None
- }
- .unwrap_or((0, 0));
+ let (line, index) = state
+ .grapheme_line_and_index(position)
+ .unwrap_or((0, 0));
let new_end = SelectionEnd { line, index };
@@ -309,7 +303,7 @@ where
}
click::Kind::Double => {
let (line, index) = state
- .grapheme_line_and_index(target)
+ .grapheme_line_and_index(position)
.unwrap_or((0, 0));
state.selection.select_word(
@@ -321,7 +315,7 @@ where
}
click::Kind::Triple => {
let (line, _) = state
- .grapheme_line_and_index(target)
+ .grapheme_line_and_index(position)
.unwrap_or((0, 0));
state.selection.select_line(line, &state.paragraph);
@@ -343,13 +337,12 @@ where
}
Event::Mouse(mouse::Event::CursorMoved { .. })
| Event::Touch(touch::Event::FingerMoved { .. }) => {
- if let Some(cursor_position) = click_position
+ if let Some(position) = click_position
&& state.is_dragging
{
- let target =
- cursor_position - core::Vector::new(bounds.x, bounds.y);
- let (line, index) =
- state.grapheme_line_and_index(target).unwrap_or((0, 0));
+ let (line, index) = state
+ .grapheme_line_and_index(position)
+ .unwrap_or((0, 0));
let new_end = SelectionEnd { line, index };