Avoid drag on double or triple click for now in TextEditor
This commit is contained in:
parent
c9dbccba46
commit
45c5cfe577
2 changed files with 32 additions and 24 deletions
|
|
@ -61,6 +61,10 @@ impl Click {
|
||||||
self.kind
|
self.kind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn position(&self) -> Point {
|
||||||
|
self.position
|
||||||
|
}
|
||||||
|
|
||||||
fn is_consecutive(&self, new_position: Point, time: Instant) -> bool {
|
fn is_consecutive(&self, new_position: Point, time: Instant) -> bool {
|
||||||
let duration = if time > self.time {
|
let duration = if time > self.time {
|
||||||
Some(time - self.time)
|
Some(time - self.time)
|
||||||
|
|
|
||||||
|
|
@ -162,8 +162,8 @@ where
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
is_dragging: bool,
|
|
||||||
last_click: Option<mouse::Click>,
|
last_click: Option<mouse::Click>,
|
||||||
|
drag_click: Option<mouse::click::Kind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Message, Renderer> Widget<Message, Renderer>
|
impl<'a, Message, Renderer> Widget<Message, Renderer>
|
||||||
|
|
@ -179,8 +179,8 @@ where
|
||||||
fn state(&self) -> widget::tree::State {
|
fn state(&self) -> widget::tree::State {
|
||||||
widget::tree::State::new(State {
|
widget::tree::State::new(State {
|
||||||
is_focused: false,
|
is_focused: false,
|
||||||
is_dragging: false,
|
|
||||||
last_click: None,
|
last_click: None,
|
||||||
|
drag_click: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -238,18 +238,27 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
match update {
|
match update {
|
||||||
Update::Click { click, action } => {
|
Update::Click(click) => {
|
||||||
|
let action = match click.kind() {
|
||||||
|
mouse::click::Kind::Single => {
|
||||||
|
Action::Click(click.position())
|
||||||
|
}
|
||||||
|
mouse::click::Kind::Double => Action::SelectWord,
|
||||||
|
mouse::click::Kind::Triple => Action::SelectLine,
|
||||||
|
};
|
||||||
|
|
||||||
state.is_focused = true;
|
state.is_focused = true;
|
||||||
state.is_dragging = true;
|
|
||||||
state.last_click = Some(click);
|
state.last_click = Some(click);
|
||||||
|
state.drag_click = Some(click.kind());
|
||||||
|
|
||||||
shell.publish(on_edit(action));
|
shell.publish(on_edit(action));
|
||||||
}
|
}
|
||||||
Update::Unfocus => {
|
Update::Unfocus => {
|
||||||
state.is_focused = false;
|
state.is_focused = false;
|
||||||
state.is_dragging = false;
|
state.drag_click = None;
|
||||||
}
|
}
|
||||||
Update::StopDragging => {
|
Update::Release => {
|
||||||
state.is_dragging = false;
|
state.drag_click = None;
|
||||||
}
|
}
|
||||||
Update::Edit(action) => {
|
Update::Edit(action) => {
|
||||||
shell.publish(on_edit(action));
|
shell.publish(on_edit(action));
|
||||||
|
|
@ -393,9 +402,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Update {
|
enum Update {
|
||||||
Click { click: mouse::Click, action: Action },
|
Click(mouse::Click),
|
||||||
Unfocus,
|
Unfocus,
|
||||||
StopDragging,
|
Release,
|
||||||
Edit(Action),
|
Edit(Action),
|
||||||
Copy,
|
Copy,
|
||||||
Paste,
|
Paste,
|
||||||
|
|
@ -423,15 +432,7 @@ impl Update {
|
||||||
state.last_click,
|
state.last_click,
|
||||||
);
|
);
|
||||||
|
|
||||||
let action = match click.kind() {
|
Some(Update::Click(click))
|
||||||
mouse::click::Kind::Single => {
|
|
||||||
Action::Click(cursor_position)
|
|
||||||
}
|
|
||||||
mouse::click::Kind::Double => Action::SelectWord,
|
|
||||||
mouse::click::Kind::Triple => Action::SelectLine,
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(Update::Click { click, action })
|
|
||||||
} else if state.is_focused {
|
} else if state.is_focused {
|
||||||
Some(Update::Unfocus)
|
Some(Update::Unfocus)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -439,14 +440,17 @@ impl Update {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mouse::Event::ButtonReleased(mouse::Button::Left) => {
|
mouse::Event::ButtonReleased(mouse::Button::Left) => {
|
||||||
Some(Update::StopDragging)
|
Some(Update::Release)
|
||||||
}
|
}
|
||||||
mouse::Event::CursorMoved { .. } if state.is_dragging => {
|
mouse::Event::CursorMoved { .. } => match state.drag_click {
|
||||||
let cursor_position = cursor.position_in(bounds)?
|
Some(mouse::click::Kind::Single) => {
|
||||||
- Vector::new(padding.top, padding.left);
|
let cursor_position = cursor.position_in(bounds)?
|
||||||
|
- Vector::new(padding.top, padding.left);
|
||||||
|
|
||||||
edit(Action::Drag(cursor_position))
|
edit(Action::Drag(cursor_position))
|
||||||
}
|
}
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
Event::Keyboard(event) => match event {
|
Event::Keyboard(event) => match event {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue