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
18 changes: 18 additions & 0 deletions src/_util/copyToClipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function copy(text: string) {
let success: boolean;
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
try {
document.execCommand('copy');
success = true;
} catch (e) {
console.error('fallback 复制失败', e);
success = false;
}
document.body.removeChild(textarea);
return success;
}
23 changes: 15 additions & 8 deletions src/chat-action/action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../../src/tooltip';
import { Component, signal, tag } from 'omi';

import { getClassPrefix } from '../_util/classname';
import { copy as fallbackCopy } from '../_util/copyToClipboard';
import { setExportparts } from '../_util/dom';
import { type ChatComment } from '../chat-engine';
import { MessagePlugin } from '../message';
Expand All @@ -30,14 +31,20 @@ export const renderActions = (
const clickCopyHandler = () => {
const text = copyText.toString();
if (!text) return;
navigator.clipboard
.writeText(copyText.toString())
.then(() => {
MessagePlugin.success('复制成功');
})
.catch(() => {
MessagePlugin.success('复制失败,请手动复制');
});
if (navigator.clipboard) {
navigator.clipboard
.writeText(copyText.toString())
.then(() => {
MessagePlugin.success('复制成功');
})
.catch(() => {
MessagePlugin.success('复制失败,请手动复制');
});
} else {
const success = fallbackCopy(text);
if (success) MessagePlugin.success('复制成功');
else MessagePlugin.error('复制失败,请手动复制');
}
};

const handleClickAction = (action: TdChatActionsName, data: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/collapse/collapse-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default class CollapsePanel extends Component<TdCollapsePanelProps> {
}

renderBody() {
const isActive = this.injection.getCollapseValue().includes(this.innerValue.value);
const isActive = this.injection.getCollapseValue?.().includes(this.innerValue.value);
const { destroyOnCollapse } = this.props;
if (this.afterLeaved.value === null && !isActive) {
return null;
Expand Down