-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
GH-5706: DIsposed the clipboard copy listener. #5709
Conversation
disposable = addClipboardListener(document.documentElement, 'copy', e => this.handleCopy(e, downloadUrl)); | ||
} finally { | ||
if (disposable) { | ||
disposable.dispose(); |
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.
it should be disposed within event handler before calling this.handleCopy
.
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.
Can you explain why?
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.
because we want to wait till copy
event is fired and remove a listener only after it? I don't understand how current change ensures it, i.e. it removes a listener before calling copy
.
We use the same pattern in other places as well: https://github.com/theia-ide/theia/blob/60dcb3326ea5e70c8d1017dcd206013304a5c92e/packages/markers/src/browser/problem/problem-contribution.ts#L158-L168
if (document.documentElement) { | ||
addClipboardListener(document.documentElement, 'copy', e => this.handleCopy(e, downloadUrl)); | ||
try { | ||
disposable = addClipboardListener(document.documentElement, 'copy', e => this.handleCopy(e, downloadUrl)); |
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.
const toDispose = addClipboardListener(document.documentElement, 'copy', e => {
toDispose.dispose();
this.handleCopy(e, downloadUrl);
});
@@ -22,6 +22,7 @@ import { FileSystem } from '../../common/filesystem'; | |||
import { FileDownloadData } from '../../common/download/file-download-data'; | |||
import { MessageService } from '@theia/core/lib/common/message-service'; | |||
import { addClipboardListener } from '@theia/core/lib/browser/widgets'; | |||
import { Disposable } from '@theia/core/src/common/disposable'; |
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.
/lib/
Closes #5706. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
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.
thank you! I've tested that copy download link does no steal copy handlers anymore.
I am OK merging this, but then the static download link is gone. |
@kittaakos let's merge it and deal with #5707 separately? |
Closes #5706.
Signed-off-by: Akos Kitta kittaakos@typefox.io
Related: #5708.