Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New default diagram #37

Merged
merged 2 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/common/commandPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
SModelRootImpl,
CommitModelAction,
} from "sprotty";
import { FitToScreenAction, Point } from "sprotty-protocol";
import { Point } from "sprotty-protocol";
import { LoadDiagramAction } from "../features/serialize/load";
import { FIT_TO_SCREEN_PADDING } from "../utils";
import { createDefaultFitToScreenAction } from "../utils";
import { SaveDiagramAction } from "../features/serialize/save";
import { LoadDefaultDiagramAction } from "../features/serialize/loadDefaultDiagram";
import { LayoutModelAction } from "../features/autoLayout/command";
Expand All @@ -23,15 +23,12 @@ import "./commandPalette.css";
@injectable()
export class ServerCommandPaletteActionProvider implements ICommandPaletteActionProvider {
async getActions(
_root: Readonly<SModelRootImpl>,
root: Readonly<SModelRootImpl>,
_text: string,
_lastMousePosition?: Point,
_index?: number,
): Promise<LabeledAction[]> {
const fitToScreenAction = FitToScreenAction.create(
[], // empty elementIds means fit the whole diagram
{ padding: FIT_TO_SCREEN_PADDING },
);
const fitToScreenAction = createDefaultFitToScreenAction(root);
const commitAction = CommitModelAction.create();

return [
Expand Down
12 changes: 4 additions & 8 deletions src/common/fitToScreenKeyListener.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KeyListener, SModelElementImpl } from "sprotty";
import { Action, CenterAction, FitToScreenAction } from "sprotty-protocol";
import { Action, CenterAction } from "sprotty-protocol";
import { matchesKeystroke } from "sprotty/lib/utils/keyboard";
import { FIT_TO_SCREEN_PADDING } from "../utils";
import { createDefaultFitToScreenAction } from "../utils";

/**
* Key listener that fits the diagram to the screen when pressing Ctrl+Shift+F
Expand All @@ -11,17 +11,13 @@ import { FIT_TO_SCREEN_PADDING } from "../utils";
* does not allow setting a padding.
*/
export class FitToScreenKeyListener extends KeyListener {
override keyDown(_element: SModelElementImpl, event: KeyboardEvent): Action[] {
override keyDown(element: SModelElementImpl, event: KeyboardEvent): Action[] {
if (matchesKeystroke(event, "KeyC", "ctrlCmd", "shift")) {
return [CenterAction.create([])];
}

if (matchesKeystroke(event, "KeyF", "ctrlCmd", "shift")) {
return [
FitToScreenAction.create([], {
padding: FIT_TO_SCREEN_PADDING,
}),
];
return [createDefaultFitToScreenAction(element.root)];
}

return [];
Expand Down
11 changes: 4 additions & 7 deletions src/features/autoLayout/keyListener.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import { CommitModelAction, KeyListener, SModelElementImpl } from "sprotty";
import { matchesKeystroke } from "sprotty/lib/utils/keyboard";
import { Action, FitToScreenAction } from "sprotty-protocol";
import { Action } from "sprotty-protocol";
import { LayoutModelAction } from "./command";
import { FIT_TO_SCREEN_PADDING } from "../../utils";
import { createDefaultFitToScreenAction } from "../../utils";

export class AutoLayoutKeyListener extends KeyListener {
keyDown(_element: SModelElementImpl, event: KeyboardEvent): Action[] {
keyDown(element: SModelElementImpl, event: KeyboardEvent): Action[] {
if (matchesKeystroke(event, "KeyL", "ctrlCmd")) {
event.preventDefault();

return [
LayoutModelAction.create(),
CommitModelAction.create(),
FitToScreenAction.create(
[], // empty elementIds means fit the whole diagram
{ padding: FIT_TO_SCREEN_PADDING },
),
createDefaultFitToScreenAction(element.root),
];
}

Expand Down
Loading