Skip to content

Commit d151145

Browse files
authored
Merge branch 'main' into move-shortcuts
2 parents b502968 + 18c3ad3 commit d151145

File tree

18 files changed

+841
-298
lines changed

18 files changed

+841
-298
lines changed

.github/workflows/pages.yml

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,46 @@ jobs:
2626
build:
2727
runs-on: ubuntu-latest
2828
steps:
29-
- name: Checkout
29+
- name: Checkout blockly
3030
uses: actions/checkout@v4
31+
with:
32+
path: blockly
33+
repository: google/blockly
34+
ref: develop
35+
36+
- name: Checkout blockly-keyboard-experimentation
37+
uses: actions/checkout@v4
38+
with:
39+
path: blockly-keyboard-experimentation
40+
3141
- name: Setup Node
3242
uses: actions/setup-node@v4
3343
with:
34-
node-version: latest
35-
cache: 'npm'
36-
- run: npm ci
37-
- run: npm run ghpages
44+
node-version: 20.x
45+
46+
- name: Build blockly
47+
run: |
48+
cd blockly
49+
npm ci
50+
npm run package
51+
cd dist
52+
npm link
53+
cd ../..
54+
55+
- name: Build blockly-keyboard-experimentation
56+
run: |
57+
cd blockly-keyboard-experimentation
58+
npm ci
59+
npm link blockly
60+
npm run ghpages
61+
cd ..
62+
3863
- name: Upload artifact
3964
uses: actions/upload-pages-artifact@v3
4065
with:
4166
# Upload build folder
42-
path: './dist'
67+
path: './blockly-keyboard-experimentation/dist'
68+
4369
deploy:
4470
environment:
4571
name: github-pages

package-lock.json

Lines changed: 16 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blockly/keyboard-experiment",
3-
"version": "0.0.8",
3+
"version": "0.0.9",
44
"description": "A plugin for keyboard navigation.",
55
"scripts": {
66
"audit:fix": "blockly-scripts auditFix",
@@ -48,16 +48,16 @@
4848
"src"
4949
],
5050
"devDependencies": {
51-
"@blockly/dev-scripts": "^4.0.1",
52-
"@blockly/field-colour": "^5.0.7",
51+
"@blockly/dev-scripts": "^4.0.8",
52+
"@blockly/field-colour": "^6.0.0",
5353
"@eslint/eslintrc": "^2.1.2",
5454
"@eslint/js": "^8.49.0",
5555
"@types/chai": "^5.2.1",
5656
"@types/mocha": "^10.0.10",
5757
"@types/p5": "^1.7.6",
5858
"@typescript-eslint/eslint-plugin": "^6.7.2",
5959
"@typescript-eslint/parser": "^6.7.2",
60-
"blockly": "^12.0.0",
60+
"blockly": "^12.0.1-beta.1",
6161
"chai": "^5.2.0",
6262
"eslint": "^8.49.0",
6363
"eslint-config-google": "^0.14.0",
@@ -73,11 +73,11 @@
7373
"webdriverio": "^9.12.1"
7474
},
7575
"peerDependencies": {
76-
"blockly": "^12.0.0"
76+
"blockly": "^12.0.1-beta.1"
7777
},
7878
"overrides": {
7979
"@blockly/field-colour": {
80-
"blockly": "^12.0.0"
80+
"blockly": "^12.0.1-beta.1"
8181
}
8282
},
8383
"publishConfig": {

src/actions/action_menu.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,23 @@ export class ActionMenu {
4545
private registerShortcut() {
4646
const menuShortcut: ShortcutRegistry.KeyboardShortcut = {
4747
name: Constants.SHORTCUT_NAMES.MENU,
48-
preconditionFn: (workspace) =>
49-
this.navigation.canCurrentlyNavigate(workspace),
48+
preconditionFn: (workspace) => {
49+
return (
50+
this.navigation.canCurrentlyNavigate(workspace) &&
51+
!workspace.isDragging()
52+
);
53+
},
5054
callback: (workspace) => {
5155
switch (this.navigation.getState(workspace)) {
5256
case Constants.STATE.WORKSPACE:
5357
return this.openActionMenu(workspace);
58+
case Constants.STATE.FLYOUT: {
59+
const flyoutWorkspace = workspace.getFlyout()?.getWorkspace();
60+
if (flyoutWorkspace) {
61+
return this.openActionMenu(flyoutWorkspace);
62+
}
63+
return false;
64+
}
5465
default:
5566
return false;
5667
}

src/actions/disconnect.ts

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
import {
88
BlockSvg,
9-
RenderedConnection,
9+
Events,
1010
ShortcutRegistry,
1111
utils as BlocklyUtils,
12+
Connection,
13+
ConnectionType,
1214
} from 'blockly';
1315
import * as Constants from '../constants';
14-
import type {WorkspaceSvg, IFocusableNode} from 'blockly';
16+
import type {WorkspaceSvg} from 'blockly';
1517
import {Navigation} from '../navigation';
1618

1719
const KeyCodes = BlocklyUtils.KeyCodes;
@@ -76,66 +78,16 @@ export class DisconnectAction {
7678
*/
7779
disconnectBlocks(workspace: WorkspaceSvg) {
7880
const cursor = workspace.getCursor();
79-
if (!cursor) {
80-
return;
81-
}
82-
let curNode: IFocusableNode | null = cursor.getCurNode();
83-
let wasVisitingConnection = true;
84-
while (
85-
curNode &&
86-
!(curNode instanceof RenderedConnection && curNode.isConnected())
87-
) {
88-
if (curNode instanceof BlockSvg) {
89-
const previous = curNode.previousConnection;
90-
const output = curNode.outputConnection;
91-
if (previous?.isConnected()) {
92-
curNode = previous;
93-
break;
94-
} else if (output?.isConnected()) {
95-
curNode = output;
96-
break;
97-
}
98-
}
99-
100-
curNode = workspace.getNavigator().getParent(curNode);
101-
wasVisitingConnection = false;
102-
}
103-
if (!curNode) {
104-
console.log('Unable to find a connection to disconnect');
105-
return;
106-
}
107-
if (!(curNode instanceof RenderedConnection && curNode.isConnected())) {
108-
return;
109-
}
110-
const targetConnection = curNode.targetConnection;
111-
if (!targetConnection) {
112-
throw new Error('Must have target if connected');
113-
}
114-
115-
const superiorConnection = curNode.isSuperior()
116-
? curNode
117-
: targetConnection;
118-
119-
const inferiorConnection = curNode.isSuperior()
120-
? targetConnection
121-
: curNode;
122-
123-
if (inferiorConnection.getSourceBlock().isShadow()) {
124-
return;
125-
}
126-
127-
if (!inferiorConnection.getSourceBlock().isMovable()) {
128-
return;
129-
}
130-
131-
superiorConnection.disconnect();
132-
inferiorConnection.bumpAwayFrom(superiorConnection);
81+
if (!cursor) return;
82+
const curNode = cursor.getCurNode();
83+
if (!(curNode instanceof BlockSvg)) return;
13384

134-
const rootBlock = superiorConnection.getSourceBlock().getRootBlock();
135-
rootBlock.bringToFront();
85+
const healStack = !curNode.outputConnection?.isConnected();
86+
Events.setGroup(true);
87+
curNode.unplug(healStack);
88+
Events.setGroup(false);
13689

137-
if (wasVisitingConnection) {
138-
workspace.getCursor()?.setCurNode(superiorConnection);
139-
}
90+
// Needed or we end up with passive focus.
91+
cursor.setCurNode(curNode);
14092
}
14193
}

0 commit comments

Comments
 (0)