Skip to content

Commit b03791d

Browse files
authored
Merge branch 'main' into block-comment-nav
2 parents 52cd210 + 48600df commit b03791d

18 files changed

+329
-205
lines changed

src/actions/action_menu.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ export class ActionMenu {
8686
// TODO(#362): Pass this through the precondition and callback instead of making it up.
8787
const menuOpenEvent = new KeyboardEvent('keydown');
8888

89-
const cursor = workspace.getCursor();
90-
if (!cursor) throw new Error('workspace has no cursor');
91-
const node = cursor.getCurNode();
89+
const node = workspace.getCursor().getCurNode();
9290
if (!node) return false;
9391
// TODO(google/blockly#8847): Add typeguard for IContextMenu in core when this moves over
9492
if (

src/actions/arrow_navigation.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ export class ArrowNavigation {
3838
workspace: WorkspaceSvg,
3939
shortcut: ShortcutRegistry.KeyboardShortcut,
4040
): boolean {
41-
const cursor = workspace.getCursor();
42-
if (!cursor || !cursor.getCurNode()) {
43-
return false;
44-
}
45-
const curNode = cursor.getCurNode();
41+
const curNode = workspace.getCursor().getCurNode();
4642
if (curNode instanceof Field) {
4743
return curNode.onShortcut(shortcut);
4844
}
@@ -70,7 +66,7 @@ export class ArrowNavigation {
7066
if (
7167
!this.navigation.defaultWorkspaceCursorPositionIfNeeded(workspace)
7268
) {
73-
workspace.getCursor()?.in();
69+
workspace.getCursor().in();
7470
}
7571
isHandled = true;
7672
}
@@ -103,7 +99,7 @@ export class ArrowNavigation {
10399
if (
104100
!this.navigation.defaultWorkspaceCursorPositionIfNeeded(workspace)
105101
) {
106-
workspace.getCursor()?.out();
102+
workspace.getCursor().out();
107103
}
108104
isHandled = true;
109105
}
@@ -169,7 +165,7 @@ export class ArrowNavigation {
169165
workspace,
170166
)
171167
) {
172-
workspace.getCursor()?.next();
168+
workspace.getCursor().next();
173169
}
174170
isHandled = true;
175171
}
@@ -182,7 +178,7 @@ export class ArrowNavigation {
182178
workspace.targetWorkspace,
183179
)
184180
) {
185-
workspace.getCursor()?.next();
181+
workspace.getCursor().next();
186182
}
187183
isHandled = true;
188184
}
@@ -232,7 +228,7 @@ export class ArrowNavigation {
232228
'last',
233229
)
234230
) {
235-
workspace.getCursor()?.prev();
231+
workspace.getCursor().prev();
236232
}
237233
isHandled = true;
238234
}
@@ -246,7 +242,7 @@ export class ArrowNavigation {
246242
'last',
247243
)
248244
) {
249-
workspace.getCursor()?.prev();
245+
workspace.getCursor().prev();
250246
}
251247
isHandled = true;
252248
}

