-
Notifications
You must be signed in to change notification settings - Fork 100
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,11 +66,11 @@ export class SearchDisplayController { | |
/** @type {boolean} */ | ||
this._clipboardMonitorEnabled = false; | ||
/** @type {import('clipboard-monitor').ClipboardReaderLike} */ | ||
const clipboardReader = { | ||
this.clipboardReaderLike = { | ||
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)], | ||
|
@@ -268,10 +268,9 @@ export class SearchDisplayController { | |
} | ||
|
||
/** */ | ||
_onCopy() { | ||
async _onCopy() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'>} */ | ||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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()
orpop()
for example.There was a problem hiding this comment.
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