Skip to content
Merged
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 @@ -12,8 +12,7 @@ import { SelectionToolbar } from "./SelectionToolbar";
export const FloatingSelectionToolbar = observer(
function FloatingSelectionToolbar({ spec }: { spec: ComponentSpec | null }) {
const { editor } = useSharedStores();
const { duplicateSelectedNodes, copySelectedNodes, pasteNodes } =
useTaskActions();
const { duplicateSelectedNodes, copySelectedNodes } = useTaskActions();
const { createSubgraph } = usePipelineActions();
const { multiSelection } = editor;
const reactFlow = useReactFlow();
Expand All @@ -32,14 +31,6 @@ export const FloatingSelectionToolbar = observer(
copySelectedNodes(spec, multiSelection);
};

const handlePaste = () => {
if (!spec) return;
const viewport = reactFlow.getViewport();
const centerX = (window.innerWidth / 2 - viewport.x) / viewport.zoom;
const centerY = (window.innerHeight / 2 - viewport.y) / viewport.zoom;
void pasteNodes(spec, { x: centerX, y: centerY });
};

const handleDelete = () => {
if (!spec || !reactFlow.viewportInitialized) return;
const selectedEdges = getSelectedEdgesFromInstance(reactFlow);
Expand Down Expand Up @@ -74,7 +65,6 @@ export const FloatingSelectionToolbar = observer(
<SelectionToolbar
onDuplicate={handleDuplicate}
onCopy={handleCopy}
onPaste={handlePaste}
onDelete={handleDelete}
onCreateSubgraph={handleCreateSubgraph}
selectedTaskCount={selectedTasks.length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ import { Separator } from "@/components/ui/separator";
import { Text } from "@/components/ui/typography";
import { cn } from "@/lib/utils";
import { CreateSubgraphForm } from "@/routes/v2/pages/Editor/components/CreateSubgraphForm";
import { useEditorSession } from "@/routes/v2/pages/Editor/store/EditorSessionContext";
import { tracking } from "@/utils/tracking";

interface SelectionToolbarProps {
onDuplicate: () => void;
onCopy: () => void;
onPaste?: () => void;
onDelete: () => void;
onCreateSubgraph?: (name: string) => void;
selectedTaskCount?: number;
Expand All @@ -29,12 +27,10 @@ interface SelectionToolbarProps {
export const SelectionToolbar = observer(function SelectionToolbar({
onDuplicate,
onCopy,
onPaste,
onDelete,
onCreateSubgraph,
selectedTaskCount = 0,
}: SelectionToolbarProps) {
const { clipboard } = useEditorSession();
const [popoverOpen, setPopoverOpen] = useState(false);

const handleCreate = (name: string) => {
Expand Down Expand Up @@ -63,15 +59,6 @@ export const SelectionToolbar = observer(function SelectionToolbar({
testId="selection-copy"
trackingAction="v2.pipeline_canvas.selection_toolbar.copy"
/>
{clipboard.hasContent && onPaste && (
<ToolbarButton
label="Paste"
icon="ClipboardPaste"
onClick={onPaste}
testId="selection-paste"
trackingAction="v2.pipeline_canvas.selection_toolbar.paste"
/>
)}
{onCreateSubgraph && selectedTaskCount >= 2 && (
<>
<Separator orientation="vertical" className="mx-0.5 self-stretch" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export function useClipboardShortcuts(
keys: [CMDALT, "C"],
label: "Copy",
action: (e) => {
const textSelection = window.getSelection();
if (
textSelection &&
!textSelection.isCollapsed &&
textSelection.toString().length > 0
) {
return false;
}
e.preventDefault();
if (!spec) return;
const selection = getEffectiveSelection(registry, spec, editor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ export const TaskDetails = observer(function TaskDetails({
/>
) : (
<div className="group min-w-0 flex items-baseline gap-1">
<Text size="md" weight="semibold" className="wrap-anywhere">
<Text
size="md"
weight="semibold"
className="wrap-anywhere select-text"
>
{task.name}
</Text>
<Button
Expand Down
22 changes: 20 additions & 2 deletions src/routes/v2/pages/Editor/store/clipboardStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { XYPosition } from "@xyflow/react";
import { action, computed, makeObservable, observable } from "mobx";
import {
action,
computed,
makeObservable,
observable,
runInAction,
} from "mobx";

import type { ComponentSpec } from "@/models/componentSpec";
import { IncrementingIdGenerator } from "@/models/componentSpec/factories/idGenerator";
Expand All @@ -26,6 +32,7 @@ const idGen = new IncrementingIdGenerator();
export class ClipboardStore {
@observable.shallow accessor snapshots: NodeSnapshot[] = [];
@observable.shallow accessor bindingSnapshots: BindingSnapshot[] = [];
@observable accessor pasteOffsetIndex: number = 0;

constructor(private undoStore: UndoGroupable) {
makeObservable(this);
Expand All @@ -50,6 +57,7 @@ export class ClipboardStore {

this.snapshots = snapshots;
this.bindingSnapshots = bindings;
this.pasteOffsetIndex = 0;

writeToSystemClipboard(snapshots, bindings);
}
Expand All @@ -64,11 +72,20 @@ export class ClipboardStore {

if (snapshots.length === 0) return [];

const offset = this.pasteOffsetIndex * PASTE_OFFSET;
const offsetCenter = {
x: centerPosition.x + offset,
y: centerPosition.y + offset,
};
runInAction(() => {
this.pasteOffsetIndex += 1;
});

return this.cloneSnapshotsAtPosition(
spec,
snapshots,
bindings,
centerPosition,
offsetCenter,
);
}

Expand Down Expand Up @@ -104,6 +121,7 @@ export class ClipboardStore {
@action clear() {
this.snapshots = [];
this.bindingSnapshots = [];
this.pasteOffsetIndex = 0;
}

private cloneSnapshotsAtPosition(
Expand Down
Loading