Class: FShortcut
The Facade API object to handle shortcuts in Univer
Extends
FBase
Methods
disableShortcut()
disableShortcut(): this
Disable shortcuts of Univer.
Returns
this
The Facade API instance itself for chaining.
Example
const fShortcut = univerAPI.getShortcut();
fShortcut.disableShortcut();
dispatchShortcutEvent()
dispatchShortcutEvent(e): any
Dispatch a KeyboardEvent to the shortcut service and return the matched shortcut item.
Parameters
Parameter | Type | Description |
---|---|---|
e | KeyboardEvent | The KeyboardEvent to dispatch. |
Returns
any
The matched shortcut item.
Example
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.
}
enableShortcut()
enableShortcut(): this
Enable shortcuts of Univer.
Returns
this
The Facade API instance itself for chaining.
Example
fShortcut.enableShortcut(); // Use the FShortcut instance used by disableShortcut before, do not create a new instance
triggerShortcut()
triggerShortcut(e): any
Trigger shortcut of Univer by a KeyboardEvent and return the matched shortcut item.
Parameters
Parameter | Type | Description |
---|---|---|
e | KeyboardEvent | The KeyboardEvent to trigger. |
Returns
any
The matched shortcut item.
Example
// Assum the current sheet is empty sheet.
const fWorkbook = univerAPI.getActiveWorkbook();
const fWorksheet = fWorkbook.getActiveSheet();
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
}