mirror of
https://github.com/servo/servo.git
synced 2025-08-07 22:45:34 +01:00
Auto merge of #11616 - ConnorGBrewster:navigation_delta, r=asajeffrey
Add support for navigating by a delta <!-- Please describe your changes on the following line: --> This adds support for passing a delta with `NavigationDirection`. This will be used with `history.go` r? @asajeffrey --- <!-- 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 do not require tests because I am unsure how to write a test for this <!-- 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="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11616) <!-- Reviewable:end -->
This commit is contained in:
commit
a80767993b
5 changed files with 31 additions and 30 deletions
|
@ -1278,34 +1278,35 @@ impl<Message, LTF, STF> Constellation<Message, LTF, STF>
|
|||
// Get the ids for the previous and next pipelines.
|
||||
let (prev_pipeline_id, next_pipeline_id) = match self.frames.get_mut(&frame_id) {
|
||||
Some(frame) => {
|
||||
let prev = frame.current;
|
||||
let next = match direction {
|
||||
NavigationDirection::Forward => {
|
||||
match frame.next.pop() {
|
||||
None => {
|
||||
warn!("no next page to navigate to");
|
||||
return;
|
||||
},
|
||||
Some(next) => {
|
||||
frame.prev.push(frame.current);
|
||||
next
|
||||
},
|
||||
NavigationDirection::Forward(delta) => {
|
||||
if delta > frame.next.len() && delta > 0 {
|
||||
return warn!("Invalid navigation delta");
|
||||
}
|
||||
let new_next_len = frame.next.len() - (delta - 1);
|
||||
frame.prev.push(frame.current);
|
||||
frame.prev.extend(frame.next.drain(new_next_len..).rev());
|
||||
frame.current = match frame.next.pop() {
|
||||
Some(frame) => frame,
|
||||
None => return warn!("Could not get next frame for forward navigation"),
|
||||
};
|
||||
frame.current
|
||||
}
|
||||
NavigationDirection::Back => {
|
||||
match frame.prev.pop() {
|
||||
None => {
|
||||
warn!("no previous page to navigate to");
|
||||
return;
|
||||
},
|
||||
Some(prev) => {
|
||||
frame.next.push(frame.current);
|
||||
prev
|
||||
},
|
||||
NavigationDirection::Back(delta) => {
|
||||
if delta > frame.prev.len() && delta > 0 {
|
||||
return warn!("Invalid navigation delta");
|
||||
}
|
||||
let new_prev_len = frame.prev.len() - (delta - 1);
|
||||
frame.next.push(frame.current);
|
||||
frame.next.extend(frame.prev.drain(new_prev_len..).rev());
|
||||
frame.current = match frame.prev.pop() {
|
||||
Some(frame) => frame,
|
||||
None => return warn!("Could not get prev frame for back navigation"),
|
||||
};
|
||||
frame.current
|
||||
}
|
||||
};
|
||||
let prev = frame.current;
|
||||
frame.current = next;
|
||||
(prev, next)
|
||||
},
|
||||
None => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue