mirror of
https://github.com/servo/servo.git
synced 2025-07-23 23:33:43 +01:00
Add/correct documentation comments in textinput
This commit is contained in:
parent
d7e6f8b0f1
commit
e17ed2e6b0
1 changed files with 9 additions and 2 deletions
|
@ -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> {
|
pub fn get_absolute_selection_range(&self) -> Range<usize> {
|
||||||
match self.get_sorted_selection() {
|
match self.get_sorted_selection() {
|
||||||
Some((begin, _end)) =>
|
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);
|
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
|
/// 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.
|
/// adjusted vertically and the process repeats with the remaining adjustment requested.
|
||||||
pub fn adjust_horizontal(&mut self, adjust: isize, select: Selection) {
|
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);
|
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)
|
fn adjust_selection_for_horizontal_change(&mut self, adjust: Direction, select: Selection)
|
||||||
-> bool {
|
-> bool {
|
||||||
if select == Selection::Selected {
|
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 {
|
pub fn len(&self) -> usize {
|
||||||
self.lines.iter().fold(0, |m, l| {
|
self.lines.iter().fold(0, |m, l| {
|
||||||
m + l.len() + 1
|
m + l.len() + 1
|
||||||
|
@ -520,10 +524,12 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
self.selection_begin = None;
|
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 {
|
pub fn get_absolute_insertion_point(&self) -> usize {
|
||||||
self.get_absolute_point_for_text_point(&self.edit_point)
|
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 {
|
pub fn get_absolute_point_for_text_point(&self, text_point: &TextPoint) -> usize {
|
||||||
self.lines.iter().enumerate().fold(0, |acc, (i, val)| {
|
self.lines.iter().enumerate().fold(0, |acc, (i, val)| {
|
||||||
if i < text_point.line {
|
if i < text_point.line {
|
||||||
|
@ -534,6 +540,7 @@ impl<T: ClipboardProvider> TextInput<T> {
|
||||||
}) + text_point.index
|
}) + 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 {
|
pub fn get_text_point_for_absolute_point(&self, abs_point: usize) -> TextPoint {
|
||||||
let mut index = abs_point;
|
let mut index = abs_point;
|
||||||
let mut line = 0;
|
let mut line = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue