Repository navigation
fix(editor): scroll a moved block into view after it moves - #13598
yuxi-liu-wired wants to merge 2 commits into
Conversation
| (js/requestAnimationFrame | ||
| (fn [] | ||
| (when-let [block-node (util/get-first-block-by-id (:block/uuid (first blocks)))] | ||
| (.scrollIntoView block-node #js {:behavior "smooth" :block "nearest"})))) |
There was a problem hiding this comment.
🟡 Delayed move scroll jumps to another view
If navigation finishes before requestAnimationFrame, the callback can scroll a sidebar copy of the moved block. The move's original page is no longer active, so the sidebar jumps unexpectedly.
Learn more
A move submits an asynchronous worker mutation. The transaction captures the original route, but the scroll callback looks up a block globally after the worker resolves. If the user navigates away before that callback and the block is also displayed in the sidebar, the lookup can find the sidebar copy and scroll it. The existing apply-outliner-ops checks the request route for editor callbacks, but this scroll has no equivalent guard.
Example: A user moves block A on its page, where A is also open in the sidebar. They navigate to another page before the move returns. The scheduled frame finds A in the sidebar and scrolls that sidebar unexpectedly.
Recommended fix: Capture the active graph and route when move-up-down starts. Before scrolling, verify they still match and locate the block inside its original view rather than with a document-wide first match.
Was this helpful? React with 👍 or 👎 to provide feedback.
Moving a block with Shift+Alt+Down past the bottom edge of the window left it below the edge: the move scrolled the block into view before the move was applied, at the block's old place, which was still on screen. Moving up worked by luck: the block's old place at the top edge was already partly off screen. Scroll once the move is applied and the block is drawn in its new place.
The scroll ran on the next frame after the move, whatever page was open by then, on the block's first row in the document, which can be a copy in an embed or the sidebar. It now runs only if the graph and route are unchanged, on the row in the container the block was moved in.
5854fc9 to
4f9b240
Compare
|
Combined with the other PRs that change the same files into #13782. |
Moving a block with Shift+Alt+Down past the bottom edge of the window leaves it below the edge: the page does not follow it. Each further press moves it further out of view, so the press looks like it did nothing. Shift+Alt+Up at the top edge follows the block.
The move scrolled the block into view before the move was applied, at the block's old place, which was still on screen, so the scroll did nothing. Up worked only because the block's old place at the top edge was already partly off screen.
The scroll now runs once the move is applied and the block is drawn in its new place.
From review, a second commit: the scroll runs only if the graph and route are still the ones the move started in (a page left during the move is not scrolled), and it scrolls the block's row in the view it was moved in, not a copy of it drawn first in an embed or the sidebar. Tests:
moved-row-is-taken-in-the-view-it-moved-in-test,move-scroll-context-is-the-graph-and-route-test.Before, on master, a 40-block journal with block 20 at the bottom edge of the window, 4 presses of Shift+Alt+Down: the block's top ends 86 px below the window's bottom edge, the page never scrolls. After: the page scrolls with every press and the block stays on screen. Held down (10 presses, 33 ms apart): before, 254 px below the edge; after, on screen. Up at the top edge, moves in the middle of the page, and blocks with children move as before.