Unify Focus and Click updates in widget::text_editor
This commit is contained in:
parent
40eb648f1e
commit
d502c9f16f
1 changed files with 14 additions and 30 deletions
|
|
@ -189,16 +189,12 @@ where
|
||||||
};
|
};
|
||||||
|
|
||||||
match update {
|
match update {
|
||||||
Update::Focus { click, action } => {
|
|
||||||
state.is_focused = true;
|
|
||||||
state.last_click = Some(click);
|
|
||||||
shell.publish(on_edit(action));
|
|
||||||
}
|
|
||||||
Update::Unfocus => {
|
Update::Unfocus => {
|
||||||
state.is_focused = false;
|
state.is_focused = false;
|
||||||
state.is_dragging = false;
|
state.is_dragging = false;
|
||||||
}
|
}
|
||||||
Update::Click { click, action } => {
|
Update::Click { click, action } => {
|
||||||
|
state.is_focused = true;
|
||||||
state.last_click = Some(click);
|
state.last_click = Some(click);
|
||||||
state.is_dragging = true;
|
state.is_dragging = true;
|
||||||
shell.publish(on_edit(action));
|
shell.publish(on_edit(action));
|
||||||
|
|
@ -340,9 +336,8 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Update {
|
enum Update {
|
||||||
Focus { click: mouse::Click, action: Action },
|
|
||||||
Unfocus,
|
|
||||||
Click { click: mouse::Click, action: Action },
|
Click { click: mouse::Click, action: Action },
|
||||||
|
Unfocus,
|
||||||
StopDragging,
|
StopDragging,
|
||||||
Edit(Action),
|
Edit(Action),
|
||||||
Copy,
|
Copy,
|
||||||
|
|
@ -364,31 +359,20 @@ impl Update {
|
||||||
let cursor_position = cursor_position
|
let cursor_position = cursor_position
|
||||||
- Vector::new(padding.top, padding.left);
|
- Vector::new(padding.top, padding.left);
|
||||||
|
|
||||||
if state.is_focused {
|
let click = mouse::Click::new(
|
||||||
let click = mouse::Click::new(
|
cursor_position,
|
||||||
cursor_position,
|
state.last_click,
|
||||||
state.last_click,
|
);
|
||||||
);
|
|
||||||
|
|
||||||
let action = match click.kind() {
|
let action = match click.kind() {
|
||||||
mouse::click::Kind::Single => {
|
mouse::click::Kind::Single => {
|
||||||
Action::Click(cursor_position)
|
Action::Click(cursor_position)
|
||||||
}
|
}
|
||||||
mouse::click::Kind::Double => {
|
mouse::click::Kind::Double => Action::SelectWord,
|
||||||
Action::SelectWord
|
mouse::click::Kind::Triple => Action::SelectLine,
|
||||||
}
|
};
|
||||||
mouse::click::Kind::Triple => {
|
|
||||||
Action::SelectLine
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(Update::Click { click, action })
|
Some(Update::Click { click, action })
|
||||||
} else {
|
|
||||||
Some(Update::Focus {
|
|
||||||
click: mouse::Click::new(cursor_position, None),
|
|
||||||
action: Action::Click(cursor_position),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if state.is_focused {
|
} else if state.is_focused {
|
||||||
Some(Update::Unfocus)
|
Some(Update::Unfocus)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue