FShortcut
The Facade API object to handle shortcuts in Univer
Access
Access through:
Setup
Register @univerjs/ui or a preset that includes it. In plugin mode, import @univerjs/ui/facade. Additional methods below require their listed plugin packages. See Facade setup.
@univerjs/ui
FShortcut.disableShortcut
Disable shortcuts of Univer.
disableShortcut(): thisReturns
The Facade API instance itself for chaining.
Examples
const fShortcut = univerAPI.getShortcut()fShortcut.disableShortcut()Package: @univerjs/ui · Type definitions
FShortcut.dispatchShortcutEvent
Dispatch a KeyboardEvent to the shortcut service and return the matched shortcut item.
dispatchShortcutEvent(e: KeyboardEvent): IShortcutItem<object> | undefinedParameters
e— Required. The KeyboardEvent to dispatch.
Returns
The matched shortcut item.
Examples
const fShortcut = univerAPI.getShortcut()const pseudoEvent = new KeyboardEvent('keydown', { key: 's', ctrlKey: true })const ifShortcutItem = fShortcut.dispatchShortcutEvent(pseudoEvent)if (ifShortcutItem) { const commandId = ifShortcutItem.id // Do something with the commandId.}Types: IShortcutItem · KeyboardEvent
Package: @univerjs/ui · Type definitions
FShortcut.enableShortcut
Enable shortcuts of Univer.
enableShortcut(): thisReturns
The Facade API instance itself for chaining.
Examples
fShortcut.enableShortcut() // Use the FShortcut instance used by disableShortcut before, do not create a new instancePackage: @univerjs/ui · Type definitions
FShortcut.triggerShortcut
Trigger shortcut of Univer by a KeyboardEvent and return the matched shortcut item.
triggerShortcut(e: KeyboardEvent): IShortcutItem<object> | undefinedParameters
e— Required. The KeyboardEvent to trigger.
Returns
The matched shortcut item.
Examples
// Assum the current sheet is empty sheet.const fWorkbook = univerAPI.getActiveWorkbook()const fWorksheet = fWorkbook.getSheetByName('Sheet1')if (!fWorksheet) throw new Error('fWorksheet is not available')const fRange = fWorksheet.getRange('A1')// Set A1 cell active and set value to 'Hello Univer'.fRange.activate()fRange.setValue('Hello Univer')console.log(fRange.getCellStyle().bold) // false// Set A1 cell bold by shortcut.const fShortcut = univerAPI.getShortcut()const pseudoEvent = new KeyboardEvent('keydown', { key: 'b', ctrlKey: true, keyCode: univerAPI.Enum.KeyCode.B,})const ifShortcutItem = fShortcut.triggerShortcut(pseudoEvent)if (ifShortcutItem) { const commandId = ifShortcutItem.id console.log(fRange.getCellStyle().bold) // true}Types: IShortcutItem · KeyboardEvent
Package: @univerjs/ui · Type definitions
How is this guide?