aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/textinput.rs
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2016-04-01 12:25:21 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2016-04-01 14:00:49 -0700
commite17ed2e6b0572fd201c126dbe38ea949ca226fe8 (patch)
tree69275df632392d3c01c41bde709302832df5e7a7 /components/script/textinput.rs
parentd7e6f8b0f15326aad413eb1c59fc57e913e309b4 (diff)
downloadservo-e17ed2e6b0572fd201c126dbe38ea949ca226fe8.tar.gz
servo-e17ed2e6b0572fd201c126dbe38ea949ca226fe8.zip
Add/correct documentation comments in textinput
Diffstat (limited to 'components/script/textinput.rs')
-rw-r--r--components/script/textinput.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index ec4af672178..1f0cb0c53d8 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -165,6 +165,9 @@ impl<T: ClipboardProvider> TextInput<T> {
})
}
+ /// Return the selection range as UTF-8 byte offsets from the start of the content.
+ ///
+ /// If there is no selection, returns an empty range at the insertion point.
pub fn get_absolute_selection_range(&self) -> Range<usize> {
match self.get_sorted_selection() {
Some((begin, _end)) =>
@@ -302,7 +305,7 @@ impl<T: ClipboardProvider> TextInput<T> {
self.edit_point.index = min(self.current_line_length(), self.edit_point.index);
}
- /// Adjust the editing point position by a given number of columns. If the adjustment
+ /// Adjust the editing point position by a given number of bytes. If the adjustment
/// requested is larger than is available in the current line, the editing point is
/// adjusted vertically and the process repeats with the remaining adjustment requested.
pub fn adjust_horizontal(&mut self, adjust: isize, select: Selection) {
@@ -339,7 +342,7 @@ impl<T: ClipboardProvider> TextInput<T> {
self.perform_horizontal_adjustment(adjust, select);
}
- // Return whether to cancel the caret move
+ /// Return whether to cancel the caret move
fn adjust_selection_for_horizontal_change(&mut self, adjust: Direction, select: Selection)
-> bool {
if select == Selection::Selected {
@@ -489,6 +492,7 @@ impl<T: ClipboardProvider> TextInput<T> {
}
}
+ /// The length of the content in bytes.
pub fn len(&self) -> usize {
self.lines.iter().fold(0, |m, l| {
m + l.len() + 1
@@ -520,10 +524,12 @@ impl<T: ClipboardProvider> TextInput<T> {
self.selection_begin = None;
}
+ /// Get the insertion point as a byte offset from the start of the content.
pub fn get_absolute_insertion_point(&self) -> usize {
self.get_absolute_point_for_text_point(&self.edit_point)
}
+ /// Convert a TextPoint into a byte offset from the start of the content.
pub fn get_absolute_point_for_text_point(&self, text_point: &TextPoint) -> usize {
self.lines.iter().enumerate().fold(0, |acc, (i, val)| {
if i < text_point.line {
@@ -534,6 +540,7 @@ impl<T: ClipboardProvider> TextInput<T> {
}) + text_point.index
}
+ /// Convert a byte offset from the start of the content into a TextPoint.
pub fn get_text_point_for_absolute_point(&self, abs_point: usize) -> TextPoint {
let mut index = abs_point;
let mut line = 0;