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

fix: fallback on readText permisisons #3444

Merged
merged 1 commit into from
Jan 15, 2025
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
27 changes: 17 additions & 10 deletions frontend/src/components/editor/cell/cell-context-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { CellOutputId } from "@/core/cells/ids";
import { Logger } from "@/utils/Logger";
import { copyToClipboard } from "@/utils/copy";
import { toast } from "@/components/ui/use-toast";
import { sendToPanelManager } from "@/core/vscode/vscode-bindings";

interface Props extends CellActionButtonProps {
children: React.ReactNode;
Expand Down Expand Up @@ -81,16 +82,22 @@ export const CellActionsContextMenu = ({ children, ...props }: Props) => {
}
// We can't use the native browser paste since we don't have focus
// so instead we use the editorViewView
const clipText = await navigator.clipboard.readText();
if (clipText) {
// Get the current selection, or the start of the document if nothing is selected
const { from, to } = editorView.state.selection.main;
// Create a new transaction that replaces the selection with the clipboard text
const tr = editorView.state.update({
changes: { from, to, insert: clipText },
});
// Apply the transaction
editorView.dispatch(tr);
try {
const clipText = await navigator.clipboard.readText();
if (clipText) {
// Get the current selection, or the start of the document if nothing is selected
const { from, to } = editorView.state.selection.main;
// Create a new transaction that replaces the selection with the clipboard text
const tr = editorView.state.update({
changes: { from, to, insert: clipText },
});
// Apply the transaction
editorView.dispatch(tr);
}
} catch (error) {
Logger.error("Failed to paste from clipboard", error);
// Try vscode or other parent
sendToPanelManager({ command: "paste" });
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/core/vscode/vscode-bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function registerContextMenu() {
});
}

function sendToPanelManager(msg: VscodeMessage) {
export function sendToPanelManager(msg: VscodeMessage) {
window.parent?.postMessage(msg, "*");
}

Expand Down
Loading