ElyTable: a cell scrolls in by the least amount; a drag never scrolls under the pointer (T-02)

This commit is contained in:
ZacharyZhang-NY committed 2026-10-09 09:47:10 -04:00
1 parent c52e1a3b16
commit ecf977364b
6 files changed
+31 -6

No files matched your search

+3 -1
View File
@@ -375,8 +375,9 @@ impl LokView {
}
if batch.cursor != self.cursor {
self.moves += 1;
// A moved cursor stays in view.
// A moved cursor stays in view, but not mid-drag.
if self.viewport.1 > 0.0
&& !self.dragging
&& let Some(cursor) = batch.cursor
{
self.show(cursor, cx);
@@ -385,6 +386,7 @@ impl LokView {
// A moved cell cursor stays in view too.
if batch.cell.cursor != self.cell.cursor
&& self.viewport.1 > 0.0
&& !self.dragging
&& let Some(cell) = batch.cell.cursor
{
self.show(cell, cx);
+11 -4
View File
@@ -61,11 +61,11 @@ impl LokView {
let need = self.print_of((x + w + vw + fx, y + h + vh + fy));
self.reach = (self.reach.0.max(need.0), self.reach.1.max(need.1));
}
if x >= fx && (x < fx + self.scroll.0 || x + w > fx + self.scroll.0 + vw) {
self.scroll.0 = x - fx - vw / 2;
if x >= fx {
self.scroll.0 = least(x - fx, w, self.scroll.0, vw);
}
if y >= fy && (y < fy + self.scroll.1 || y + h > fy + self.scroll.1 + vh) {
self.scroll.1 = y - fy - vh / 3;
if y >= fy {
self.scroll.1 = least(y - fy, h, self.scroll.1, vh);
}
self.clamp_scroll();
cx.notify();
@@ -172,3 +172,10 @@ impl LokView {
})
}
}
/// The scroll nearest `scroll` that shows `start..start + len`.
fn least(start: i32, len: i32, scroll: i32, view: i32) -> i32 {
// A span wider than the view keeps covering it.
let end = start + len - view;
scroll.clamp(start.min(end), start.max(end))
}
+10
View File
@@ -202,6 +202,16 @@ fn a_sheet_brings_far_cut_and_frozen_cells_into_view() {
let cut = (width - 200, 0, 1280, 256);
view.show(cut, cx);
assert!(view.scroll.0 > 0 && shows(view, cut), "a cell cut at the right edge comes into view");
let (x, _, w, _) = view.tile_rect(cut);
assert_eq!(view.scroll.0, x + w - width, "it scrolls no further than the cell's edge");
let before = view.scroll;
view.show((0, 0, view.print_of((x + w + width, 0)).0, 256), cx);
assert_eq!(view.scroll, before, "a cell wider than the view and covering it keeps still");
view.dragging = true;
let cell = crate::Cell { cursor: Some((1418, 90_000, 1280, 277)), ..crate::Cell::default() };
view.apply_batch(crate::Events { cell, ..crate::Events::default() }, None, cx);
assert_eq!(view.scroll, before, "a drag does not scroll under the pointer");
view.dragging = false;
view.scroll = (0, 0);
view.set_frozen((0, 600), cx);
let frozen = view.place((0, 300)).y;