src/actions/disconnect.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ export class DisconnectAction {
7878
*/
7979
disconnectBlocks(workspace: WorkspaceSvg) {
8080
const cursor = workspace.getCursor();
81-
if (!cursor) return;
8281
const curNode = cursor.getCurNode();
8382
if (!(curNode instanceof BlockSvg)) return;
8483

src/actions/edit.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {
8-
ContextMenuRegistry,
9-
LineCursor,
10-
Msg,
11-
keyboardNavigationController,
12-
} from 'blockly';
7+
import {ContextMenuRegistry, Msg, keyboardNavigationController} from 'blockly';
138
import {Navigation} from 'src/navigation';
149
import {getMenuItem} from '../shortcut_formatting';
1510
import * as Constants from '../constants';
@@ -67,7 +62,7 @@ export class EditAction {
6762
if (!workspace || !this.navigation.canCurrentlyNavigate(workspace)) {
6863
return 'disabled';
6964
}
70-
const cursor = workspace.getCursor() as LineCursor | null;
65+
const cursor = workspace.getCursor();
7166
if (!cursor) return 'disabled';
7267
return cursor.atEndOfLine() ? 'hidden' : 'enabled';
7368
},

src/actions/enter.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ export class EnterAction {
117117
private shouldHandleEnterForWS(workspace: WorkspaceSvg): boolean {
118118
if (!this.navigation.canCurrentlyNavigate(workspace)) return false;
119119

120-
const cursor = workspace.getCursor();
121-
const curNode = cursor?.getCurNode();
120+
const curNode = workspace.getCursor().getCurNode();
122121
if (!curNode) return false;
123122
if (curNode instanceof Field) return curNode.isClickable();
124123
if (
@@ -144,7 +143,7 @@ export class EnterAction {
144143
*/
145144
private handleEnterForWS(workspace: WorkspaceSvg): boolean {
146145
const cursor = workspace.getCursor();
147-
const curNode = cursor?.getCurNode();
146+
const curNode = cursor.getCurNode();
148147
if (!curNode) return false;
149148
if (curNode instanceof Field) {
150149
curNode.showEditor();
@@ -167,7 +166,7 @@ export class EnterAction {
167166
curNode.onClick();
168167
renderManagement.finishQueuedRenders().then(() => {
169168
if (hasBubble(curNode) && curNode.bubbleIsVisible()) {
170-
cursor?.in();
169+
cursor.in();
171170
}
172171
});
173172
return true;

src/actions/move.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class MoveActions {
260260
const node = getFocusManager().getFocusedNode();
261261
if (node instanceof comments.RenderedWorkspaceComment) return node;
262262

263-
let block = workspace?.getCursor()?.getSourceBlock();
263+
let block = workspace.getCursor().getSourceBlock();
264264
if (!block) return undefined;
265265
while (block.isShadow()) {
266266
block = block.getParent();

src/actions/mover.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export class Mover {
160160
// In case a block is detached, ensure that it still retains focus
161161
// (otherwise dragging will break). This is also the point a new block's
162162
// initial insert position is scrolled into view.
163-
workspace.getCursor()?.setCurNode(draggable);
163+
workspace.getCursor().setCurNode(draggable);
164164
draggable.getFocusableElement().addEventListener('blur', blurListener);
165165

166166
// Register a keyboard shortcut under the key combos of all existing
@@ -257,7 +257,7 @@ export class Mover {
257257
);
258258

259259
if (dragStrategy.moveType === MoveType.Insert && target) {
260-
workspace.getCursor()?.setCurNode(target);
260+
workspace.getCursor().setCurNode(target);
261261
}
262262

263263
this.postDragEndCleanup(workspace, info);

src/actions/ws_movement.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ export class WorkspaceMovement {
119119
* @param workspace The workspace the cursor is on.
120120
*/
121121
createWSCursor(workspace: WorkspaceSvg) {
122-
const cursor = workspace.getCursor();
123-
124-
if (!cursor) return false;
125-
126-
cursor.setCurNode(workspace);
122+
workspace.getCursor().setCurNode(workspace);
127123
return true;
128124
}
129125
}

src/flyout_cursor.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,18 @@ export class FlyoutCursor extends Blockly.LineCursor {
8989
export const registrationType = Blockly.registry.Type.CURSOR;
9090
export const registrationName = 'FlyoutCursor';
9191

92-
Blockly.registry.register(registrationType, registrationName, FlyoutCursor);
93-
9492
export const pluginInfo = {
9593
[registrationType.toString()]: registrationName,
9694
};
95+
96+
/**
97+
* Registers the FlyoutCursor with Blockly's registry.
98+
*/
99+
export function registerFlyoutCursor() {
100+
Blockly.registry.register(
101+
registrationType,
102+
registrationName,
103+
FlyoutCursor,
104+
true,
105+
);
106+
}

src/index.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,148 @@ export class KeyboardNavigation {
323323
.blocklyMenuItemContent .blocklyShortcutContainer .blocklyShortcut {
324324
color: #ccc;
325325
}
326+
`);
327+
328+
// Register classes used by the shortcuts modal
329+
Blockly.Css.register(`
330+
:root {
331+
--divider-border-color: #eee;
332+
--key-border-color: #ccc;
333+
--shortcut-modal-border-color: #9aa0a6;
334+
}
335+
336+
.shortcut-modal {
337+
border: 1px solid var(--shortcut-modal-border-color);
338+
border-radius: 12px;
339+
box-shadow: 6px 6px 32px rgba(0,0,0,.5);
340+
flex-direction: column;
341+
gap: 12px;
342+
margin: auto;
343+
max-height: 82vh;
344+
max-width: calc(100% - 10em);
345+
padding: 24px 12px 24px 32px;
346+
position: relative;
347+
z-index: 99;
348+
}
349+
350+
.shortcut-modal[open] {
351+
display: flex;
352+
}
353+
354+
.shortcut-modal .close-modal {
355+
border: 0;
356+
background: transparent;
357+
float: inline-end;
358+
margin: 0 0 0 0;
359+
position: absolute;
360+
top: 16px;
361+
right: 24px;
362+
}
363+
364+
.shortcut-modal h1 {
365+
font-weight: 600;
366+
font-size: 1.2em;
367+
}
368+
369+
.shortcut-modal:before {
370+
background: radial-gradient(rgba(244, 244, 244, 0.43), rgba(75, 75, 75, 0.51));
371+
align-items: center;
372+
display: block;
373+
font-family: Roboto;
374+
height: 100%;
375+
justify-content: center;
376+
left: 0;
377+
position: absolute;
378+
top: 0;
379+
width: 100%;
380+
}
381+
382+
.shortcut-tables {
383+
display: grid;
384+
align-items: start;
385+
grid-template-columns: 1fr;
386+
row-gap: 1em;
387+
column-gap: 2em;
388+
}
389+
390+
@media (min-width: 950px) {
391+
.shortcut-tables {
392+
grid-template-columns: 1fr 1fr
393+
}
394+
}
395+
396+
@media (min-width: 1360px) {
397+
.shortcut-tables {
398+
grid-template-columns: 1fr 1fr 1fr
399+
}
400+
}
401+
402+
.shortcut-table {
403+
border-collapse: collapse;
404+
font-family: Roboto;
405+
font-size: .9em;
406+
}
407+
408+
.shortcut-table th {
409+
padding-inline-end: 0.5em;
410+
text-align: left;
411+
text-wrap: nowrap;
412+
vertical-align: baseline;
413+
}
414+
415+
.shortcut-table td:first-child {
416+
text-wrap: auto;
417+
width: 40%;
418+
}
419+
420+
.shortcut-table tr:has(+ .category) {
421+
--divider-border-color: transparent;
422+
margin-end: 1em;
423+
}
424+
425+
.shortcut-table tr:not(.category, :last-child) {
426+
border-bottom: 1px solid var(--divider-border-color);
427+
}
428+
429+
.shortcut-table td {
430+
padding: 0.2em 1em 0.3em 0;
431+
text-wrap: nowrap;
432+
}
433+
434+
.shortcut-table h2 {
435+
border-bottom: 1px solid #999;
436+
font-size: 1em;
437+
padding-block-end: 0.5em;
438+
}
439+
440+
.shortcut-table .key {
441+
border: 1px solid var(--key-border-color);
442+
border-radius: 8px;
443+
display: inline-block;
444+
margin: 0 4px;
445+
min-width: 2em;
446+
padding: .3em .5em;
447+
text-align: center;
448+
}
449+
450+
.shortcut-table .separator {
451+
color: gray;
452+
display: inline-block;
453+
padding: 0 0.5em;
454+
}
455+
456+
.shortcut-container {
457+
font-size: 0.95em;
458+
overflow: auto;
459+
padding: 0.5em;
460+
}
461+
462+
.shortcut-combo {
463+
display: inline-block;
464+
padding: 0.25em 0;
465+
text-wrap: nowrap;
466+
}
467+
326468
`);
327469
}
328470
}

0 commit comments

Comments
 (0)