aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/textcontrol.rs
diff options
context:
space:
mode:
authorThomas Delacour <thomas.delacour@mongodb.com>2019-04-13 14:35:49 -0400
committerThomas Delacour <thomas.delacour@mongodb.com>2019-05-16 15:33:24 -0400
commit14c8bbb49de03bc9d3757167df47df7b389cfd5d (patch)
treeea9683a9c26020148c4b89a415fc111ce5a38254 /components/script/dom/textcontrol.rs
parentce93e017c65ba8e987226c843df7fc923af5957a (diff)
downloadservo-14c8bbb49de03bc9d3757167df47df7b389cfd5d.tar.gz
servo-14c8bbb49de03bc9d3757167df47df7b389cfd5d.zip
ISSUE-20455: introduce stronger types for textinput indexing
Diffstat (limited to 'components/script/dom/textcontrol.rs')
-rw-r--r--components/script/dom/textcontrol.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/components/script/dom/textcontrol.rs b/components/script/dom/textcontrol.rs
index 8e9421996a8..0f215b4cbc8 100644
--- a/components/script/dom/textcontrol.rs
+++ b/components/script/dom/textcontrol.rs
@@ -15,7 +15,7 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::event::{EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget;
use crate::dom::node::{window_from_node, Node, NodeDamage};
-use crate::textinput::{SelectionDirection, SelectionState, TextInput};
+use crate::textinput::{SelectionDirection, SelectionState, TextInput, UTF8Bytes};
use script_traits::ScriptToConstellationChan;
pub trait TextControlElement: DerivedFrom<EventTarget> + DerivedFrom<Node> {
@@ -177,7 +177,8 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
// change the selection state in order to replace the text in the range.
let original_selection_state = self.textinput.borrow().selection_state();
- let content_length = self.textinput.borrow().len() as u32;
+ let UTF8Bytes(content_length) = self.textinput.borrow().len_utf8();
+ let content_length = content_length as u32;
// Step 5
if start > content_length {
@@ -262,11 +263,13 @@ impl<'a, E: TextControlElement> TextControlSelection<'a, E> {
}
fn start(&self) -> u32 {
- self.textinput.borrow().selection_start_offset() as u32
+ let UTF8Bytes(offset) = self.textinput.borrow().selection_start_offset();
+ offset as u32
}
fn end(&self) -> u32 {
- self.textinput.borrow().selection_end_offset() as u32
+ let UTF8Bytes(offset) = self.textinput.borrow().selection_end_offset();
+ offset as u32
}
fn direction(&self) -> SelectionDirection {