-
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 4 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,51 @@ 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: | ||
| // The main workspace may or may not handle it depending on what's | ||
| // selected, so always pass it through to the callback. | ||
| return true; | ||
|
||
| 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 | ||
maribethb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // 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, | ||
| ); | ||
| if (targetWorkspace.isReadOnly()) return false; | ||
|
||
| 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; | ||
|
|
@@ -94,12 +111,13 @@ export class EnterAction { | |
| * 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; | ||
| if (!cursor) return false; | ||
| const curNode = cursor.getCurNode(); | ||
| if (!curNode) return; | ||
| if (!curNode) return false; | ||
| if (curNode instanceof Field) { | ||
| curNode.showEditor(); | ||
| } else if (curNode instanceof BlockSvg) { | ||
|
|
@@ -114,6 +132,7 @@ export class EnterAction { | |
| } else if (curNode instanceof icons.Icon) { | ||
| curNode.onClick(); | ||
| } | ||
| return true; | ||
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -278,7 +297,7 @@ export class EnterAction { | |
| if (block.isSimpleReporter()) { | ||
| for (const input of block.inputList) { | ||
| for (const field of input.fieldRow) { | ||
| if (field.isClickable() && field.isFullBlockField()) { | ||
| if (field.isFullBlockField()) { | ||
|
||
| field.showEditor(); | ||
| return true; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checking, is this change supposed to be here? it doesn't seem related to the PR title
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, not sure how this slipped in.