Skip to content

Commit

Permalink
fix: clipboard copy plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Apr 9, 2024
1 parent 35dc0b0 commit e3a90ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export class BasicTool {
return Zotero.platformMajorVersion >= 102;
}

isFX115(): boolean {
return Zotero.platformMajorVersion >= 115;
}

/**
* Get DOMParser.
*
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ export class ClipboardHelper extends BasicTool {

public addText(
source: string,
type: "text/html" | "text/unicode" = "text/unicode"
type: "text/html" | "text/plain" | "text/unicode" = "text/plain"
) {
const str = Components.classes[
"@mozilla.org/supports-string;1"
].createInstance(Components.interfaces.nsISupportsString);
str.data = source;
// Compatible to text/unicode in fx115
if (this.isFX115() && type === "text/unicode") type = "text/plain";
this.transferable.addDataFlavor(type);
this.transferable.setTransferData(type, str, source.length * 2);
return this;
Expand Down

0 comments on commit e3a90ce

Please sign in to comment.