summaryrefslogtreecommitdiff
path: root/ext/js/comm/clipboard-monitor.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/comm/clipboard-monitor.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/comm/clipboard-monitor.js')
-rw-r--r--ext/js/comm/clipboard-monitor.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/ext/js/comm/clipboard-monitor.js b/ext/js/comm/clipboard-monitor.js
index c5046046..3b3a56a9 100644
--- a/ext/js/comm/clipboard-monitor.js
+++ b/ext/js/comm/clipboard-monitor.js
@@ -18,17 +18,32 @@
import {EventDispatcher} from '../core.js';
+/**
+ * @augments EventDispatcher<import('clipboard-monitor').EventType>
+ */
export class ClipboardMonitor extends EventDispatcher {
+ /**
+ * @param {{japaneseUtil: import('../language/sandbox/japanese-util.js').JapaneseUtil, clipboardReader: import('clipboard-monitor').ClipboardReaderLike}} details
+ */
constructor({japaneseUtil, clipboardReader}) {
super();
+ /** @type {import('../language/sandbox/japanese-util.js').JapaneseUtil} */
this._japaneseUtil = japaneseUtil;
+ /** @type {import('clipboard-monitor').ClipboardReaderLike} */
this._clipboardReader = clipboardReader;
+ /** @type {?import('core').Timeout} */
this._timerId = null;
+ /** @type {?import('core').TokenObject} */
this._timerToken = null;
+ /** @type {number} */
this._interval = 250;
+ /** @type {?string} */
this._previousText = null;
}
+ /**
+ * @returns {void}
+ */
start() {
this.stop();
@@ -36,6 +51,7 @@ export class ClipboardMonitor extends EventDispatcher {
// hasn't been started during the await call. The check below the await call
// will exit early if the reference has changed.
let canChange = false;
+ /** @type {?import('core').TokenObject} */
const token = {};
const intervalCallback = async () => {
this._timerId = null;
@@ -55,7 +71,7 @@ export class ClipboardMonitor extends EventDispatcher {
) {
this._previousText = text;
if (canChange && this._japaneseUtil.isStringPartiallyJapanese(text)) {
- this.trigger('change', {text});
+ this.trigger('change', /** @type {import('clipboard-monitor').ChangeEvent} */ ({text}));
}
}
@@ -68,6 +84,9 @@ export class ClipboardMonitor extends EventDispatcher {
intervalCallback();
}
+ /**
+ * @returns {void}
+ */
stop() {
this._timerToken = null;
this._previousText = null;
@@ -77,6 +96,9 @@ export class ClipboardMonitor extends EventDispatcher {
}
}
+ /**
+ * @param {?string} text
+ */
setPreviousText(text) {
this._previousText = text;
}