-
Notifications
You must be signed in to change notification settings - Fork 13
fix: Allow some things to handle the enter key on read only workspaces #597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6c865bc
a6f526d
bd45dd7
0695cfc
ffc9554
2f33035
bcaf238
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ | |
|
|
||
| import { | ||
| Events, | ||
| Msg, | ||
| ShortcutRegistry, | ||
| utils as BlocklyUtils, | ||
| getFocusManager, | ||
|
|
@@ -54,33 +53,48 @@ export class EnterAction { | |
| */ | ||
| ShortcutRegistry.registry.register({ | ||
| name: Constants.SHORTCUT_NAMES.EDIT_OR_CONFIRM, | ||
| preconditionFn: (workspace) => | ||
| this.navigation.canCurrentlyEdit(workspace), | ||
| callback: (workspace, event) => { | ||
| preconditionFn: (workspace): boolean => { | ||
| switch (this.navigation.getState()) { | ||
| case Constants.STATE.WORKSPACE: | ||
| return this.shouldHandleEnterForWS(workspace); | ||
| case Constants.STATE.FLYOUT: { | ||
| // If we're in the flyout the only supported actions are inserting | ||
| // blocks or clicking buttons, so don't handle this if the | ||
| // main workspace is read only. | ||
| const targetWorkspace = workspace.isFlyout | ||
| ? workspace.targetWorkspace | ||
| : workspace; | ||
| return !!targetWorkspace && !targetWorkspace.isReadOnly(); | ||
| } | ||
| default: | ||
| return false; | ||
| } | ||
| }, | ||
| callback: (workspace, event): boolean => { | ||
| event.preventDefault(); | ||
|
|
||
| const targetWorkspace = workspace.isFlyout | ||
| ? workspace.targetWorkspace | ||
| : workspace; | ||
| if (!targetWorkspace) return false; | ||
|
|
||
| let flyoutCursor; | ||
| let curNode; | ||
|
|
||
| switch (this.navigation.getState(workspace)) { | ||
| switch (this.navigation.getState()) { | ||
| case Constants.STATE.WORKSPACE: | ||
| this.handleEnterForWS(workspace); | ||
| return true; | ||
| return this.handleEnterForWS(workspace); | ||
| case Constants.STATE.FLYOUT: | ||
| if (!workspace.targetWorkspace) return false; | ||
| flyoutCursor = this.navigation.getFlyoutCursor( | ||
| workspace.targetWorkspace, | ||
| ); | ||
| flyoutCursor = this.navigation.getFlyoutCursor(targetWorkspace); | ||
| if (!flyoutCursor) { | ||
| return false; | ||
| } | ||
| curNode = flyoutCursor.getCurNode(); | ||
| if (curNode instanceof BlockSvg) { | ||
| this.insertFromFlyout(workspace.targetWorkspace); | ||
| this.insertFromFlyout(targetWorkspace); | ||
| } else if (curNode instanceof FlyoutButton) { | ||
| this.triggerButtonCallback(workspace); | ||
| } | ||
|
|
||
| return true; | ||
| default: | ||
| return false; | ||
|
|
@@ -90,16 +104,31 @@ export class EnterAction { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the enter key should do anything for this ws. | ||
| * | ||
| * @param workspace The workspace to check. | ||
| * @returns True if the enter action should be handled. | ||
| */ | ||
| private shouldHandleEnterForWS(workspace: WorkspaceSvg): boolean { | ||
| const cursor = workspace.getCursor(); | ||
| const curNode = cursor?.getCurNode(); | ||
| if (!curNode) return false; | ||
| if (curNode instanceof Field && !curNode.isClickable()) return false; | ||
| // Returning true is sometimes incorrect for icons, but there's no API to check. | ||
| return true; | ||
|
||
| } | ||
|
|
||
| /** | ||
| * Handles hitting the enter key on the workspace. | ||
| * | ||
| * @param workspace The workspace. | ||
| * @returns True if the enter was handled, false otherwise. | ||
| */ | ||
| private handleEnterForWS(workspace: WorkspaceSvg) { | ||
| private handleEnterForWS(workspace: WorkspaceSvg): boolean { | ||
| const cursor = workspace.getCursor(); | ||
| if (!cursor) return; | ||
| const curNode = cursor.getCurNode(); | ||
| if (!curNode) return; | ||
| const curNode = cursor?.getCurNode(); | ||
| if (!curNode) return false; | ||
| if (curNode instanceof Field) { | ||
| curNode.showEditor(); | ||
| } else if (curNode instanceof BlockSvg) { | ||
|
|
@@ -114,6 +143,7 @@ export class EnterAction { | |
| } else if (curNode instanceof icons.Icon) { | ||
| curNode.onClick(); | ||
| } | ||
| return true; | ||
|
||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.