Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/actions/exit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {ShortcutRegistry, utils as BlocklyUtils} from 'blockly/core';

import type {WorkspaceSvg} from 'blockly/core';

import * as Constants from '../constants';
import type {Navigation} from '../navigation';

const KeyCodes = BlocklyUtils.KeyCodes;

/**
* Class for registering a shortcut for the exit action.
*/
export class ExitAction {
constructor(
private navigation: Navigation,
private canCurrentlyNavigate: (ws: WorkspaceSvg) => boolean,
) {}

/**
* Adds the exit action shortcut to the registry.
*/
install() {
ShortcutRegistry.registry.register({
name: Constants.SHORTCUT_NAMES.EXIT,
preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace),
callback: (workspace) => {
switch (this.navigation.getState(workspace)) {
case Constants.STATE.FLYOUT:
case Constants.STATE.TOOLBOX:
this.navigation.focusWorkspace(workspace);
return true;
default:
return false;
}
},
keyCodes: [KeyCodes.ESC],
allowCollision: true,
});
}

/**
* Removes the exit action shortcut.
*/
uninstall() {
ShortcutRegistry.registry.unregister(Constants.SHORTCUT_NAMES.EXIT);
}
}
28 changes: 7 additions & 21 deletions src/navigation_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {DeleteAction} from './actions/delete';
import {InsertAction} from './actions/insert';
import {Clipboard} from './actions/clipboard';
import {WorkspaceMovement} from './actions/ws_movement';
import {ExitAction} from './actions/exit';
import {EnterAction} from './actions/enter';
import {DisconnectAction} from './actions/disconnect';

Expand Down Expand Up @@ -84,12 +85,15 @@ export class NavigationController {
this.canCurrentlyEdit.bind(this),
);

exitAction: ExitAction = new ExitAction(
this.navigation,
this.canCurrentlyNavigate.bind(this),

enterAction: EnterAction = new EnterAction(
this.navigation,
this.canCurrentlyEdit.bind(this),
);

hasNavigationFocus: boolean = false;
navigationFocus: NAVIGATION_FOCUS_MODE = NAVIGATION_FOCUS_MODE.NONE;

/**
Expand Down Expand Up @@ -489,26 +493,6 @@ export class NavigationController {
keyCodes: [KeyCodes.T],
},

/** Exit the current location and focus on the workspace. */
exit: {
name: Constants.SHORTCUT_NAMES.EXIT,
preconditionFn: (workspace) => this.canCurrentlyNavigate(workspace),
callback: (workspace) => {
switch (this.navigation.getState(workspace)) {
case Constants.STATE.FLYOUT:
this.navigation.focusWorkspace(workspace);
return true;
case Constants.STATE.TOOLBOX:
this.navigation.focusWorkspace(workspace);
return true;
default:
return false;
}
},
keyCodes: [KeyCodes.ESC],
allowCollision: true,
},

/** Announce the current location of the cursor. */
announceLocation: {
name: Constants.SHORTCUT_NAMES.ANNOUNCE,
Expand Down Expand Up @@ -655,6 +639,7 @@ export class NavigationController {
this.deleteAction.install();
this.insertAction.install();
this.workspaceMovement.install();
this.exitAction.install();
this.enterAction.install();
this.disconnectAction.install();

Expand All @@ -680,6 +665,7 @@ export class NavigationController {
this.disconnectAction.uninstall();
this.clipboard.uninstall();
this.workspaceMovement.uninstall();
this.exitAction.uninstall();
this.enterAction.uninstall();
this.shortcutDialog.uninstall();

Expand Down