mirror of
https://github.com/excalidraw/excalidraw.git
synced 2026-12-05 18:55:28 +03:00
fix(editor): keep fit-and-enlarge zoom in the command palette with nothing selected
With nothing selected, "Zoom to selection" (Shift+3) fits the whole scene and, unlike "Zoom to fit all elements", also zooms in past 100%. Requiring a selection hid that. It's now listed as "Zoom to fit all elements (enlarge)" when nothing is selected.
This commit is contained in:
3 files changed
+20
-2
No files matched your search
@@ -313,6 +313,10 @@ function CommandPaletteInner({
|
||||
};
|
||||
|
||||
if (uiAppState && app.scene && actionManager) {
|
||||
const hasSelection =
|
||||
getSelectedElements(app.scene.getNonDeletedElements(), uiAppState)
|
||||
.length > 0;
|
||||
|
||||
const elementsCommands: CommandPaletteItem[] = [
|
||||
actionManager.actions.group,
|
||||
actionManager.actions.ungroup,
|
||||
@@ -336,7 +340,7 @@ function CommandPaletteInner({
|
||||
actionManager.actions.duplicateSelection,
|
||||
actionManager.actions.flipHorizontal,
|
||||
actionManager.actions.flipVertical,
|
||||
actionManager.actions.zoomToFitSelection,
|
||||
...(hasSelection ? [actionManager.actions.zoomToFitSelection] : []),
|
||||
actionManager.actions.zoomToFitSelectionInViewport,
|
||||
actionManager.actions.increaseFontSize,
|
||||
actionManager.actions.decreaseFontSize,
|
||||
@@ -382,6 +386,9 @@ function CommandPaletteInner({
|
||||
actionManager.actions.zoomOut,
|
||||
actionManager.actions.resetZoom,
|
||||
actionManager.actions.zoomToFit,
|
||||
// with nothing selected, "Zoom to selection" fits the whole scene and,
|
||||
// unlike "Zoom to fit all elements", also zooms in past 100%
|
||||
...(hasSelection ? [] : [actionManager.actions.zoomToFitSelection]),
|
||||
actionManager.actions.zenMode,
|
||||
actionManager.actions.viewMode,
|
||||
actionManager.actions.gridMode,
|
||||
@@ -393,7 +400,13 @@ function CommandPaletteInner({
|
||||
actionManager.actions.toggleElementLock,
|
||||
actionManager.actions.unlockAllElements,
|
||||
actionManager.actions.stats,
|
||||
].map((action) => actionToCommand(action, DEFAULT_CATEGORIES.editor));
|
||||
].map((action) =>
|
||||
actionToCommand(action, DEFAULT_CATEGORIES.editor, (command, action) =>
|
||||
action.name === "zoomToFitSelection"
|
||||
? { ...command, label: t("labels.zoomToFitEnlarge") }
|
||||
: command,
|
||||
),
|
||||
);
|
||||
|
||||
const exportCommands: CommandPaletteItem[] = [
|
||||
actionManager.actions.saveToActiveFile,
|
||||
|
||||
@@ -187,6 +187,7 @@
|
||||
"zoomToFitViewport": "Zoom to fit in viewport",
|
||||
"zoomToFitSelection": "Zoom to fit selection",
|
||||
"zoomToFit": "Zoom to fit all elements",
|
||||
"zoomToFitEnlarge": "Zoom to fit all elements (enlarge)",
|
||||
"installPWA": "Install Excalidraw locally (PWA)",
|
||||
"autoResize": "Enable text auto-resizing",
|
||||
"toggleAutoResize": "Toggle text auto-resizing",
|
||||
|
||||
@@ -133,6 +133,9 @@ describe("command palette", () => {
|
||||
for (const label of selectionCommands) {
|
||||
expect(getCommandNames()).not.toContain(label);
|
||||
}
|
||||
// "Zoom to selection" then fits the whole scene, under another name
|
||||
const zoomToFitEnlarge = "Zoom to fit all elements (enlarge)";
|
||||
expect(getCommandNames()).toContain(zoomToFitEnlarge);
|
||||
|
||||
act(() => {
|
||||
API.setAppState({ openDialog: null });
|
||||
@@ -144,6 +147,7 @@ describe("command palette", () => {
|
||||
expect.arrayContaining(selectionCommands),
|
||||
),
|
||||
);
|
||||
expect(getCommandNames()).not.toContain(zoomToFitEnlarge);
|
||||
});
|
||||
|
||||
it("lists the file, layout, library and text commands", async () => {
|
||||
|
||||
Reference in new issue
Block a user