Skip to content

Commit

Permalink
handle refresh and clipboard for paste
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchit-agarwal committed Apr 10, 2024
1 parent e1478f7 commit d046879
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions packages/core/src/events/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { expandRowsAndColumns, storeSheetParamALL } from "../modules/sheet";
import { jfrefreshgrid } from "../modules/refresh";
import { setRowHeight } from "../api";
import { CFSplitRange } from "../modules";
import clipboard from "../modules/clipboard";

function postPasteCut(
ctx: Context,
Expand Down Expand Up @@ -390,6 +391,7 @@ function pasteHandler(ctx: Context, data: any, borderInfo?: any) {
// jfrefreshgrid(d, ctx.luckysheet_select_save, allParam);
// selectHightlightShow();
}
jfrefreshgrid(ctx, null, undefined);
} else {
data = data.replace(/\r/g, "");
const dataChe = [];
Expand Down Expand Up @@ -496,6 +498,7 @@ function pasteHandler(ctx: Context, data: any, borderInfo?: any) {
// jfrefreshgrid(d, ctx.luckysheet_select_save);
// selectHightlightShow();
// }
jfrefreshgrid(ctx, null, undefined);
}
}

Expand Down Expand Up @@ -1953,7 +1956,6 @@ export function handlePaste(ctx: Context, e: ClipboardEvent) {
});
r += 1;
});

ctx.luckysheet_selection_range = [];
pasteHandler(ctx, data, borderInfo);
// $("#fortune-copy-content").empty();
Expand Down Expand Up @@ -1987,17 +1989,23 @@ export function handlePaste(ctx: Context, e: ClipboardEvent) {
}
}

export function handlePasteByClick(ctx: Context, triggerType?: string) {
export function handlePasteByClick(
ctx: Context,
clipboardData: string,
triggerType?: string
) {
const allowEdit = isAllowEdit(ctx);
if (!allowEdit) return;

if (clipboardData) clipboard.writeHtml(clipboardData);

const textarea = document.querySelector("#fortune-copy-content");
// textarea.focus();
// textarea.select();

// 等50毫秒,keyPress事件发生了再去处理数据
// setTimeout(function () {
const data = textarea?.innerHTML;
const data = textarea?.innerHTML || textarea?.textContent;
if (!data) return;

if (
Expand All @@ -2015,7 +2023,7 @@ export function handlePasteByClick(ctx: Context, triggerType?: string) {
} else if (data.indexOf("fortune-copy-action-image") > -1) {
// imageCtrl.pasteImgItem();
} else if (triggerType !== "btn") {
// pasteHandler(data);
pasteHandler(ctx, data);
} else {
// if (isEditMode()) {
// alert(local_drag.pasteMustKeybordAlert);
Expand Down
5 changes: 3 additions & 2 deletions packages/react/src/components/ContextMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ const ContextMenu: React.FC = () => {
return (
<Menu
key={name}
onClick={() => {
onClick={async () => {
const clipboardText = await navigator.clipboard.readText();
setContext((draftCtx) => {
handlePasteByClick(draftCtx);
handlePasteByClick(draftCtx, clipboardText);
draftCtx.contextMenu = {};
});
}}
Expand Down

0 comments on commit d046879

Please sign in to comment.