Improve history states (#932)

* Add some more history states

* Fix undo whilst drawing

* Paste image history

* Toggle output and preview history

* Code review nits

* Remove extra '{'

* Fix typo

* Fix about.toml

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube 2023-01-01 22:02:44 +00:00 committed by Keavon Chambers
parent 6e142627a3
commit 2bcc3d3baf
16 changed files with 282 additions and 190 deletions

View file

@ -593,11 +593,17 @@ export default defineComponent({
// Clicked on a node
if (nodeId) {
let modifiedSelected = false;
const id = BigInt(nodeId);
if (e.shiftKey || e.ctrlKey) {
modifiedSelected = true;
if (this.selected.includes(id)) this.selected.splice(this.selected.lastIndexOf(id), 1);
else this.selected.push(id);
} else if (!this.selected.includes(id)) {
modifiedSelected = true;
this.selected = [id];
} else {
this.selectIfNotDragged = id;
@ -607,15 +613,17 @@ export default defineComponent({
this.draggingNodes = { startX: e.x, startY: e.y, roundX: 0, roundY: 0 };
}
this.editor.instance.selectNodes(new BigUint64Array(this.selected));
if (modifiedSelected) this.editor.instance.selectNodes(new BigUint64Array(this.selected));
return;
}
// Clicked on the graph background
this.panning = true;
this.selected = [];
this.editor.instance.selectNodes(new BigUint64Array(this.selected));
if (this.selected.length !== 0) {
this.selected = [];
this.editor.instance.selectNodes(new BigUint64Array(this.selected));
}
},
doubleClick(e: MouseEvent) {
const node = (e.target as HTMLElement).closest("[data-node]") as HTMLElement | undefined;
@ -677,12 +685,14 @@ export default defineComponent({
}
} else if (this.draggingNodes) {
if (this.draggingNodes.startX === e.x || this.draggingNodes.startY === e.y) {
if (this.selectIfNotDragged !== undefined) {
if (this.selectIfNotDragged !== undefined && (this.selected.length !== 1 || this.selected[0] !== this.selectIfNotDragged)) {
this.selected = [this.selectIfNotDragged];
this.editor.instance.selectNodes(new BigUint64Array(this.selected));
}
}
this.editor.instance.moveSelectedNodes(this.draggingNodes.roundX, this.draggingNodes.roundY);
if (this.selected.length > 0 && this.draggingNodes.roundX !== 0 && this.draggingNodes.roundY !== 0)
this.editor.instance.moveSelectedNodes(this.draggingNodes.roundX, this.draggingNodes.roundY);
// Check if this node should be inserted between two other nodes
if (this.selected.length === 1) {

View file

@ -644,6 +644,9 @@ impl JsEditorHandle {
/// Notifies the backend that the selected nodes have been moved
#[wasm_bindgen(js_name = moveSelectedNodes)]
pub fn move_selected_nodes(&self, displacement_x: i32, displacement_y: i32) {
let message = DocumentMessage::StartTransaction;
self.dispatch(message);
let message = NodeGraphMessage::MoveSelectedNodes { displacement_x, displacement_y };
self.dispatch(message);
}