Skip to content

Commit

Permalink
fix: cross-tab copy in same project
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 119fb7db89a2f51f83635197527c149680e6c4ec
  • Loading branch information
abbas-nazar authored and actions-user committed Jan 6, 2025
1 parent 30b3efc commit 31cc51b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions platform/wab/src/wab/client/clipboard/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
PasteResult,
ensureViewCtxOrThrowUserError,
} from "@/wab/client/clipboard/common";
import { ensure } from "@/wab/shared/common";
import { unwrap } from "@/wab/commons/failable-utils";
import { cloneArenaFrame } from "@/wab/shared/Arenas";
import { VariantCombo } from "@/wab/shared/Variants";
import { ArenaFrame, Component, TplNode } from "@/wab/shared/model/classes";
import { ensure } from "@/wab/shared/common";
import * as Tpls from "@/wab/shared/core/tpls";
import { ArenaFrame, Component, TplNode } from "@/wab/shared/model/classes";

export interface StyleClip {
type: "style";
Expand Down Expand Up @@ -81,8 +81,10 @@ export function cloneClip(x: Clippable): Clippable {
*/
export class LocalClipboard {
_contents: undefined | Clippable = undefined;
_timeStamp: number = Date.now();

copy(x: Clippable) {
this._timeStamp = Date.now();
this._contents = cloneClip(x);
}

Expand All @@ -109,6 +111,10 @@ export class LocalClipboard {
contents() {
return this._contents;
}

timeStamp() {
return this._timeStamp;
}
}

export type LocalClipboardAction = "cut" | "copy";
Expand Down
8 changes: 8 additions & 0 deletions platform/wab/src/wab/client/clipboard/paste.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ function shouldPerformCrossTabCopy(
if (copyState.bundleRef.type === "pkg") {
return true;
}
// We are dealing with the same project and branch, but different tab
// perform a cross-tab copy, if local clipboard is empty or the cross-tab clipboard is more recent.
if (
sc.clipboard.isEmpty() ||
sc.clipboard.timeStamp() < copyState.timeStamp
) {
return true;
}
// It may be the case that we are dealing with a different revisionNum here
// but we will assume it's fine, considering the expected time for user to copy/paste
return false;
Expand Down
5 changes: 4 additions & 1 deletion platform/wab/src/wab/client/components/canvas/view-ops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,10 @@ export class ViewOps {
);
console.log("Copied styles", props);
// TODO: also copy mixins
this.clipboard().copy({ type: "style", cssProps: props });
this.clipboard().copy({
type: "style",
cssProps: props,
});
}

tryPasteStyleFromClipboard(targetTpl?: TplNode, cssProps?: string[]) {
Expand Down
1 change: 1 addition & 0 deletions platform/wab/src/wab/client/insertable-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ export function getCopyState(
componentUuid: currentComponent.uuid,
componentName: currentComponent.name,
references,
timeStamp: viewCtx.clipboard.timeStamp(),
};

return state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ export function mkInsertableComponentImporter(
(c.templateInfo?.name &&
c.templateInfo?.name === comp.templateInfo?.name) ||
(c.templateInfo?.componentId === comp.uuid &&
c.templateInfo?.projectId === info.projectId)
c.templateInfo?.projectId === info.projectId) ||
c.uuid === comp.uuid
);
if (existing) {
oldToNewComponent.set(comp, existing);
Expand Down
1 change: 1 addition & 0 deletions platform/wab/src/wab/shared/insertable-templates/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface CopyState {
branchId?: string;
bundleRef: CopyStateBundleRef;
references: CopyElementsReference[];
timeStamp: number;
}

export interface CopyStateExtraInfo
Expand Down

0 comments on commit 31cc51b

Please sign in to comment.