Skip to content

Commit

Permalink
chore:
Browse files Browse the repository at this point in the history
  • Loading branch information
army8735 committed Jan 14, 2025
1 parent 1e55799 commit 2893b5d
Showing 1 changed file with 74 additions and 36 deletions.
110 changes: 74 additions & 36 deletions src/control/Listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1651,47 +1651,85 @@ export default class Listener extends Event {
this.emit(Listener.SELECT_NODE, this.selected.slice(0));
}
}
// 移动
// 移动,普通的节点移动和矢量顶点侦听,文字光标是特殊的聚焦input框侦听
else if (keyCode >= 37 && keyCode <= 40 || ['ArrowUp', 'ArrowRight', 'ArrowDown', 'ArrowLeft'].includes(code)) {
const target = e.target as HTMLElement;
if (target && !['INPUT', 'SELECT', 'TEXTAREA'].includes(target.tagName.toUpperCase())) {
e.preventDefault();
const nodes = this.selected.slice(0);
const data: MoveData[] = [];
const changeAb: Node[] = [];
nodes.forEach((node) => {
const originStyle = node.getStyle();
const oldAb = node.artBoard;
let ab;
let x = 0;
let y = 0;
if (keyCode === 37) {
x = this.shiftKey ? -10 : -1;
}
else if (keyCode === 38) {
y = this.shiftKey ? -10 : -1;
}
else if (keyCode === 39) {
x = this.shiftKey ? 10 : 1;
}
else if (keyCode === 40) {
y = this.shiftKey ? 10 : 1;
}
ab = MoveCommand.update(node, node.computedStyle, x, y);
if (oldAb !== ab) {
changeAb.push(node);
}
node.endPosChange(originStyle, x, y);
data.push({ dx: x, dy: y });
node.checkPosSizeUpward();
});
if (changeAb.length) {
this.emit(Listener.ART_BOARD_NODE, changeAb);
let x = 0;
let y = 0;
if (keyCode === 37) {
if (this.shiftKey) {
x = -10;
}
else if (this.altKey) {
x = -0.1;
}
else {
x = -1;
}
}
else if (keyCode === 38) {
if (this.shiftKey) {
y = -10;
}
else if (this.altKey) {
y = -0.1;
}
else {
y = -1;
}
}
if (nodes.length) {
this.select.updateSelect(nodes);
this.emit(Listener.MOVE_NODE, nodes.slice(0));
this.history.addCommand(new MoveCommand(nodes, data));
else if (keyCode === 39) {
if (this.shiftKey) {
x = 10;
}
else if (this.altKey) {
x = 0.1;
}
else {
x = 1;
}
}
else if (keyCode === 40) {
if (this.shiftKey) {
y = 10;
}
else if (this.altKey) {
y = 0.1;
}
else {
y = 1;
}
}
if (this.state === State.EDIT_GEOM) {
const node = this.selected[0];
if (node instanceof Polyline && this.geometry.idx.length) {}
}
else {
const nodes = this.selected.slice(0);
const data: MoveData[] = [];
const changeAb: Node[] = [];
nodes.forEach((node) => {
const originStyle = node.getStyle();
const oldAb = node.artBoard;
let ab;
ab = MoveCommand.update(node, node.computedStyle, x, y);
if (oldAb !== ab) {
changeAb.push(node);
}
node.endPosChange(originStyle, x, y);
data.push({ dx: x, dy: y });
node.checkPosSizeUpward();
});
if (changeAb.length) {
this.emit(Listener.ART_BOARD_NODE, changeAb);
}
if (nodes.length) {
this.select.updateSelect(nodes);
this.emit(Listener.MOVE_NODE, nodes.slice(0));
this.history.addCommand(new MoveCommand(nodes, data));
}
}
}
}
Expand Down

0 comments on commit 2893b5d

Please sign in to comment.