Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser agnostic search page clipboard and selection handling #965

Merged
merged 1 commit into from
May 21, 2024
Merged
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
9 changes: 4 additions & 5 deletions ext/js/display/search-display-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export class SearchDisplayController {
/** @type {boolean} */
this._clipboardMonitorEnabled = false;
/** @type {import('clipboard-monitor').ClipboardReaderLike} */
const clipboardReader = {
this.clipboardReaderLike = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does Like mean here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes it clear that this isnt an instance of the clipboardReader class and doesn't have all the function of it but has similar base function. Similar to an "arraylike" type where theres an array that might be able to do the array storage stuff but it might not be able to do push() or pop() for example.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other languages you would accomplish this by typing an interface but ig js doesn't have this pattern

getText: this._display.application.api.clipboardGet.bind(this._display.application.api)
};
/** @type {ClipboardMonitor} */
this._clipboardMonitor = new ClipboardMonitor(clipboardReader);
this._clipboardMonitor = new ClipboardMonitor(this.clipboardReaderLike);
/** @type {import('application').ApiMap} */
this._apiMap = createApiMap([
['searchDisplayControllerGetMode', this._onMessageGetMode.bind(this)],
Expand Down Expand Up @@ -268,10 +268,9 @@ export class SearchDisplayController {
}

/** */
_onCopy() {
async _onCopy() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this to async? I would've thought a function signature change would require changing the call sites of _onCopy as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_onCopy runs based off of an event listener. Event listener calls are essentially voids.

// Ignore copy from search page
const selection = window.getSelection();
this._clipboardMonitor.setPreviousText(selection !== null ? selection.toString().trim() : '');
this._clipboardMonitor.setPreviousText(document.hasFocus() ? await this.clipboardReaderLike.getText(false) : '');
}

/** @type {import('application').ApiHandler<'searchDisplayControllerUpdateSearchQuery'>} */
Expand Down