Skip to content

Commit 386e1c4

Browse files
fix: scroll into view used the wrong position
It used the position from positionNewTopLevelBlock, not the initial insert position. Delay the setting of current node until the position is correct.
1 parent 05ad7d3 commit 386e1c4

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/actions/enter.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@ export class EnterAction {
146146

147147
workspace.setResizesEnabled(true);
148148

149-
getFocusManager().focusTree(workspace);
150-
workspace.getCursor()?.setCurNode(newBlock);
151149
this.mover.startMove(workspace, newBlock, insertStartPoint);
152150

153151
const isStartBlock =

src/actions/mover.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,9 @@ export class Mover {
143143
dragger.onDragStart(info.fakePointerEvent('pointerdown'));
144144
info.updateTotalDelta();
145145
// In case the block is detached, ensure that it still retains focus
146-
// (otherwise dragging will break).
147-
getFocusManager().focusNode(block);
146+
// (otherwise dragging will break). This is also the point a new block's
147+
// initial insert position is scrolled into view.
148+
workspace.getCursor()?.setCurNode(block);
148149
block.getFocusableElement().addEventListener('blur', blurListener);
149150

150151
// Register a keyboard shortcut under the key combos of all existing

test/webdriverio/test/scroll_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ suite('Scrolling into view', function () {
5353
await this.browser.keys(Key.Enter);
5454

5555
// Asset new block has been scrolled into the viewport.
56+
await this.browser.pause(PAUSE_TIME);
5657
const inViewport = await this.browser.execute(() => {
5758
const workspace = Blockly.getMainWorkspace() as Blockly.WorkspaceSvg;
5859
const block = workspace.getBlocksByType(
@@ -68,7 +69,6 @@ suite('Scrolling into view', function () {
6869
);
6970
return viewport.contains(blockBounds.left, blockBounds.top);
7071
});
71-
// FIXME: actually scrolls the wrong bounds into view
72-
chai.assert.isFalse(inViewport);
72+
chai.assert.isTrue(inViewport);
7373
});
7474
});

0 commit comments

Comments
 (0)