Skip to content

Commit 641aa95

Browse files
authored
Merge branch 'main' into add-ci-workflows
2 parents b36c8b2 + 2209a97 commit 641aa95

File tree

5 files changed

+91
-63
lines changed

5 files changed

+91
-63
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Report a bug 🐛
2+
description: Report bugs in Blockly, so we can fix them.
3+
labels: 'issue: bug, issue: triage'
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: >
8+
Thank you for taking the time to fill out a bug report!
9+
If you have a question about how to use Blockly in your application,
10+
please ask on the [forum](https://groups.google.com/forum/#!forum/blockly) instead of filing an issue.
11+
- type: checkboxes
12+
id: duplicates
13+
attributes:
14+
label: Check for duplicates
15+
options:
16+
- label: I have searched for similar issues before opening a new one.
17+
- type: textarea
18+
id: description
19+
attributes:
20+
label: Description
21+
description: Please provide a clear and concise description of the bug.
22+
placeholder: What happened? What did you expect to happen?
23+
validations:
24+
required: true
25+
- type: textarea
26+
id: repro
27+
attributes:
28+
label: Reproduction steps
29+
description: What steps should we take to reproduce the issue?
30+
value: |
31+
1.
32+
2.
33+
3.
34+
- type: textarea
35+
id: stack-trace
36+
attributes:
37+
label: Stack trace
38+
description: If you saw an error message or stack trace, please include it here.
39+
placeholder: The text in this section will be formatted automatically; no need to include backticks.
40+
render: shell
41+
- type: textarea
42+
id: screenshots
43+
attributes:
44+
label: Screenshots
45+
description: Screenshots can help us see the behavior you're describing. Please add a screenshot or gif, especially if you are describing a rendering or visual bug.
46+
placeholder: Paste or drag-and-drop an image to upload it.
47+
- type: dropdown
48+
id: browsers
49+
attributes:
50+
label: Browsers
51+
description: Please select all browsers you've observed this behavior on. If the bug isn't browser-specific, you can leave this blank.
52+
multiple: true
53+
options:
54+
- Chrome desktop
55+
- Safari desktop
56+
- Firefox desktop
57+
- Android mobile
58+
- iOS mobile

src/actions/action_menu.ts

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import {
88
ASTNode,
9-
Connection,
109
ContextMenu,
1110
ContextMenuRegistry,
1211
ShortcutRegistry,
@@ -22,10 +21,6 @@ const createSerializedKey = ShortcutRegistry.registry.createSerializedKey.bind(
2221
ShortcutRegistry.registry,
2322
);
2423

25-
export interface ScopeWithConnection extends ContextMenuRegistry.Scope {
26-
connection?: Connection;
27-
}
28-
2924
/**
3025
* Keyboard shortcut to show the action menu on Cmr/Ctrl/Alt+Enter key.
3126
*/
@@ -114,10 +109,10 @@ export class ActionMenu {
114109
const connection = node.getLocation() as RenderedConnection;
115110
rtl = connection.getSourceBlock().RTL;
116111

117-
// Slightly hacky: get insert action from registry. Hacky
118-
// because registry typings don't include {connection: ...} as
119-
// a possible kind of scope.
120-
const menuOptions = this.addConnectionItems(connection, menuOpenEvent);
112+
const menuOptions = ContextMenuRegistry.registry.getContextMenuOptions(
113+
{focusedNode: connection},
114+
menuOpenEvent,
115+
);
121116
// If no valid options, don't show a menu
122117
if (!menuOptions?.length) return true;
123118
const location = this.calculateLocationForConnectionMenu(connection);
@@ -153,45 +148,6 @@ export class ActionMenu {
153148
return true;
154149
}
155150

156-
/**
157-
* Add menu items for a context menu on a connection scope.
158-
*
159-
* @param connection The connection on which the menu is shown.
160-
* @param menuOpenEvent The event that opened this context menu.
161-
*/
162-
private addConnectionItems(connection: Connection, menuOpenEvent: Event) {
163-
const menuOptions: Array<
164-
| ContextMenuRegistry.ContextMenuOption
165-
| ContextMenuRegistry.LegacyContextMenuOption
166-
> = [];
167-
const possibleOptions = [
168-
this.getContextMenuAction('insert'),
169-
this.getContextMenuAction('blockPasteFromContextMenu'),
170-
];
171-
172-
// Check preconditions and get menu texts.
173-
const scope = {
174-
connection,
175-
} as unknown as ContextMenuRegistry.Scope;
176-
177-
for (const option of possibleOptions) {
178-
const precondition = option.preconditionFn?.(scope, menuOpenEvent);
179-
if (precondition === 'hidden') continue;
180-
const displayText =
181-
(typeof option.displayText === 'function'
182-
? option.displayText(scope)
183-
: option.displayText) ?? '';
184-
menuOptions.push({
185-
text: displayText,
186-
enabled: precondition === 'enabled',
187-
callback: option.callback,
188-
scope,
189-
weight: option.weight,
190-
});
191-
}
192-
return menuOptions;
193-
}
194-
195151
/**
196152
* Find a context menu action, throwing an `Error` if it is not present or
197153
* not an action. This usefully narrows the type to `ActionRegistryItem`

src/actions/clipboard.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
import * as Constants from '../constants';
1818
import type {BlockSvg, WorkspaceSvg} from 'blockly';
1919
import {Navigation} from '../navigation';
20-
import {ScopeWithConnection} from './action_menu';
2120
import {getShortActionShortcut} from '../shortcut_formatting';
21+
import * as Blockly from 'blockly';
2222

2323
const KeyCodes = blocklyUtils.KeyCodes;
2424
const createSerializedKey = ShortcutRegistry.registry.createSerializedKey.bind(
@@ -306,19 +306,28 @@ export class Clipboard {
306306
private registerPasteContextMenuAction() {
307307
const pasteAction: ContextMenuRegistry.RegistryItem = {
308308
displayText: (scope) => `Paste (${getShortActionShortcut('paste')})`,
309-
preconditionFn: (scope: ScopeWithConnection) => {
310-
const block = scope.block ?? scope.connection?.getSourceBlock();
309+
preconditionFn: (scope: ContextMenuRegistry.Scope) => {
310+
let block;
311+
if (scope.focusedNode instanceof Blockly.Block) {
312+
block = scope.focusedNode;
313+
} else if (scope.focusedNode instanceof Blockly.Connection) {
314+
block = scope.focusedNode.getSourceBlock();
315+
}
311316
const ws = block?.workspace as WorkspaceSvg | null;
312317
if (!ws) return 'hidden';
313318
return this.pastePrecondition(ws) ? 'enabled' : 'disabled';
314319
},
315-
callback: (scope: ScopeWithConnection) => {
316-
const block = scope.block ?? scope.connection?.getSourceBlock();
320+
callback: (scope: ContextMenuRegistry.Scope) => {
321+
let block;
322+
if (scope.focusedNode instanceof Blockly.Block) {
323+
block = scope.focusedNode;
324+
} else if (scope.focusedNode instanceof Blockly.Connection) {
325+
block = scope.focusedNode.getSourceBlock();
326+
}
317327
const ws = block?.workspace as WorkspaceSvg | null;
318328
if (!ws) return;
319329
return this.pasteCallback(ws);
320330
},
321-
scopeType: ContextMenuRegistry.ScopeType.BLOCK,
322331
id: 'blockPasteFromContextMenu',
323332
weight: BASE_WEIGHT + 2,
324333
};

src/actions/insert.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
import * as Constants from '../constants';
1313
import type {WorkspaceSvg} from 'blockly';
1414
import {Navigation} from '../navigation';
15-
import {ScopeWithConnection} from './action_menu';
15+
16+
import * as Blockly from 'blockly/core';
1617

1718
const KeyCodes = BlocklyUtils.KeyCodes;
1819

@@ -70,21 +71,25 @@ export class InsertAction {
7071
displayText: () => {
7172
return 'Insert Block (I)';
7273
},
73-
preconditionFn: (scope: ScopeWithConnection) => {
74-
const block = scope.block ?? scope.connection?.getSourceBlock();
74+
preconditionFn: (scope: ContextMenuRegistry.Scope) => {
75+
let block;
76+
if (scope.focusedNode instanceof Blockly.Block) {
77+
block = scope.focusedNode;
78+
} else if (scope.focusedNode instanceof Blockly.Connection) {
79+
block = scope.focusedNode.getSourceBlock();
80+
}
7581
const ws = block?.workspace as WorkspaceSvg | null;
7682
if (!ws) return 'hidden';
7783

7884
return this.insertPrecondition(ws) ? 'enabled' : 'hidden';
7985
},
80-
callback: (scope: ScopeWithConnection) => {
86+
callback: (scope: ContextMenuRegistry.Scope) => {
8187
const ws =
82-
scope.block?.workspace ??
83-
(scope.connection?.getSourceBlock().workspace as WorkspaceSvg);
88+
scope.focusedNode?.workspace ??
89+
(scope.focusedNode?.getSourceBlock().workspace as WorkspaceSvg);
8490
if (!ws) return false;
8591
this.insertCallback(ws);
8692
},
87-
scopeType: ContextMenuRegistry.ScopeType.BLOCK,
8893
id: 'insert',
8994
weight: 9,
9095
};

src/navigation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ export class Navigation {
404404
const passiveFocusNode = this.passiveFocusIndicator.getCurNode();
405405
this.passiveFocusIndicator.hide();
406406
const disposed = passiveFocusNode?.getSourceBlock()?.disposed;
407-
// If there's a gesture then it will either set the node if it has not
408-
// been disposed (which can happen when blocks are reloaded) or be a click
407+
// If there's a gesture then it will either set the node if it has not
408+
// been disposed (which can happen when blocks are reloaded) or be a click
409409
// that should not set one.
410410
if (!Blockly.Gesture.inProgress() && passiveFocusNode && !disposed) {
411411
cursor.setCurNode(passiveFocusNode);

0 commit comments

Comments
 (0)