Skip to content

Commit

Permalink
feat: add align shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
F-star committed Sep 8, 2024
1 parent 1c46772 commit 3fa6470
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
58 changes: 57 additions & 1 deletion packages/core/src/host_event_manager/command_key_binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import {
SuikaText,
} from '../graphs';
import {
alignAndRecord,
arrangeAndRecord,
flipHorizontalAndRecord,
flipVerticalAndRecord,
MutateGraphsAndRecord,
ungroupAndRecord,
} from '../service';
import { groupAndRecord } from '../service/group_and_record';
import { ArrangeType } from '../type';
import { AlignType, ArrangeType } from '../type';

export class CommandKeyBinding {
private isBound = false;
Expand Down Expand Up @@ -248,6 +249,61 @@ export class CommandKeyBinding {
action: backwardAction,
});

/*************** align **************/
editor.keybindingManager.register({
key: { altKey: true, keyCode: 'KeyA' },
when: (ctx) => !ctx.isToolDragging,
actionName: 'AlignLeft',
action: () => {
alignAndRecord(editor, AlignType.Left);
},
});

editor.keybindingManager.register({
key: { altKey: true, keyCode: 'KeyH' },
when: (ctx) => !ctx.isToolDragging,
actionName: 'AlignHorizontalCenters',
action: () => {
alignAndRecord(editor, AlignType.HCenter);
},
});

editor.keybindingManager.register({
key: { altKey: true, keyCode: 'KeyD' },
when: (ctx) => !ctx.isToolDragging,
actionName: 'AlignRight',
action: () => {
alignAndRecord(editor, AlignType.Right);
},
});

editor.keybindingManager.register({
key: { altKey: true, keyCode: 'KeyW' },
when: (ctx) => !ctx.isToolDragging,
actionName: 'AlignTop',
action: () => {
alignAndRecord(editor, AlignType.Top);
},
});

editor.keybindingManager.register({
key: { altKey: true, keyCode: 'KeyV' },
when: (ctx) => !ctx.isToolDragging,
actionName: 'AlignVerticalCenters',
action: () => {
alignAndRecord(editor, AlignType.VCenter);
},
});

editor.keybindingManager.register({
key: { altKey: true, keyCode: 'KeyS' },
when: (ctx) => !ctx.isToolDragging,
actionName: 'AlignBottom',
action: () => {
alignAndRecord(editor, AlignType.Bottom);
},
});

/*************** group **************/
// group
const groupAction = () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/service/align_and_record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const alignAndRecord = (editor: SuikaEditor, type: AlignType) => {
const worldTfs = graphicsArr.map((item) => item.getWorldTransform());
const mixedBBox = mergeBoxes(bboxes);

// TODO: check whether had align

const transaction = new Transaction(editor);

const updateGraphicsPosition = (
Expand Down

0 comments on commit 3fa6470

Please sign in to comment.