mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Add Command API to Grist Plugin API
Summary: The new Command API provides limited access to Grist Commands from within cusotm widgets. This includes the ability to perform undo and redo, which is bound to the same keyboard shortcut as Grist by default. Test Plan: Browser tests. Reviewers: jarek Reviewed By: jarek Subscribers: paulfitz, jarek Differential Revision: https://phab.getgrist.com/D4050
This commit is contained in:
@@ -65,6 +65,8 @@ export const widgetApi = rpc.getStub<WidgetAPI>('WidgetAPI', checkers.WidgetAPI)
|
||||
*/
|
||||
export const sectionApi = rpc.getStub<CustomSectionAPI>('CustomSectionAPI', checkers.CustomSectionAPI);
|
||||
|
||||
export const commandApi = rpc.getStub<any>('CommandAPI');
|
||||
|
||||
/**
|
||||
* Shortcut for [[GristView.allowSelectBy]].
|
||||
*/
|
||||
@@ -437,6 +439,12 @@ export async function addImporter(name: string, path: string, mode: 'fullscreen'
|
||||
});
|
||||
}
|
||||
|
||||
export function enableKeyboardShortcuts() {
|
||||
const Mousetrap = require('mousetrap');
|
||||
Mousetrap.bind('mod+z', () => commandApi.run('undo'));
|
||||
Mousetrap.bind(['mod+shift+z', 'ctrl+y'], () => commandApi.run('redo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Options when initializing connection to Grist.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user