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 useIsMobile from "../is-mobile";
import { KEYS } from "../keys";
import { muteFSAbortError } from "../utils";
import { register } from "./register";
export const actionChangeProjectName = register({
@ -156,18 +155,29 @@ export const actionSaveAsScene = register({
export const actionLoadScene = register({
name: "loadScene",
perform: (
elements,
appState,
{ elements: loadedElements, appState: loadedAppState, error },
) => ({
elements: loadedElements,
appState: {
...loadedAppState,
errorMessage: error,
},
commitToHistory: true,
}),
perform: async (elements, appState) => {
try {
const {
elements: loadedElements,
appState: loadedAppState,
} = await loadFromJSON(appState);
return {
elements: loadedElements,
appState: loadedAppState,
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 }) => (
<ToolButton
type="button"
@ -175,16 +185,7 @@ export const actionLoadScene = register({
title={t("buttons.load")}
aria-label={t("buttons.load")}
showAriaLabel={useIsMobile()}
onClick={() => {
loadFromJSON(appState)
.then(({ elements, appState }) => {
updateData({ elements, appState });
})
.catch(muteFSAbortError)
.catch((error) => {
updateData({ error: error.message });
});
}}
onClick={updateData}
/>
),
});

View File

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

View File

@ -16,6 +16,7 @@ Please add the latest change on the top under the correct section.
### 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):
- 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.