mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #21975 - pyfisch:fix-selection, r=paulrouget
Correctly determine text selection direction Add some debug! output. Closes #21891 <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21891 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21975) <!-- Reviewable:end -->
This commit is contained in:
commit
c3c68983b7
1 changed files with 24 additions and 5 deletions
|
@ -293,6 +293,12 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
|
||||
// Check that the selection is valid.
|
||||
fn assert_ok_selection(&self) {
|
||||
debug!(
|
||||
"edit_point: {:?}, selection_origin: {:?}, direction: {:?}",
|
||||
self.edit_point,
|
||||
self.selection_origin,
|
||||
self.selection_direction
|
||||
);
|
||||
if let Some(begin) = self.selection_origin {
|
||||
debug_assert!(begin.line < self.lines.len());
|
||||
debug_assert!(begin.index <= self.lines[begin.line].len());
|
||||
|
@ -506,11 +512,6 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
if self.selection_origin.is_none() {
|
||||
self.selection_origin = Some(self.edit_point);
|
||||
}
|
||||
|
||||
self.selection_direction = match adjust {
|
||||
Direction::Backward => SelectionDirection::Backward,
|
||||
Direction::Forward => SelectionDirection::Forward,
|
||||
};
|
||||
} else {
|
||||
if self.has_selection() {
|
||||
self.edit_point = match adjust {
|
||||
|
@ -524,6 +525,23 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
false
|
||||
}
|
||||
|
||||
/// Update the field selection_direction.
|
||||
///
|
||||
/// When the edit_point (or focus) is before the selection_origin (or anchor)
|
||||
/// you have a backward selection. Otherwise you have a forward selection.
|
||||
fn update_selection_direction(&mut self) {
|
||||
debug!(
|
||||
"edit_point: {:?}, selection_origin: {:?}",
|
||||
self.edit_point,
|
||||
self.selection_origin
|
||||
);
|
||||
self.selection_direction = if Some(self.edit_point) < self.selection_origin {
|
||||
SelectionDirection::Backward
|
||||
} else {
|
||||
SelectionDirection::Forward
|
||||
}
|
||||
}
|
||||
|
||||
fn perform_horizontal_adjustment(&mut self, adjust: isize, select: Selection) {
|
||||
if adjust < 0 {
|
||||
let remaining = self.edit_point.index;
|
||||
|
@ -548,6 +566,7 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
);
|
||||
}
|
||||
}
|
||||
self.update_selection_direction();
|
||||
self.assert_ok_selection();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue