Skip to content

Commit

Permalink
innerClipboard_: on get, detect another name with/without "!"
Browse files Browse the repository at this point in the history
  • Loading branch information
gdh1995 committed Feb 14, 2024
1 parent c741d02 commit ac7606f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 10 additions & 4 deletions background/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CurCVer_, CurFFVer_, OnChrome, OnEdge, OnFirefox, copy_, paste_, substitute_, set_copy_, set_paste_, set_substitute_,
settingsCache_, updateHooks_, searchEngines_, blank_, runOnTee_, innerClipboard_, framesForTab_, curTabId_
settingsCache_, updateHooks_, searchEngines_, blank_, runOnTee_, innerClipboard_, framesForTab_, curTabId_,
readInnerClipboard_, set_readInnerClipboard_
} from "./store"
import * as BgUtils_ from "./utils"
import * as Exclusions from "./exclusions"
Expand Down Expand Up @@ -285,7 +286,7 @@ export const replaceUsingClipboard = (text: string, item: ClipSubItem, lastClean
return "$" + key
}
const cmd = s1.replace(<RegExpOne> /^<|>$/, ""), opArr = (<RegExpOne> /\|\|=|[+\-*\/\|]=?|=/).exec(cmd)
let name = opArr ? cmd.slice(0, opArr.index) : cmd, value = innerClipboard_.get(name) || ""
let name = opArr ? cmd.slice(0, opArr.index) : cmd, value = readInnerClipboard_(name)
if (opArr && (value || "||=".includes(opArr[0]))) {
let op = opArr[0], alg = op[0], x = +cmd.slice(name.length + op.length) || 0, y = +value
if (!isNaN(y || x)) {
Expand Down Expand Up @@ -385,7 +386,7 @@ set_substitute_(((input: string, normalContext: SedContext, mixedSed?: MixedSedO
if (typeof action === "string") {
const actionName = action.split("=")[0], actionVal = action.slice(actionName.length + 1)
if (actionName === "copy") { writeInnerClipboard_(actionVal, text) }
else if (actionName === "paste") { text = innerClipboard_.get(actionVal) || "" }
else if (actionName === "paste") { text = readInnerClipboard_(actionVal) }
else if (actionName === "keyword" && exOut) { exOut.keyword_ = actionVal }
else if (actionName === "act" && exOut) { exOut.actAnyway_ = actionVal !== "false" }
else if ((actionName === "sys-clip" || actionName === "sysclip") && exOut) {
Expand Down Expand Up @@ -451,6 +452,11 @@ const writeInnerClipboard_ = (name: string, text: string): void => {
}, Build.NDEBUG ? 20_000 : 45_000)
}

set_readInnerClipboard_(((name: string): string => {
const val = innerClipboard_.get(name)
return (val ?? innerClipboard_.get(name.endsWith("!") ? name.slice(0, -1) : name + "!")) || ""
}) satisfies typeof readInnerClipboard_)

const getTextArea_html = (): HTMLTextAreaElement => {
const el = (globalThis as MaybeWithWindow).document!.createElement("textarea")
el.style.position = "absolute"
Expand Down Expand Up @@ -540,7 +546,7 @@ set_copy_(((data, join, sed, keyword): string | Promise<string> => {
set_paste_(((sed, newLenLimit?: number, exOut?: InfoOnSed): string | Promise<string | null> => {
const clip = detectClipSed(sed, "<")
if (clip) {
return reformat_(innerClipboard_.get(clip) || "", null, exOut)
return reformat_(readInnerClipboard_(clip), null, exOut)
}
if (Build.MV3 || OnFirefox && (navClipboard || (navClipboard = navigator.clipboard))) {
return (Build.MV3 ? runOnTee_(kTeeTask.Paste, null, null)
Expand Down
2 changes: 2 additions & 0 deletions background/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export let paste_: (sed?: MixedSedOpts | null, len?: number, exOut?: InfoOnSed
) => string | Promise<string | null> | null = () => ""
export let substitute_: (text: string, context: SedContext, sed?: MixedSedOpts | null, exOut?: InfoOnSed) => string
= s => s
export let readInnerClipboard_: (name: string) => string = () => ""
export let evalVimiumUrl_: Urls.Executor = () => null
export let updateToLocal_: ((wait: number) => void) | true | null = null
export let shownHash_: ((this: void) => string) | null = null
Expand All @@ -237,6 +238,7 @@ export const set_restoreSettings_ = (_newRestore: typeof restoreSettings_): void
export const set_copy_ = (_newCopy: typeof copy_): void => { copy_ = _newCopy }
export const set_paste_ = (_newPaste: typeof paste_): void => { paste_ = _newPaste }
export const set_substitute_ = (_newSed: typeof substitute_): void => { substitute_ = _newSed }
export const set_readInnerClipboard_ = (_newRIC: typeof readInnerClipboard_): void => { readInnerClipboard_ = _newRIC }
export const set_evalVimiumUrl_ = (_newEval: typeof evalVimiumUrl_): void => { evalVimiumUrl_ = _newEval }
export const set_shownHash_ = (_newHash: typeof shownHash_): void => { shownHash_ = _newHash }
export const set_updateToLocal_ = (_newBackup: typeof updateToLocal_): void => { updateToLocal_ = _newBackup }
Expand Down

0 comments on commit ac7606f

Please sign in to comment.