mirror of
https://github.com/zadam/trilium.git
synced 2025-11-12 08:15:52 +01:00
feat(client): display message when copying code block in text note
This commit is contained in:
@@ -28,4 +28,17 @@ declare module "ckeditor5" {
|
||||
getSelectedHtml(): string;
|
||||
removeSelection(): Promise<void>;
|
||||
}
|
||||
|
||||
interface EditorConfig {
|
||||
syntaxHighlighting: {
|
||||
loadHighlightJs: () => Promise<any>;
|
||||
mapLanguageName(mimeType: string): string;
|
||||
defaultMimeType: string;
|
||||
enabled: boolean;
|
||||
},
|
||||
|
||||
clipboard?: {
|
||||
copy(text: string): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,17 @@ export default class CopyToClipboardButton extends Plugin {
|
||||
|
||||
export class CopyToClipboardCommand extends Command {
|
||||
|
||||
private executeCallback?: (text: string) => void;
|
||||
|
||||
execute(...args: Array<unknown>) {
|
||||
const editor = this.editor;
|
||||
const model = editor.model;
|
||||
const selection = model.document.selection;
|
||||
|
||||
if (!this.executeCallback) {
|
||||
this.executeCallback = this.editor.config.get("clipboard")?.copy;
|
||||
}
|
||||
|
||||
const codeBlockEl = selection.getFirstPosition()?.findAncestor("codeBlock");
|
||||
if (!codeBlockEl) {
|
||||
console.warn("Unable to find code block element to copy from.");
|
||||
@@ -43,11 +49,15 @@ export class CopyToClipboardCommand extends Command {
|
||||
.join("");
|
||||
|
||||
if (codeText) {
|
||||
navigator.clipboard.writeText(codeText).then(() => {
|
||||
console.log('Code block copied to clipboard');
|
||||
}).catch(err => {
|
||||
console.error('Failed to copy code block', err);
|
||||
});
|
||||
if (!this.executeCallback) {
|
||||
navigator.clipboard.writeText(codeText).then(() => {
|
||||
console.log('Code block copied to clipboard');
|
||||
}).catch(err => {
|
||||
console.error('Failed to copy code block', err);
|
||||
});
|
||||
} else {
|
||||
this.executeCallback(codeText);
|
||||
}
|
||||
} else {
|
||||
console.warn('No code block selected or found.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user