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

GH-5706: DIsposed the clipboard copy listener. #5709

Merged
merged 1 commit into from
Jul 15, 2019
Merged

GH-5706: DIsposed the clipboard copy listener. #5709

merged 1 commit into from
Jul 15, 2019

Conversation

kittaakos
Copy link
Contributor

Closes #5706.

Signed-off-by: Akos Kitta [email protected]

Related: #5708.

@kittaakos kittaakos requested a review from akosyakov July 15, 2019 07:29
disposable = addClipboardListener(document.documentElement, 'copy', e => this.handleCopy(e, downloadUrl));
} finally {
if (disposable) {
disposable.dispose();
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you explain why?

Copy link
Member

@akosyakov akosyakov Jul 15, 2019

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));
Copy link
Member

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';
Copy link
Member

Choose a reason for hiding this comment

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

/lib/

Copy link
Member

@akosyakov akosyakov left a 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.

@kittaakos
Copy link
Contributor Author

I am OK merging this, but then the static download link is gone.

@akosyakov
Copy link
Member

@kittaakos let's merge it and deal with #5707 separately?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy and Paste is Break by #5466
2 participants