Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update - 'duplicate' functionality #29

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ function createKeyboardCommands(nodeGraph: NodeGraphEditor) {
keybinding: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z
};

const duplicate: KeyboardCommand = {
handler: () => nodeGraph.duplicate(),
keybinding: KeyMod.CtrlCmd | KeyCode.KEY_D
};

const navBack: KeyboardCommand = {
handler: () => nodeGraph.navigationHistory.goBack(),
keybinding: KeyMod.CtrlCmd | KeyCode.US_OPEN_SQUARE_BRACKET
Expand Down Expand Up @@ -553,7 +558,7 @@ function createKeyboardCommands(nodeGraph: NodeGraphEditor) {
keybinding: KeyMod.CtrlCmd | KeyCode.US_SLASH
};

return [copy, paste, cut, undo, redo, navBack, navForward, deleteWithBackspace, deleteWithDel, createComment];
return [copy, paste, cut, undo, redo, duplicate, navBack, navForward, deleteWithBackspace, deleteWithDel, createComment];
}

export class EditorDocumentProvider implements IDocumentProvider {
Expand Down
24 changes: 21 additions & 3 deletions packages/noodl-editor/src/editor/src/views/nodegrapheditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,7 @@ export class NodeGraphEditor extends View {
} else {
this.clipboard = undefined;
}

ToastLayer.showInteraction('Copied');


return nodeset;
}

Expand Down Expand Up @@ -930,6 +928,7 @@ export class NodeGraphEditor extends View {

copy() {
this.copySelected();
ToastLayer.showInteraction('Copied');
}

cut() {
Expand Down Expand Up @@ -1095,6 +1094,25 @@ export class NodeGraphEditor extends View {
}
}

duplicate() {
if (this.readOnly) {
return false;
}

const nodeset = this.copySelected();
if (nodeset === undefined) return;

const ns = this.getNodeSetFromClipboard() || this.clipboard;
if (!ns) return;

this.insertNodeSet({
nodeset: ns,
x: this.latestMousePos.x,
y: this.latestMousePos.y,
toastMessage: 'Duplicated'
});
}

getDevicePixelRatio(ctx) {
const dpr = window.devicePixelRatio || 1;
const bsr =
Expand Down