script: Ask layout to redraw the selection whenever the user moves the

caret in an input element.
This commit is contained in:
Patrick Walton 2015-09-15 16:26:01 -07:00
parent 4a53c873f5
commit 34d9a6091b
3 changed files with 18 additions and 11 deletions

View file

@ -27,9 +27,9 @@ use dom::node::{Node, NodeDamage, NodeTypeId};
use dom::node::{document_from_node, window_from_node}; use dom::node::{document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods; use dom::virtualmethods::VirtualMethods;
use msg::constellation_msg::ConstellationChan; use msg::constellation_msg::ConstellationChan;
use textinput::KeyReaction::{TriggerDefaultAction, DispatchInput, Nothing}; use textinput::KeyReaction::{TriggerDefaultAction, DispatchInput, Nothing, RedrawSelection};
use textinput::Lines::Single; use textinput::Lines::Single;
use textinput::TextInput; use textinput::{TextInput, TextPoint};
use string_cache::Atom; use string_cache::Atom;
use util::str::DOMString; use util::str::DOMString;
@ -599,6 +599,9 @@ impl VirtualMethods for HTMLInputElement {
self.force_relayout(); self.force_relayout();
event.PreventDefault(); event.PreventDefault();
} }
RedrawSelection => {
self.force_relayout();
}
Nothing => (), Nothing => (),
} }
}); });

View file

@ -350,6 +350,9 @@ impl VirtualMethods for HTMLTextAreaElement {
self.force_relayout(); self.force_relayout();
} }
KeyReaction::RedrawSelection => {
self.force_relayout();
}
KeyReaction::Nothing => (), KeyReaction::Nothing => (),
} }
}); });

View file

@ -49,6 +49,7 @@ pub struct TextInput<T: ClipboardProvider> {
pub enum KeyReaction { pub enum KeyReaction {
TriggerDefaultAction, TriggerDefaultAction,
DispatchInput, DispatchInput,
RedrawSelection,
Nothing, Nothing,
} }
@ -366,7 +367,7 @@ impl<T: ClipboardProvider> TextInput<T> {
match key { match key {
Key::A if is_control_key(mods) => { Key::A if is_control_key(mods) => {
self.select_all(); self.select_all();
KeyReaction::Nothing KeyReaction::RedrawSelection
}, },
Key::C if is_control_key(mods) => { Key::C if is_control_key(mods) => {
if let Some(text) = self.get_selection_text() { if let Some(text) = self.get_selection_text() {
@ -397,36 +398,36 @@ impl<T: ClipboardProvider> TextInput<T> {
} }
Key::Left => { Key::Left => {
self.adjust_horizontal_by_one(Direction::Backward, maybe_select); self.adjust_horizontal_by_one(Direction::Backward, maybe_select);
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::Right => { Key::Right => {
self.adjust_horizontal_by_one(Direction::Forward, maybe_select); self.adjust_horizontal_by_one(Direction::Forward, maybe_select);
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::Up => { Key::Up => {
self.adjust_vertical(-1, maybe_select); self.adjust_vertical(-1, maybe_select);
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::Down => { Key::Down => {
self.adjust_vertical(1, maybe_select); self.adjust_vertical(1, maybe_select);
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::Enter | Key::KpEnter => self.handle_return(), Key::Enter | Key::KpEnter => self.handle_return(),
Key::Home => { Key::Home => {
self.edit_point.index = 0; self.edit_point.index = 0;
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::End => { Key::End => {
self.edit_point.index = self.current_line_length(); self.edit_point.index = self.current_line_length();
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::PageUp => { Key::PageUp => {
self.adjust_vertical(-28, maybe_select); self.adjust_vertical(-28, maybe_select);
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::PageDown => { Key::PageDown => {
self.adjust_vertical(28, maybe_select); self.adjust_vertical(28, maybe_select);
KeyReaction::Nothing KeyReaction::RedrawSelection
} }
Key::Tab => KeyReaction::TriggerDefaultAction, Key::Tab => KeyReaction::TriggerDefaultAction,
_ => KeyReaction::Nothing, _ => KeyReaction::Nothing,