add Ctrl+A and Ctrl+Shift+A shortcuts to select
selects all layer content and all visible (still only on current layer) Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
dda2461496
commit
874e39de4b
3 changed files with 68 additions and 30 deletions
|
@ -350,7 +350,7 @@
|
|||
<!-- Base Libs -->
|
||||
<script src="js/lib/util.js?v=49a78a6" type="text/javascript"></script>
|
||||
<script src="js/lib/events.js?v=2ab7933" type="text/javascript"></script>
|
||||
<script src="js/lib/input.js?v=09298ac" type="text/javascript"></script>
|
||||
<script src="js/lib/input.js?v=aa14afc" type="text/javascript"></script>
|
||||
<script src="js/lib/layers.js?v=a1f8aea" type="text/javascript"></script>
|
||||
<script src="js/lib/commands.js?v=bf23c83" type="text/javascript"></script>
|
||||
|
||||
|
@ -388,7 +388,7 @@
|
|||
src="js/ui/tool/colorbrush.js?v=3f8c01a"
|
||||
type="text/javascript"></script>
|
||||
<script
|
||||
src="js/ui/tool/select.js?v=d149dc5"
|
||||
src="js/ui/tool/select.js?v=3c70aea"
|
||||
type="text/javascript"></script>
|
||||
<script src="js/ui/tool/stamp.js?v=4a86ff8" type="text/javascript"></script>
|
||||
<script
|
||||
|
|
|
@ -615,6 +615,7 @@ window.onkeydown = (evn) => {
|
|||
!!callback.alt === evn.altKey &&
|
||||
!!callback.shift === evn.shiftKey
|
||||
) {
|
||||
evn.preventDefault();
|
||||
// onshortcut event
|
||||
keyboard.listen.onshortcut.emit({
|
||||
target: evn.target,
|
||||
|
|
|
@ -25,6 +25,11 @@ const selectTransformTool = () =>
|
|||
uil.onactive.on(state.uilayeractivecb);
|
||||
|
||||
// Registers keyboard shortcuts
|
||||
keyboard.onShortcut({ctrl: true, key: "KeyA"}, state.ctrlacb);
|
||||
keyboard.onShortcut(
|
||||
{ctrl: true, shift: true, key: "KeyA"},
|
||||
state.ctrlsacb
|
||||
);
|
||||
keyboard.onShortcut({ctrl: true, key: "KeyC"}, state.ctrlccb);
|
||||
keyboard.onShortcut({ctrl: true, key: "KeyV"}, state.ctrlvcb);
|
||||
keyboard.onShortcut({ctrl: true, key: "KeyX"}, state.ctrlxcb);
|
||||
|
@ -49,6 +54,8 @@ const selectTransformTool = () =>
|
|||
|
||||
keyboard.listen.onkeyclick.clear(state.keyclickcb);
|
||||
keyboard.listen.onkeydown.clear(state.keydowncb);
|
||||
keyboard.deleteShortcut(state.ctrlacb, "KeyA");
|
||||
keyboard.deleteShortcut(state.ctrlsacb, "KeyA");
|
||||
keyboard.deleteShortcut(state.ctrlccb, "KeyC");
|
||||
keyboard.deleteShortcut(state.ctrlvcb, "KeyV");
|
||||
keyboard.deleteShortcut(state.ctrlxcb, "KeyX");
|
||||
|
@ -387,6 +394,29 @@ const selectTransformTool = () =>
|
|||
};
|
||||
|
||||
// Handles left mouse drag end events
|
||||
|
||||
/** @type {(bb: BoundingBox) => void} */
|
||||
const select = (bb) => {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = bb.w;
|
||||
canvas.height = bb.h;
|
||||
canvas
|
||||
.getContext("2d")
|
||||
.drawImage(uil.canvas, bb.x, bb.y, bb.w, bb.h, 0, 0, bb.w, bb.h);
|
||||
|
||||
uil.ctx.clearRect(bb.x, bb.y, bb.w, bb.h);
|
||||
|
||||
state.original = {
|
||||
...bb,
|
||||
sx: bb.center.x,
|
||||
sy: bb.center.y,
|
||||
layer: uil.layer,
|
||||
};
|
||||
state.selected = new _tool.MarqueeSelection(canvas, bb.center);
|
||||
|
||||
state.redraw();
|
||||
};
|
||||
|
||||
state.dragendcb = (evn) => {
|
||||
const {x, y, sx, sy} = _tool._process_cursor(evn, state.snapToGrid);
|
||||
|
||||
|
@ -397,34 +427,7 @@ const selectTransformTool = () =>
|
|||
|
||||
state.reset();
|
||||
|
||||
if (selection.exists && bb.w !== 0 && bb.h !== 0) {
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = bb.w;
|
||||
canvas.height = bb.h;
|
||||
canvas
|
||||
.getContext("2d")
|
||||
.drawImage(
|
||||
uil.canvas,
|
||||
bb.x,
|
||||
bb.y,
|
||||
bb.w,
|
||||
bb.h,
|
||||
0,
|
||||
0,
|
||||
bb.w,
|
||||
bb.h
|
||||
);
|
||||
|
||||
uil.ctx.clearRect(bb.x, bb.y, bb.w, bb.h);
|
||||
|
||||
state.original = {
|
||||
...bb,
|
||||
sx: selection.bb.center.x,
|
||||
sy: selection.bb.center.y,
|
||||
layer: uil.layer,
|
||||
};
|
||||
state.selected = new _tool.MarqueeSelection(canvas, bb.center);
|
||||
}
|
||||
if (selection.exists && bb.w !== 0 && bb.h !== 0) select(bb);
|
||||
|
||||
selection.deselect();
|
||||
}
|
||||
|
@ -457,6 +460,40 @@ const selectTransformTool = () =>
|
|||
}
|
||||
};
|
||||
|
||||
// Register Ctrl-A Shortcut
|
||||
state.ctrlacb = () => {
|
||||
try {
|
||||
const {bb} = cropCanvas(uil.canvas);
|
||||
select(bb);
|
||||
} catch (e) {
|
||||
// Ignore errors
|
||||
}
|
||||
};
|
||||
|
||||
state.ctrlsacb = () => {
|
||||
// Shift Key selects based on all visible layer information
|
||||
const tl = {x: Infinity, y: Infinity};
|
||||
const br = {x: -Infinity, y: -Infinity};
|
||||
|
||||
uil.layers.forEach(({layer}) => {
|
||||
try {
|
||||
const {bb} = cropCanvas(layer.canvas);
|
||||
|
||||
tl.x = Math.min(bb.tl.x, tl.x);
|
||||
tl.y = Math.min(bb.tl.y, tl.y);
|
||||
|
||||
br.x = Math.max(bb.br.x, br.x);
|
||||
br.y = Math.max(bb.br.y, br.y);
|
||||
} catch (e) {
|
||||
// Ignore errors
|
||||
}
|
||||
});
|
||||
|
||||
if (Number.isFinite(br.x - tl.y)) {
|
||||
select(BoundingBox.fromStartEnd(tl, br));
|
||||
}
|
||||
};
|
||||
|
||||
// Register Ctrl-C/V Shortcut
|
||||
|
||||
// Handles copying
|
||||
|
|
Loading…
Reference in a new issue