Skip to content

Select a cell when the button goes down, not on release - #909

Open
marcoarnulfo wants to merge 1 commit into
storytold:mainfrom
marcoarnulfo:fix/select-cell-on-press
Open

marcoarnulfo wants to merge 1 commit into
storytold:mainfrom
marcoarnulfo:fix/select-cell-on-press

Conversation

@marcoarnulfo

Copy link
Copy Markdown
Contributor

Fixes #900.

The grid only decided a press from drag_started() or clicked(), so nothing happened while the button was down, and a press whose movement and release arrived in the same frame (past the click distance, but never recognised as a drag) selected nothing. A press on a plain cell now selects it right away (Shift extends, Ctrl/Cmd adds an area) and enters Drag::Select with that cell as the anchor, so dragging extends from it as before. Presses on the outline buttons, filter and list arrows, objects, freeze handles, the fill handle and the move border, and presses while editing, keep going through the existing path, so they still act on drag or release. Following a hyperlink, toggling a checkbox and double-click-to-edit stay on release, as in Excel. The selection code moved into a small select_pressed_cell helper shared by both paths.

Two things to know: with a drawing tool active the press still selects on release, as before. And since the cell is now selected on the way down, its fill handle is already there when the button comes up, so a click on the last few pixels of the bottom-right corner of a cell that wasn't selected before lands on the handle (no double-click-to-edit or link there). Happy to adjust either.

Validation:

  • selection::a_press_selects_the_cell_before_the_release: fails on main (A1 still selected while the button is down on C3), passes here
  • selection::a_press_that_moves_within_the_cell_selects_it: fails on main (move + release in one frame leaves A1 selected), passes here
  • selection::pressing_a_filter_arrow_or_an_outline_button_keeps_the_selection: guards the button-like targets; dropping the filter-arrow exclusion makes it fail
  • cargo test -p gridcraft-ui-egui for selection, interaction, outline, filter_list_scroll, fill_handle_double_click, header_column_drag, freeze_handles, chart_resize, cell_pictures, merged_cells, right_to_left, popup_dismissal, text_box_editing and the other pointer-driven test files
  • cargo clippy -p gridcraft-ui-egui --all-targets -- -D warnings, cargo fmt --all -- --check
  • (macOS, Apple silicon)

@richard1912

Copy link
Copy Markdown
Contributor

Thanks @marcoarnulfo, and thanks for picking this up so quickly (and for #869 too)!

I built this branch (427dcac) on Windows 11 at 150% scaling and re-ran the real-mouse tests from the issue against it and against v0.6.1. Same method as before: SetCursorPos + mouse_event, selection read over the control channel with document.inspect, F14 selected before each run, press on C8, 3 runs per case. All 3 runs matched in every case.

Case v0.6.1 PR #909
Quick click C8 C8
Held 300 ms, selection read while held F14 while held, C8 after C8 while held, C8 after
Move 4 px inside C8, read while held F14 while held, C8 after C8 while held, C8 after
Drag C8 to E10, read while held C8:E10 C8:E10
Held still 750 ms, no reads during the press C8 C8
Held still 800 / 850 / 900 ms F14 (nothing) C8
Held still 1.5 s / 3 s F14 (nothing) C8
Nudge 3 px, then hold 1.5 s F14 (nothing) C8
Jitter every 60 ms for 1.5 s C8 C8
Shift+click C8 C8:F14 C8:F14
Ctrl+click C8 F14,C8 F14,C8

So the long-press case (0.8 s or longer, which your tests don't cover since it needs real idle time with no frames) is fixed on Windows too, and nothing regressed in the cases I tried. I didn't test the fill-handle corner or drawing tools.

@marcoarnulfo

Copy link
Copy Markdown
Contributor Author

Thank you for the thorough run on real hardware, that table is great. Especially the long-press rows: those need real idle time, which my harness tests can't reproduce, so it's good to know they're fixed too.

@anton-belkin

Copy link
Copy Markdown

Thanks for this — I hit the same lag on macOS and had a local patch for it before finding #900, so a few notes from that work in case they are useful.

Presses that still wait for release here. The press path requires in_cells and app.editor.is_none(), so these keep the old feel:

  • row and column headers (select the row/column, Shift to extend, Ctrl/Cmd to add), and the select-all corner;
  • a press on a cell while editing a formula in point mode (inserting the reference);
  • a press on another cell while editing plain text (commit, then select).

In my patch these also act on press. The only header presses I had to leave on drag/release were resize edges and a press on an already selected column header (it may become a column move).

Page Layout view — worth a check, I have not run this branch. A header/footer zone lies inside the cell area, so in_cells is true there. In my patch a press on the header zone first selected the cell underneath and then started the header edit on release; I had to exclude those zones from the press path explicitly (PageGrid::hf_zone_at). The press path here looks like it would do the same.

Double-click. Keeping double-click-to-edit on release is the right call: I first opened the editor on the second press, and the release over the grid then took keyboard focus away from it, so typing went nowhere.

Happy to send the header part as a small follow-up PR once this lands, if that is welcome.

@marcoarnulfo

Copy link
Copy Markdown
Contributor Author

Thanks @anton-belkin, these notes are really useful. I'm checking the Page Layout header/footer zones on this branch now and will exclude them from the press path if a press there selects the cell underneath. And yes please on the header follow-up, that would be very welcome.

@marcoarnulfo

Copy link
Copy Markdown
Contributor Author

@anton-belkin I checked the Page Layout case: on this codebase in_cells already excludes the header/footer zones (PageGrid::on_cells starts below the top margin and stops above the bottom one, which are exactly the zones hf_zone_at returns), so a press there doesn't reach the press path.

Also, I see #927 by @echelon covers #900 together with the fill-handle and whole-column reference work. Happy to close this one in favour of it if that's simpler for you, just say so.

@anton-belkin

Copy link
Copy Markdown

You're right, thanks for checking — in_cells already stops at the margins. I misattributed it: in my patch the press flag stayed set on presses outside the cells, which is what broke the header/footer edit, not the zone itself. Sorry for the noise.

On #909 vs #927 that's the maintainers' call. I'll base the header follow-up on whichever one lands.

@marcoarnulfo

Copy link
Copy Markdown
Contributor Author

No noise at all, thanks for digging into it @anton-belkin. Sounds good, happy to help with the header follow-up whichever lands.

@FredApps FredApps left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReviewerA — source-read COMMENT (not an approval)

I read the head of the diff: a cell is selected when the button goes down, not on release. A press on a plain cell selects it at once, as Excel does, and dragging extends from it; presses on button-like targets, objects, the fill handle or the move border, and presses while editing, are still decided below on drag or release. Excel selects on mouse down, so the oracle fits, and the usual defect of this change is that a press on a target that should not select (a header, a hyperlink, a scroll bar) does. The condition lists the exceptions, and a test for each is the proof. Touch screens, where a press can be the start of a scroll, may want selection on release; that case should be considered. I have not run it, and no exact-head CI result exists for this head. Nothing was run.

I ran nothing and have no exact-head CI result for this PR, so this is not an approval. Where a diff was long I read its code hunks rather than every generated or documentation line.

Status: waiting_author.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(grid): selection waits for mouse release, and a press held 0.8 s or longer selects nothing

4 participants