feat: Add cmd+o shortcut to load scene (#2732)

This commit is contained in:
David Luzar 2021-01-06 13:36:55 +01:00 committed by GitHub
parent e16266ce5d
commit 778e4b08af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 23 deletions

View File

@ -9,7 +9,6 @@ import { loadFromJSON, saveAsJSON } from "../data";
import { t } from "../i18n"; import { t } from "../i18n";
import useIsMobile from "../is-mobile"; import useIsMobile from "../is-mobile";
import { KEYS } from "../keys"; import { KEYS } from "../keys";
import { muteFSAbortError } from "../utils";
import { register } from "./register"; import { register } from "./register";
export const actionChangeProjectName = register({ export const actionChangeProjectName = register({
@ -156,18 +155,29 @@ export const actionSaveAsScene = register({
export const actionLoadScene = register({ export const actionLoadScene = register({
name: "loadScene", name: "loadScene",
perform: ( perform: async (elements, appState) => {
elements, try {
appState, const {
{ elements: loadedElements, appState: loadedAppState, error },
) => ({
elements: loadedElements, elements: loadedElements,
appState: { appState: loadedAppState,
...loadedAppState, } = await loadFromJSON(appState);
errorMessage: error, return {
}, elements: loadedElements,
appState: loadedAppState,
commitToHistory: true, commitToHistory: true,
}), };
} catch (error) {
if (error?.name === "AbortError") {
return false;
}
return {
elements,
appState: { ...appState, errorMessage: error.message },
commitToHistory: false,
};
}
},
keyTest: (event) => event[KEYS.CTRL_OR_CMD] && event.key === KEYS.O,
PanelComponent: ({ updateData, appState }) => ( PanelComponent: ({ updateData, appState }) => (
<ToolButton <ToolButton
type="button" type="button"
@ -175,16 +185,7 @@ export const actionLoadScene = register({
title={t("buttons.load")} title={t("buttons.load")}
aria-label={t("buttons.load")} aria-label={t("buttons.load")}
showAriaLabel={useIsMobile()} showAriaLabel={useIsMobile()}
onClick={() => { onClick={updateData}
loadFromJSON(appState)
.then(({ elements, appState }) => {
updateData({ elements, appState });
})
.catch(muteFSAbortError)
.catch((error) => {
updateData({ error: error.message });
});
}}
/> />
), ),
}); });

View File

@ -40,6 +40,7 @@ export const KEYS = {
D: "d", D: "d",
E: "e", E: "e",
L: "l", L: "l",
O: "o",
P: "p", P: "p",
Q: "q", Q: "q",
R: "r", R: "r",

View File

@ -16,6 +16,7 @@ Please add the latest change on the top under the correct section.
### Features ### Features
- Add `cmd+o` shortcut to load scene [#2732](https://github.com/excalidraw/excalidraw/pull/2732)
- Remove language picker, and add `langCode`, `renderFooter` [#2644](https://github.com/excalidraw/excalidraw/pull/2644): - Remove language picker, and add `langCode`, `renderFooter` [#2644](https://github.com/excalidraw/excalidraw/pull/2644):
- BREAKING: removed the language picker from UI. It is now the host app's responsibility to implement a language picker if desirable, using the newly added [`renderFooter`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#renderFooter) prop. The reasoning is that the i18n should be controlled by the app itself, not by the nested Excalidraw component. - BREAKING: removed the language picker from UI. It is now the host app's responsibility to implement a language picker if desirable, using the newly added [`renderFooter`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#renderFooter) prop. The reasoning is that the i18n should be controlled by the app itself, not by the nested Excalidraw component.
- Added [`langCode`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#langCode) prop to control the UI language. - Added [`langCode`](https://github.com/excalidraw/excalidraw/blob/master/src/packages/excalidraw/README.md#langCode) prop to control the UI language.