@atlaskit/editor-plugin-undo-redo
Version:
Undo redo plugin for @atlaskit/editor-core
23 lines • 1.13 kB
JavaScript
export const closeTypeAheadAndRunCommand = (editorView, api) => command => {
var _api$typeAhead, _api$typeAhead$action;
if (!editorView) {
return false;
}
if (api !== null && api !== void 0 && (_api$typeAhead = api.typeAhead) !== null && _api$typeAhead !== void 0 && (_api$typeAhead$action = _api$typeAhead.actions) !== null && _api$typeAhead$action !== void 0 && _api$typeAhead$action.isOpen(editorView.state)) {
var _api$typeAhead2, _api$typeAhead2$actio;
api === null || api === void 0 ? void 0 : (_api$typeAhead2 = api.typeAhead) === null || _api$typeAhead2 === void 0 ? void 0 : (_api$typeAhead2$actio = _api$typeAhead2.actions) === null || _api$typeAhead2$actio === void 0 ? void 0 : _api$typeAhead2$actio.close({
attachCommand: command,
insertCurrentQueryAsRawText: false
});
} else {
command(editorView.state, editorView.dispatch);
}
return true;
};
export const forceFocus = (editorView, api) => command => {
const result = closeTypeAheadAndRunCommand(editorView, api)(command);
if (result && !editorView.hasFocus()) {
editorView.focus();
}
return result;
};