-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add keyboard shortcut to fit the diagram to the screen
- Loading branch information
Showing
7 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { KeyListener, SModelElementImpl } from "sprotty"; | ||
import { Action, CenterAction, FitToScreenAction } from "sprotty-protocol"; | ||
import { matchesKeystroke } from "sprotty/lib/utils/keyboard"; | ||
import { FIT_TO_SCREEN_PADDING } from "../utils"; | ||
|
||
/** | ||
* Key listener that fits the diagram to the screen when pressing Ctrl+Shift+F | ||
* and centers the diagram when pressing Ctrl+Shift+C. | ||
* | ||
* Custom version of the CenterKeyboardListener from sprotty because that one | ||
* does not allow setting a padding. | ||
*/ | ||
export class FitToScreenKeyListener extends KeyListener { | ||
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 []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters