R3.3: the LOK view's pointer follows the kernel; an arrow over cells

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

[skip ci]
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-12 23:31:28 -04:00
1 parent ee1b8ad375
commit 26c0a64665
11 files changed
+72 -6

No files matched your search

+2
View File
@@ -14,6 +14,7 @@ fn unpack_pushed(body: &[u8]) -> io::Result<(u64, Events)> {
let rects = rects_of(&mut unpack)?;
let cursor = rects_of(&mut unpack)?.first().copied();
let cursor_visible = unpack.u64()? != 0;
let pointer = unpack.str()?;
let selection = rects_of(&mut unpack)?;
let graphic = rects_of(&mut unpack)?.first().copied();
let cropping = unpack.u64()? != 0;
@@ -55,6 +56,7 @@ fn unpack_pushed(body: &[u8]) -> io::Result<(u64, Events)> {
rects,
cursor,
cursor_visible,
pointer,
selection,
graphic,
cropping,
+24
View File
@@ -195,3 +195,27 @@ fn a_theme_switch_is_no_edit() {
assert_eq!(undo["actions"], "", "{scheme} left undo steps");
}
}
#[test]
fn the_pointer_is_text_only_while_a_cell_edits() {
if install().is_none() {
eprintln!("SKIP: no pinned LOK build");
return;
}
let (_dir, mut worker, doc) = open_book(FODS);
let hover = |worker: &mut Worker, x| {
let at = Mouse { kind: 2, x, y: 120, count: 1, buttons: 0, modifiers: 0 };
worker.post_mouse(&doc, at).expect("hovers");
};
hover(&mut worker, 400);
let reading = poll_until(&mut worker, &doc, &Events::default(), SETTLE, |seen| {
!seen.pointer.is_empty()
});
assert_eq!(reading.pointer, "default", "a cell shows the arrow");
worker.post_key(&doc, 0, 769).expect("F2 edits A1");
hover(&mut worker, 500);
let editing = poll_until(&mut worker, &doc, &reading, SETTLE, |seen| {
seen.pointer == "text"
});
assert_eq!(editing.pointer, "text", "the edited cell shows the text pointer");
}
+6 -1
View File
@@ -46,6 +46,7 @@ const FONTS: i32 = 57;
const SIZE_CHANGED: i32 = 13;
const SET_PART: i32 = 14;
const CELL_CURSOR: i32 = 17;
const MOUSE_POINTER: i32 = 18;
const CELL_FORMULA: i32 = 19;
const HEADER: i32 = 33;
const GEOMETRY: i32 = 50;
@@ -73,6 +74,8 @@ pub struct Events {
pub rects: Vec<Rect>,
pub cursor: Option<Rect>,
pub cursor_visible: bool,
/// The CSS pointer name; empty until the kernel says.
pub pointer: String,
pub selection: Vec<Rect>,
/// The selected object's frame, if any.
pub graphic: Option<Rect>,
@@ -141,7 +144,8 @@ fn signal() -> &'static Condvar {
SIGNAL.get_or_init(Condvar::new)
}
const KINDS: [i32; 33] = [
const KINDS: [i32; 34] = [
MOUSE_POINTER,
REFERENCE_MARKS,
FUNCTION_LIST,
TOOLTIP,
@@ -233,6 +237,7 @@ fn record(slot: &mut Slot, kind: i32, text: &str) -> Option<u32> {
.collect();
}
CURSOR_VISIBLE => batch.cursor_visible = text == "true",
MOUSE_POINTER => batch.pointer = text.to_string(),
GRAPHIC => {
batch.graphic = rect_in(batch, "graphic selection", text);
batch.cropping = batch.graphic.is_some() && text.contains("\"isCropMode\": true");
+5
View File
@@ -117,6 +117,7 @@ pub struct LokView {
watching: Option<Task<()>>,
cursor: Option<Rect>,
cursor_visible: bool,
pointer: gpui::CursorStyle,
selection: Vec<Rect>,
cell: crate::Cell,
/// Whether the kernel was last told to paint dark.
@@ -222,6 +223,7 @@ impl LokView {
copied: None,
cursor: None,
cursor_visible: true,
pointer: gpui::CursorStyle::Arrow,
selection: Vec::new(),
cell: crate::Cell::default(),
dark: None,
@@ -387,6 +389,9 @@ impl LokView {
self.follow_graphic(batch.graphic, cx);
self.cursor = batch.cursor;
self.cursor_visible = batch.cursor_visible;
if !batch.pointer.is_empty() {
self.pointer = render::pointer(&batch.pointer);
}
self.selection = batch.selection;
if batch.cell.functions != self.cell.functions {
self.picked = 0;
+3
View File
@@ -384,6 +384,9 @@ impl LokView {
}
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() {
// A hover: the kernel answers with its pointer.
self.mouse(2, event.position, 0, 1, &event.modifiers);
}
}
+27 -1
View File
@@ -59,7 +59,7 @@ impl Render for LokView {
.aria_value(self.a11y.text.clone())
.key_context(CONTEXT)
.track_focus(&self.focus)
.cursor(CursorStyle::IBeam)
.cursor(self.pointer)
.size_full()
.overflow_hidden()
.bg(canvas_color)
@@ -360,3 +360,29 @@ impl LokView {
}
}
}
/// The cursor for a kernel CSS pointer name.
pub(super) fn pointer(css: &str) -> CursorStyle {
match css {
"default" | "wait" | "help" => CursorStyle::Arrow,
"text" => CursorStyle::IBeam,
"vertical-text" => CursorStyle::IBeamCursorForVerticalLayout,
"crosshair" | "fill" => CursorStyle::Crosshair,
"move" => CursorStyle::ClosedHand,
"grab" => CursorStyle::OpenHand,
"pointer" => CursorStyle::PointingHand,
"n-resize" | "s-resize" => CursorStyle::ResizeUpDown,
"e-resize" | "w-resize" => CursorStyle::ResizeLeftRight,
"ne-resize" | "sw-resize" => CursorStyle::ResizeUpRightDownLeft,
"nw-resize" | "se-resize" => CursorStyle::ResizeUpLeftDownRight,
"col-resize" => CursorStyle::ResizeColumn,
"row-resize" => CursorStyle::ResizeRow,
"copy" => CursorStyle::DragCopy,
"alias" => CursorStyle::DragLink,
"not-allowed" => CursorStyle::OperationNotAllowed,
_ => {
log::warn!("lok: unknown pointer {css}");
CursorStyle::Arrow
}
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ impl LokView {
cx.notify();
}
/// Ctrl (Cmd on macOS) with the wheel zooms; else it scrolls.
/// Ctrl (macOS: Cmd) and the wheel zoom; else scroll.
pub(super) fn on_wheel(&mut self, event: &ScrollWheelEvent, window: &mut Window, cx: &mut Context<Self>) {
if !self.wheel_zoom(event, cx) {
self.on_scroll(event, window, cx);
+1 -1
View File
@@ -37,7 +37,7 @@ fn pack_events(batch: Events) -> Vec<u8> {
.u64(batch.all as u64);
let pack = rects(pack, &batch.rects);
let pack = rects(pack, batch.cursor.as_slice());
let pack = pack.u64(batch.cursor_visible as u64);
let pack = pack.u64(batch.cursor_visible as u64).str(&batch.pointer);
let pack = rects(pack, &batch.selection);
let pack = rects(pack, batch.graphic.as_slice()).u64(batch.cropping as u64);
let pack = pack
+1 -1
View File
@@ -24,7 +24,7 @@ pub fn steps(event: &ScrollWheelEvent, carry: &mut f32) -> i32 {
}
}
/// Over its parent, takes a zooming wheel before the parent scrolls.
/// Takes a zooming wheel before the parent scrolls.
pub fn zoom_layer(
on: impl Fn(&ScrollWheelEvent, &mut Window, &mut App) + 'static,
) -> impl IntoElement {