Skip to content

Commit

Permalink
revert additional change on grid
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 24, 2024
1 parent 70c303f commit 003623f
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions rio-backend/src/crosswords/grid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,42 +207,34 @@ impl<T: GridSquare + Default + PartialEq + Clone> Grid<T> {
min(self.display_offset + positions, self.max_scroll_limit);
}

// Only rotate the entire history if the active region starts at the top.
if region.start == 0 {
// Create scrollback for the new lines.
self.increase_scroll_limit(positions);
// Create scrollback for the new lines.
self.increase_scroll_limit(positions);

// Swap the lines fixed at the top to their target positions after rotation.
//
// Since we've made sure that the rotation will never rotate away the entire region, we
// know that the position of the fixed lines before the rotation must already be
// visible.
//
// We need to start from the bottom, to make sure the fixed lines aren't swapped with
// each other.
for i in (0..region.start.0).rev().map(Line::from) {
self.raw.swap(i, i + positions);
}

// Rotate the entire line buffer upward.
self.raw.rotate(-(positions as isize));

// Swap the fixed lines at the bottom back into position.
let screen_lines = self.screen_lines() as i32;
for i in (region.end.0..screen_lines).rev().map(Line::from) {
self.raw.swap(i, i - positions);
}
} else {
// Rotate lines without moving anything into history.
for i in (region.start.0..region.end.0 - positions as i32).map(Line::from) {
self.raw.swap(i, i + positions);
}
// Swap the lines fixed at the top to their target positions after rotation.
//
// Since we've made sure that the rotation will never rotate away the entire region, we
// know that the position of the fixed lines before the rotation must already be
// visible.
//
// We need to start from the bottom, to make sure the fixed lines aren't swapped with each
// other.
for i in (0..region.start.0).rev().map(Line::from) {
self.raw.swap(i, i + positions);
}

// Rotate the entire line buffer upward.
self.raw.rotate(-(positions as isize));

// Ensure all new lines are fully cleared.
for i in (region.end.0 - positions as i32..region.end.0).map(Line::from) {
let screen_lines = self.screen_lines();
for i in ((screen_lines - positions)..screen_lines).map(Line::from) {
self.raw[i].reset(&self.cursor.template);
}

// Swap the fixed lines at the bottom back into position.
for i in (region.end.0..(screen_lines as i32)).rev().map(Line::from) {
self.raw.swap(i, i - positions);
}
}

pub fn clear_viewport<D>(&mut self)
Expand Down

0 comments on commit 003623f

Please sign in to comment.