R5.3: ElyDoc drags the cursor's table borders, one kernel command per drop at the read's revision; three rounds used, last fixes tested

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-14 10:03:47 -04:00
1 parent d07f0ddb7c
commit e6e5aea7a1
21 files changed
+832 -15

No files matched your search

+264
View File
@@ -0,0 +1,264 @@
//! Dragging the cursor's table borders (DOC-07).
use gpui::{Bounds, Context, CursorStyle, Pixels, Point, px, size};
use super::LokView;
use crate::table::{Lines, Table};
use crate::{Doc, LokError};
/// Least gap the kernel keeps between lines, in twips.
const GAP: i32 = 40;
/// A border, as `.uno:TableChangeCurrentBorderPosition` names it.
#[derive(Clone, Copy, Debug, PartialEq)]
pub(super) enum Side {
ColumnLeft,
Column(u16),
ColumnRight,
Row(u16),
RowBottom,
}
impl Side {
/// Column lines stand upright and move across.
fn upright(self) -> bool {
matches!(self, Side::ColumnLeft | Side::Column(_) | Side::ColumnRight)
}
fn kind(self) -> &'static str {
match self {
Side::ColumnLeft => "column-left",
Side::Column(_) => "column-middle",
Side::ColumnRight => "column-right",
Side::Row(_) => "row-middle",
Side::RowBottom => "row-right",
}
}
fn index(self) -> u16 {
match self {
Side::Column(index) | Side::Row(index) => index,
_ => 0,
}
}
}
/// A held border, with the table read it came from.
#[derive(Clone)]
pub(super) struct Held {
side: Side,
/// The pointer's offset from the line when pressed.
grab: i32,
from: i32,
to: i32,
table: Table,
doc: Doc,
}
/// The cursor's table as last read, and a held border.
#[derive(Default)]
pub(super) struct Borders {
table: Option<(Table, Doc)>,
/// The revision of the batch the table came from.
read: u64,
held: Option<Held>,
hover: Option<CursorStyle>,
}
/// Each border: side, place, span and room, in twips.
fn lines(table: &Table) -> Vec<(Side, i32, (i32, i32), i32)> {
let (columns, rows) = (&table.columns, &table.rows);
let down = (rows.offset + rows.left, rows.offset + rows.right);
let across = (columns.offset + columns.left, columns.offset + columns.right);
let mut upright = vec![(Side::ColumnLeft, across.0)];
upright.extend(inner(columns).map(|(index, at)| (Side::Column(index), at)));
upright.push((Side::ColumnRight, across.1));
let mut level: Vec<_> = inner(rows).map(|(index, at)| (Side::Row(index), at)).collect();
level.push((Side::RowBottom, down.1));
let mut lines = spaced(&upright, None, down);
lines.extend(spaced(&level, Some(down.0), across));
lines
}
/// Gives each line its span and nearest neighbour's distance.
fn spaced(stops: &[(Side, i32)], before: Option<i32>, span: (i32, i32)) -> Vec<(Side, i32, (i32, i32), i32)> {
let places: Vec<i32> = before.into_iter().chain(stops.iter().map(|&(_, at)| at)).collect();
let skip = places.len() - stops.len();
let room = |i: usize| {
let prev = i.checked_sub(1).map(|j| places[i] - places[j]);
prev.into_iter().chain(places.get(i + 1).map(|next| next - places[i])).min().unwrap_or(i32::MAX)
};
stops.iter().enumerate().map(|(i, &(side, at))| (side, at, span, room(i + skip))).collect()
}
fn inner(lines: &Lines) -> impl Iterator<Item = (u16, i32)> + '_ {
lines.inner.iter().enumerate().filter(|(_, line)| !line.hidden).map(|(index, line)| (index as u16, lines.offset + line.position))
}
/// `offset` as the kernel will clamp it.
fn clamp(table: &Table, side: Side, offset: i32) -> i32 {
let axis = if side.upright() { &table.columns } else { &table.rows };
let (first, last) = (axis.inner.first(), axis.inner.last());
let (at, low, high) = match side {
Side::ColumnLeft => (axis.left, i32::MIN, first.map_or(axis.right, |line| line.position) - GAP),
Side::ColumnRight | Side::RowBottom => (axis.right, last.map_or(axis.left, |line| line.position) + GAP, i32::MAX),
Side::Column(index) | Side::Row(index) => {
let line = axis.inner[usize::from(index)];
(line.position, line.min, (line.max - GAP).max(line.min))
}
};
(at.saturating_add(offset)).clamp(low, high) - at
}
impl LokView {
/// Takes the cursor's table from a batch at `revision`.
pub(super) fn read_borders(&mut self, table: Option<Table>, revision: u64) {
if revision < self.borders.read {
log::debug!("lok: table read at {revision} is older than {}", self.borders.read);
return;
}
if table.is_none() {
self.borders.hover = None;
}
let mut doc = self.doc.clone();
doc.rev = revision;
self.borders.read = revision;
self.borders.table = table.map(|table| (table, doc));
}
/// The border under `position`; short cells keep their middles.
fn border_at(&self, position: Point<Pixels>) -> Option<(Side, i32)> {
let (table, _) = self.borders.table.as_ref()?;
lines(table).into_iter().find_map(|(side, at, (start, end), room)| {
let reach = self.handle_size.min(px(self.geom.px_of(room) / 4.0));
let (from, to) = if side.upright() {
(self.window_point((at, start)), self.window_point((at, end)))
} else {
(self.window_point((start, at)), self.window_point((end, at)))
};
let (near, along, low, high) = if side.upright() {
((from.x - position.x).abs(), position.y, from.y, to.y)
} else {
((from.y - position.y).abs(), position.x, from.x, to.x)
};
(near <= reach && along >= low - reach && along <= high + reach).then_some((side, at))
})
}
/// Holds the border under `position`, if any.
pub(super) fn hold_border(&mut self, position: Point<Pixels>) -> bool {
let Some(((side, at), (table, doc))) = self.border_at(position).zip(self.borders.table.clone()) else {
return false;
};
let (x, y) = self.doc_point(position);
let grab = if side.upright() { x } else { y } - at;
log::info!("lok: table border {} {} held", side.kind(), side.index());
self.borders.held = Some(Held { side, grab, from: at, to: at, table, doc });
true
}
/// A held border follows the pointer; a hovered one shows.
pub(super) fn move_border(&mut self, position: Point<Pixels>) -> bool {
let Some(held) = &self.borders.held else {
let side = self.border_at(position).map(|(side, _)| side);
self.borders.hover = side.map(|side| if side.upright() { CursorStyle::ResizeColumn } else { CursorStyle::ResizeRow });
return false;
};
let (x, y) = self.doc_point(position);
let want = if held.side.upright() { x } else { y } - held.grab;
let to = held.from + clamp(&held.table, held.side, want - held.from);
if let Some(held) = self.borders.held.as_mut() {
held.to = to;
}
true
}
/// Lets go at `position`: one command at the read's revision.
pub(super) fn drop_border(&mut self, position: Point<Pixels>, cx: &mut Context<Self>) -> bool {
if !self.move_border(position) {
return false;
}
let Some(held) = self.borders.held.take() else {
return false;
};
let offset = held.to - held.from;
if offset == 0 {
log::info!("lok: table border let go in place");
return true;
}
log::info!("lok: table border {} {} moves {offset}", held.side.kind(), held.side.index());
let (index, offset) = (held.side.index().to_string(), offset.to_string());
if let Err(error) = self.run_at(&held.doc, "table.border", &[held.side.kind(), &index, &offset]) {
cx.emit(LokError(format!("the table border did not move: {error}")));
}
true
}
pub(super) fn holds_border(&self) -> bool {
self.borders.held.is_some()
}
/// The pointer a border asks for, while held or hovered.
pub(super) fn border_pointer(&self) -> Option<CursorStyle> {
match &self.borders.held {
Some(held) if held.side.upright() => Some(CursorStyle::ResizeColumn),
Some(_) => Some(CursorStyle::ResizeRow),
None => self.borders.hover,
}
}
/// The guide line of a held border, in window pixels.
pub(super) fn guide(&self) -> Option<Bounds<Pixels>> {
let held = self.borders.held.as_ref()?;
let (_, _, (start, end), _) = lines(&held.table).into_iter().find(|&(side, ..)| side == held.side)?;
Some(if held.side.upright() {
let (top, bottom) = (self.window_point((held.to, start)), self.window_point((held.to, end)));
Bounds { origin: top, size: size(px(1.0), bottom.y - top.y) }
} else {
let (left, right) = (self.window_point((start, held.to)), self.window_point((end, held.to)));
Bounds { origin: left, size: size(right.x - left.x, px(1.0)) }
})
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::table::Line;
fn table() -> Table {
let line = |position, min, max| Line { position, min, max, hidden: false };
Table {
columns: Lines { left: 0, right: 9000, offset: 1000, inner: vec![line(3000, 300, 6000), line(6000, 3300, 8700)] },
rows: Lines { left: 0, right: 800, offset: 2000, inner: vec![line(400, 100, 800)] },
}
}
#[test]
fn borders_lie_where_the_kernel_puts_them() {
let sides: Vec<_> = lines(&table()).into_iter().map(|(side, at, _, room)| (side, at, room)).collect();
assert_eq!(
sides,
[
(Side::ColumnLeft, 1000, 3000),
(Side::Column(0), 4000, 3000),
(Side::Column(1), 7000, 3000),
(Side::ColumnRight, 10_000, 3000),
(Side::Row(0), 2400, 400),
(Side::RowBottom, 2800, 400),
]
);
}
#[test]
fn a_drag_clamps_as_the_kernel_does() {
let table = table();
assert_eq!(clamp(&table, Side::Column(0), 500), 500, "inside its bounds");
assert_eq!(clamp(&table, Side::Column(0), 9000), 2960, "up to max less the gap");
assert_eq!(clamp(&table, Side::Column(1), -9000), -2700, "down to min");
assert_eq!(clamp(&table, Side::ColumnLeft, 5000), 2960, "short of the first line");
assert_eq!(clamp(&table, Side::ColumnRight, -8000), -2960, "past the last line");
assert_eq!(clamp(&table, Side::RowBottom, -800), -360, "a row keeps the gap");
assert_eq!(clamp(&table, Side::Row(0), 500), 360, "max less the gap");
}
}
+10 -2
View File
@@ -314,7 +314,7 @@ impl LokView {
};
window.focus(&self.focus, cx);
self.right_at = (event.button == MouseButton::Right).then_some(event.position);
if event.button == MouseButton::Left && self.grab(event.position) {
if event.button == MouseButton::Left && (self.grab(event.position) || self.hold_border(event.position)) {
cx.notify();
return;
}
@@ -334,6 +334,10 @@ impl LokView {
_: &mut Window,
cx: &mut Context<Self>,
) {
if self.drop_border(event.position, cx) {
cx.notify();
return;
}
if let Some(grip) = self.grip.take() {
let to = self.doc_point(event.position);
log::info!("lok: handle released");
@@ -366,7 +370,7 @@ impl LokView {
window: &mut Window,
cx: &mut Context<Self>,
) {
if self.dragging || self.grip.is_some() {
if self.dragging || self.grip.is_some() || self.holds_border() {
self.on_mouse_up(event, window, cx);
}
}
@@ -383,6 +387,10 @@ impl LokView {
cx.notify();
return;
}
if self.move_border(event.position) {
cx.notify();
return;
}
if self.dragging && event.pressed_button == Some(MouseButton::Left) {
self.mouse(2, event.position, 1, 1, &event.modifiers);
} else if event.pressed_button.is_none() {
+22 -3
View File
@@ -2,8 +2,8 @@
use ely_gpui_component::theme::ActiveTheme;
use gpui::{
BorderStyle, Bounds, ContentMask, Context, Corners, CursorStyle, Edges, ElementInputHandler,
InteractiveElement, IntoElement, MouseButton, ParentElement, Render, Role,
BorderStyle, Bounds, ContentMask, Context, Corners, CursorStyle, DispatchPhase, Edges,
ElementInputHandler, InteractiveElement, IntoElement, MouseButton, MouseMoveEvent, ParentElement, Render, Role,
StatefulInteractiveElement, Styled, Window, canvas, div, fill, outline, px, quad, size,
transparent_black,
};
@@ -59,7 +59,7 @@ impl Render for LokView {
.aria_value(self.a11y.text.clone())
.key_context(CONTEXT)
.track_focus(&self.focus)
.cursor(self.pointer)
.cursor(self.border_pointer().unwrap_or(self.pointer))
.size_full()
.overflow_hidden()
.bg(canvas_color)
@@ -164,6 +164,9 @@ impl Render for LokView {
));
}
}
if let Some(guide) = painted.guide {
window.paint_quad(fill(guide, frame_color));
}
if let Some(caret) = painted.caret.filter(|_| focus.is_focused(window))
{
let caret = Bounds {
@@ -173,6 +176,19 @@ impl Render for LokView {
window.paint_quad(fill(caret, caret_color));
}
});
if painted.guide.is_some() {
// A held border follows the pointer out of the view.
let this = this.clone();
window.on_mouse_event(move |event: &MouseMoveEvent, phase, _, app| {
if phase == DispatchPhase::Bubble {
this.update(app, |view, cx| {
if view.move_border(event.position) {
cx.notify();
}
});
}
});
}
window.handle_input(&focus, ElementInputHandler::new(bounds, this), app);
},
)
@@ -196,6 +212,8 @@ pub(super) struct Painted {
pub(super) frame: Option<(Bounds<Pixels>, Vec<Bounds<Pixels>>)>,
/// The references of a formula being typed.
pub(super) marks: Vec<(Bounds<Pixels>, gpui::Hsla)>,
/// A held table border's guide line.
pub(super) guide: Option<Bounds<Pixels>>,
}
impl LokView {
@@ -357,6 +375,7 @@ impl LokView {
cell: self.cell.cursor.map(rect),
frame,
marks: self.marks(),
guide: self.guide(),
}
}
}
+1
View File
@@ -1,5 +1,6 @@
use super::*;
mod borders;
mod clip;
mod commands;
mod fit;
+301
View File
@@ -0,0 +1,301 @@
use super::*;
use crate::client::tests::poll_until;
use gpui::{CursorStyle, MouseButton, MouseDownEvent, MouseUpEvent, TestAppContext};
const TABLE: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
<office:body><office:text>
<table:table table:name="T"><table:table-column table:number-columns-repeated="2"/>
<table:table-row><table:table-cell><text:p>left</text:p></table:table-cell><table:table-cell><text:p>right</text:p></table:table-cell></table:table-row>
<table:table-row><table:table-cell><text:p>down</text:p></table:table-cell><table:table-cell><text:p>more</text:p></table:table-cell></table:table-row>
</table:table><text:p>after</text:p></office:text></office:body>
</office:document>"#;
const WAIT: std::time::Duration = std::time::Duration::from_secs(5);
/// The view takes the cursor's table the kernel reports.
fn borders_read(view: &mut LokView) -> crate::table::Table {
let doc = view.doc.clone();
let mut worker = view.worker.lock().expect("the worker lock");
worker.post_key(&doc, 0, 1027).expect("Right moves the cursor");
let seen = poll_until(&mut worker, &doc, &Events::default(), WAIT, |seen| seen.table.is_some());
let table = seen.table.expect("the cursor's table");
let now = worker.now(&doc).expect("the revision");
drop(worker);
view.doc = now;
view.read_borders(Some(table.clone()), view.doc.rev);
table
}
#[test]
fn a_dragged_border_moves_once_where_its_guide_shows() {
let Some(install) = crate::client::tests::install() else {
eprintln!("SKIP: no pinned LOK build");
return;
};
let cx = TestAppContext::single();
let (view, _) = cx.update(|app| live_view_of(app, &install, "table.fodt", TABLE));
let (line, moved) = cx.update(|app| {
view.update(app, |view, cx| {
let table = borders_read(view);
let (columns, rows) = (&table.columns, &table.rows);
let line = columns.offset + columns.inner[0].position;
let middle = rows.offset + (rows.left + rows.right) / 2;
let on = view.window_point((line, middle));
view.move_border(on);
assert_eq!(view.border_pointer(), Some(CursorStyle::ResizeColumn), "a hovered line asks to resize");
assert!(view.hold_border(on), "the line is held");
assert!(view.drop_border(on, cx), "let go in place");
assert!(view.hold_border(on));
let end = on + gpui::point(px(40.0), px(3.0));
assert!(view.move_border(end));
let guide = view.guide().expect("a guide line");
let to = view.doc_point(guide.origin).0;
assert!(to > line, "the guide follows the pointer: {line} to {to}");
assert!(view.drop_border(end, cx), "the drop runs");
assert!(!view.holds_border());
(line, to - line)
})
});
for _ in 0..80 {
cx.executor().tick();
}
cx.update(|app| {
let view = view.read(app);
let mut worker = view.worker.lock().expect("the worker lock");
let seen = poll_until(&mut worker, &view.doc, &Events::default(), WAIT, |seen| {
seen.table.as_ref().is_some_and(|table| table.columns.offset + table.columns.inner[0].position != line)
});
let table = seen.table.expect("still in the table");
let landed = table.columns.offset + table.columns.inner[0].position;
assert!((landed - line - moved).abs() <= 1, "the kernel lands it at the guide: {line} + {moved} vs {landed}");
});
}
#[test]
fn a_held_border_keeps_its_table_and_a_newer_read_refuses_it() {
let Some(install) = crate::client::tests::install() else {
eprintln!("SKIP: no pinned LOK build");
return;
};
let cx = TestAppContext::single();
let (view, _) = cx.update(|app| live_view_of(app, &install, "table.fodt", TABLE));
let errors = std::rc::Rc::new(std::cell::RefCell::new(Vec::new()));
let line = cx.update(|app| {
let errors = errors.clone();
app.subscribe(&view, move |_, error: &LokError, _| errors.borrow_mut().push(error.0.clone())).detach();
view.update(app, |view, cx| {
let table = borders_read(view);
let (columns, rows) = (&table.columns, &table.rows);
let line = columns.offset + columns.inner[0].position;
let on = view.window_point((line, rows.offset + (rows.left + rows.right) / 2));
assert!(view.hold_border(on), "the line is held");
let doc = view.doc.clone();
let mut worker = view.worker.lock().expect("the worker lock");
worker.post_key(&doc, 'a' as u32, 512).expect("a types");
view.doc = worker.now(&doc).expect("the revision");
drop(worker);
let mut gone = table.clone();
gone.columns.inner.clear();
view.read_borders(Some(gone), view.doc.rev);
let end = on + gpui::point(px(40.0), px(0.0));
assert!(view.move_border(end), "it moves by its own table");
assert!(view.guide().is_some(), "its guide still shows");
assert!(view.drop_border(end, cx), "the drop runs");
line
})
});
for _ in 0..60 {
for _ in 0..20 {
cx.executor().tick();
}
if !errors.borrow().is_empty() {
break;
}
}
assert!(errors.borrow().iter().any(|error| error.contains("stale")), "{:?}", errors.borrow());
cx.update(|app| {
let view = view.read(app);
let mut worker = view.worker.lock().expect("the worker lock");
worker.post_key(&view.doc, 0, 1027).expect("Right moves the cursor");
let seen = poll_until(&mut worker, &view.doc, &Events::default(), WAIT, |seen| seen.table.is_some());
let table = seen.table.expect("still in the table");
assert_eq!(table.columns.offset + table.columns.inner[0].position, line, "the old drag never lands");
});
}
#[test]
fn a_click_in_a_short_row_reaches_the_document() {
let Some(install) = crate::client::tests::install() else {
eprintln!("SKIP: no pinned LOK build");
return;
};
let mut cx = TestAppContext::single();
let (view, _) = cx.update(|app| live_view_of(app, &install, "table.fodt", TABLE));
let window = cx.add_window(|_, _| super::input::Blank);
cx.update_window(window.into(), |_, window, app| {
view.update(app, |view, cx| {
view.set_zoom(0.5, cx);
let table = borders_read(view);
let (columns, rows) = (&table.columns, &table.rows);
let x = columns.offset + (columns.left + columns.inner[0].position) / 2;
let middle = view.window_point((x, rows.offset + (rows.inner[0].position + rows.right) / 2));
let line = view.window_point((x, rows.offset + rows.inner[0].position));
assert!(f32::from(line.y - middle.y).abs() < 6.0, "the row is shorter than two reaches");
let down = |position| MouseDownEvent {
button: MouseButton::Left,
position,
modifiers: Default::default(),
click_count: 1,
first_mouse: false,
};
let up = MouseUpEvent { button: MouseButton::Left, position: middle, modifiers: Default::default(), click_count: 1 };
view.on_mouse_down(&down(middle), window, cx);
assert!(!view.holds_border(), "the row's middle goes to the document");
view.on_mouse_up(&up, window, cx);
view.on_mouse_down(&down(line), window, cx);
assert!(view.holds_border(), "the line itself is held");
assert!(view.drop_border(line, cx));
})
})
.expect("the window lives");
}
/// The batch whose table has `count` inner columns.
fn table_batch(view: &LokView, count: usize) -> Events {
let mut worker = view.worker.lock().expect("the worker lock");
let seen = poll_until(&mut worker, &view.doc, &Events::default(), WAIT, |seen| {
seen.table.as_ref().is_some_and(|table| table.columns.inner.len() == count)
});
assert_eq!(seen.table.as_ref().map(|table| table.columns.inner.len()), Some(count));
seen
}
#[test]
fn a_late_batch_keeps_its_own_revision() {
let Some(install) = crate::client::tests::install() else {
eprintln!("SKIP: no pinned LOK build");
return;
};
let cx = TestAppContext::single();
let (view, _) = cx.update(|app| live_view_of(app, &install, "table.fodt", TABLE));
let errors = std::rc::Rc::new(std::cell::RefCell::new(Vec::new()));
let before = cx.update(|app| {
let errors = errors.clone();
app.subscribe(&view, move |_, error: &LokError, _| errors.borrow_mut().push(error.0.clone())).detach();
view.update(app, |view, cx| {
borders_read(view);
let old = table_batch(view, 1);
let table = old.table.clone().expect("the old table");
let now = {
let mut worker = view.worker.lock().expect("the worker lock");
worker.run(&view.doc, "table.column_right", &[]).expect("a column goes in");
worker.now(&view.doc).expect("the revision")
};
let before = table_batch(view, 2).table.expect("the new table").columns.inner[0].position;
view.seen_revision(now.rev);
view.apply_batch(old, None, cx);
let on = view.window_point((table.columns.offset + table.columns.inner[0].position, table.rows.offset + 100));
assert!(view.hold_border(on), "the old table's line is held");
let end = on + gpui::point(px(20.0), px(0.0));
assert!(view.drop_border(end, cx), "the drop runs");
before
})
});
for _ in 0..60 {
for _ in 0..20 {
cx.executor().tick();
}
if !errors.borrow().is_empty() {
break;
}
}
assert!(errors.borrow().iter().any(|error| error.contains("stale")), "{:?}", errors.borrow());
let after = cx.update(|app| view.update(app, |view, _| table_batch(view, 2).table.expect("the table").columns.inner[0].position));
assert_eq!(after, before, "the old read never moves the new table");
}
/// The real view, narrower than its window.
struct Narrow(gpui::Entity<LokView>);
impl gpui::Render for Narrow {
fn render(&mut self, _: &mut gpui::Window, _: &mut gpui::Context<Self>) -> impl gpui::IntoElement {
use gpui::{ParentElement, Styled};
gpui::div().w(px(450.0)).h(px(300.0)).child(self.0.clone())
}
}
#[test]
fn a_border_let_go_outside_the_view_lands_there() {
let Some(install) = crate::client::tests::install() else {
eprintln!("SKIP: no pinned LOK build");
return;
};
let mut cx = TestAppContext::single();
cx.update(ely_gpui_component::init_for_tests);
let (view, _) = cx.update(|app| live_view_of(app, &install, "table.fodt", TABLE));
let (_, vcx) = cx.add_window_view(|_, _| Narrow(view.clone()));
vcx.run_until_parked();
let (line, on) = vcx.update(|_, app| {
view.update(app, |view, cx| {
let table = borders_read(view);
cx.notify();
let line = table.columns.offset + table.columns.inner[0].position;
(line, view.window_point((line, table.rows.offset + 100)))
})
});
vcx.run_until_parked();
assert!(on.x > px(380.0) && on.x < px(440.0), "the line sits near the view's edge: {on:?}");
vcx.simulate_mouse_down(on, MouseButton::Left, Default::default());
assert!(vcx.update(|_, app| view.read(app).holds_border()), "the line is held");
let inside = gpui::point(px(445.0), on.y);
vcx.simulate_mouse_move(inside, MouseButton::Left, Default::default());
let at = |vcx: &mut gpui::VisualTestContext| vcx.update(|_, app| view.read(app).guide().expect("a guide").origin.x);
let held = at(vcx);
let outside = gpui::point(px(490.0), on.y);
vcx.simulate_mouse_move(outside, MouseButton::Left, Default::default());
let out = at(vcx);
assert!(out > held, "the guide follows out of the view: {held:?} to {out:?}");
let wanted = vcx.update(|_, app| view.read(app).doc_point(gpui::point(out, on.y)).0);
vcx.simulate_mouse_up(outside, MouseButton::Left, Default::default());
assert!(!vcx.update(|_, app| view.read(app).holds_border()), "let go");
vcx.run_until_parked();
let landed = vcx.update(|_, app| {
let view = view.read(app);
let mut worker = view.worker.lock().expect("the worker lock");
let seen = poll_until(&mut worker, &view.doc, &Events::default(), WAIT, |seen| {
seen.table.as_ref().is_some_and(|table| table.columns.offset + table.columns.inner[0].position != line)
});
let table = seen.table.expect("still in the table");
table.columns.offset + table.columns.inner[0].position
});
assert!((landed - wanted).abs() <= 1, "it lands at the release: {landed} vs {wanted}");
}
#[test]
fn a_still_click_beside_a_border_sends_nothing() {
let Some(install) = crate::client::tests::install() else {
eprintln!("SKIP: no pinned LOK build");
return;
};
let mut cx = TestAppContext::single();
cx.update(ely_gpui_component::init_for_tests);
let (view, _) = cx.update(|app| live_view_of(app, &install, "table.fodt", TABLE));
let (_, vcx) = cx.add_window_view(|_, _| Narrow(view.clone()));
vcx.run_until_parked();
let on = vcx.update(|_, app| {
view.update(app, |view, cx| {
let table = borders_read(view);
cx.notify();
let line = table.columns.offset + table.columns.inner[0].position;
view.window_point((line, table.rows.offset + 100)) + gpui::point(px(3.0), px(0.0))
})
});
vcx.run_until_parked();
let sent = vcx.update(|_, app| view.read(app).sent());
vcx.simulate_mouse_down(on, MouseButton::Left, Default::default());
assert!(vcx.update(|_, app| view.read(app).holds_border()), "the line is held off its centre");
vcx.simulate_mouse_up(on, MouseButton::Left, Default::default());
assert!(!vcx.update(|_, app| view.read(app).holds_border()), "let go");
assert_eq!(vcx.update(|_, app| view.read(app).sent()), sent, "a still click sends no command");
}
+1 -1
View File
@@ -60,7 +60,7 @@ fn typing_and_composing_reach_the_document() {
assert_eq!(saved(&view, &mut cx), ["ab你", "Hello 世界"]);
}
struct Blank;
pub(super) struct Blank;
impl gpui::Render for Blank {
fn render(&mut self, _: &mut Window, _: &mut gpui::Context<Self>) -> impl gpui::IntoElement {