99import { BlockSvg } from './block_svg.js' ;
1010import * as clipboard from './clipboard.js' ;
1111import { RenderedWorkspaceComment } from './comments.js' ;
12+ import * as contextmenu from './contextmenu.js' ;
1213import * as eventUtils from './events/utils.js' ;
1314import { getFocusManager } from './focus_manager.js' ;
15+ import { hasContextMenu } from './interfaces/i_contextmenu.js' ;
1416import { isCopyable as isICopyable } from './interfaces/i_copyable.js' ;
1517import { isDeletable as isIDeletable } from './interfaces/i_deletable.js' ;
1618import { isDraggable } from './interfaces/i_draggable.js' ;
@@ -33,6 +35,7 @@ export enum names {
3335 PASTE = 'paste' ,
3436 UNDO = 'undo' ,
3537 REDO = 'redo' ,
38+ MENU = 'menu' ,
3639}
3740
3841/**
@@ -134,10 +137,7 @@ function isCuttable(focused: IFocusableNode): boolean {
134137 */
135138export function registerCopy ( ) {
136139 const ctrlC = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . C , [
137- KeyCodes . CTRL ,
138- ] ) ;
139- const metaC = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . C , [
140- KeyCodes . META ,
140+ KeyCodes . CTRL_CMD ,
141141 ] ) ;
142142
143143 const copyShortcut : KeyboardShortcut = {
@@ -179,7 +179,7 @@ export function registerCopy() {
179179 : undefined ;
180180 return ! ! clipboard . copy ( focused , copyCoords ) ;
181181 } ,
182- keyCodes : [ ctrlC , metaC ] ,
182+ keyCodes : [ ctrlC ] ,
183183 } ;
184184 ShortcutRegistry . registry . register ( copyShortcut ) ;
185185}
@@ -189,10 +189,7 @@ export function registerCopy() {
189189 */
190190export function registerCut ( ) {
191191 const ctrlX = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . X , [
192- KeyCodes . CTRL ,
193- ] ) ;
194- const metaX = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . X , [
195- KeyCodes . META ,
192+ KeyCodes . CTRL_CMD ,
196193 ] ) ;
197194
198195 const cutShortcut : KeyboardShortcut = {
@@ -224,7 +221,7 @@ export function registerCut() {
224221 }
225222 return ! ! copyData ;
226223 } ,
227- keyCodes : [ ctrlX , metaX ] ,
224+ keyCodes : [ ctrlX ] ,
228225 } ;
229226
230227 ShortcutRegistry . registry . register ( cutShortcut ) ;
@@ -235,10 +232,7 @@ export function registerCut() {
235232 */
236233export function registerPaste ( ) {
237234 const ctrlV = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . V , [
238- KeyCodes . CTRL ,
239- ] ) ;
240- const metaV = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . V , [
241- KeyCodes . META ,
235+ KeyCodes . CTRL_CMD ,
242236 ] ) ;
243237
244238 const pasteShortcut : KeyboardShortcut = {
@@ -309,7 +303,7 @@ export function registerPaste() {
309303 const centerCoords = new Coordinate ( left + width / 2 , top + height / 2 ) ;
310304 return ! ! clipboard . paste ( copyData , targetWorkspace , centerCoords ) ;
311305 } ,
312- keyCodes : [ ctrlV , metaV ] ,
306+ keyCodes : [ ctrlV ] ,
313307 } ;
314308
315309 ShortcutRegistry . registry . register ( pasteShortcut ) ;
@@ -320,10 +314,7 @@ export function registerPaste() {
320314 */
321315export function registerUndo ( ) {
322316 const ctrlZ = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . Z , [
323- KeyCodes . CTRL ,
324- ] ) ;
325- const metaZ = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . Z , [
326- KeyCodes . META ,
317+ KeyCodes . CTRL_CMD ,
327318 ] ) ;
328319
329320 const undoShortcut : KeyboardShortcut = {
@@ -342,7 +333,7 @@ export function registerUndo() {
342333 e . preventDefault ( ) ;
343334 return true ;
344335 } ,
345- keyCodes : [ ctrlZ , metaZ ] ,
336+ keyCodes : [ ctrlZ ] ,
346337 } ;
347338 ShortcutRegistry . registry . register ( undoShortcut ) ;
348339}
@@ -353,13 +344,10 @@ export function registerUndo() {
353344 */
354345export function registerRedo ( ) {
355346 const ctrlShiftZ = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . Z , [
356- KeyCodes . CTRL ,
357- KeyCodes . SHIFT ,
358- ] ) ;
359- const metaShiftZ = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . Z , [
360- KeyCodes . META ,
347+ KeyCodes . CTRL_CMD ,
361348 KeyCodes . SHIFT ,
362349 ] ) ;
350+
363351 // Ctrl-y is redo in Windows. Command-y is never valid on Macs.
364352 const ctrlY = ShortcutRegistry . registry . createSerializedKey ( KeyCodes . Y , [
365353 KeyCodes . CTRL ,
@@ -381,11 +369,40 @@ export function registerRedo() {
381369 e . preventDefault ( ) ;
382370 return true ;
383371 } ,
384- keyCodes : [ ctrlShiftZ , metaShiftZ , ctrlY ] ,
372+ keyCodes : [ ctrlShiftZ , ctrlY ] ,
385373 } ;
386374 ShortcutRegistry . registry . register ( redoShortcut ) ;
387375}
388376
377+ /**
378+ * Keyboard shortcut to show the context menu on ctrl/cmd+Enter.
379+ */
380+ export function registerShowContextMenu ( ) {
381+ const ctrlEnter = ShortcutRegistry . registry . createSerializedKey (
382+ KeyCodes . ENTER ,
383+ [ KeyCodes . CTRL_CMD ] ,
384+ ) ;
385+
386+ const contextMenuShortcut : KeyboardShortcut = {
387+ name : names . MENU ,
388+ preconditionFn : ( workspace ) => {
389+ return ! workspace . isDragging ( ) ;
390+ } ,
391+ callback : ( workspace , e ) => {
392+ const target = getFocusManager ( ) . getFocusedNode ( ) ;
393+ if ( hasContextMenu ( target ) ) {
394+ target . showContextMenu ( e ) ;
395+ contextmenu . getMenu ( ) ?. highlightNext ( ) ;
396+
397+ return true ;
398+ }
399+ return false ;
400+ } ,
401+ keyCodes : [ ctrlEnter ] ,
402+ } ;
403+ ShortcutRegistry . registry . register ( contextMenuShortcut ) ;
404+ }
405+
389406/**
390407 * Registers all default keyboard shortcut item. This should be called once per
391408 * instance of KeyboardShortcutRegistry.
@@ -400,6 +417,7 @@ export function registerDefaultShortcuts() {
400417 registerPaste ( ) ;
401418 registerUndo ( ) ;
402419 registerRedo ( ) ;
420+ registerShowContextMenu ( ) ;
403421}
404422
405423registerDefaultShortcuts ( ) ;
0 commit comments