Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

[Linux][1.19.0-beta1] Closing tab with middle mouse pastes in next tab #461

Closed
1 task done
hultberg opened this issue Jun 22, 2017 · 6 comments · Fixed by atom/atom#15183
Closed
1 task done

[Linux][1.19.0-beta1] Closing tab with middle mouse pastes in next tab #461

hultberg opened this issue Jun 22, 2017 · 6 comments · Fixed by atom/atom#15183

Comments

@hultberg
Copy link

Prerequisites

Description

Same as #52, but this time I'm unable to reproduce this on 1.18, but able on 1.19.

Steps to Reproduce

  1. Open two files in the editor
  2. Close one tab with middle mouse button
  3. Observe that you have just pasted in what-ever was in your clipboard in the next file.

Make sure you have something in the clipboard.

Expected behavior: The tab should just be closed.

Actual behavior: Tab closes and content from my clipboard is pasted.

Reproduces how often: Always

Versions

1.18:

~ ᐅ atom --version
Atom    : 1.18.0
Electron: 1.4.16
Chrome  : 53.0.2785.143
Node    : 6.5.0

1.19:

~ ᐅ atom-beta --version
Atom    : 1.19.0-beta1
Electron: 1.6.9
Chrome  : 56.0.2924.87
Node    : 7.4.0

Additional Information

Related to #52

@hultberg hultberg changed the title [Linux][1.19.0-beta0] Closing tab with middle mouse pastes in next tab [Linux][1.19.0-beta1] Closing tab with middle mouse pastes in next tab Jun 22, 2017
@50Wliu 50Wliu added the bug label Jun 23, 2017
@50Wliu 50Wliu marked this as a duplicate of atom/atom#15039 Jul 17, 2017
@50Wliu
Copy link
Contributor

50Wliu commented Jul 17, 2017

Most likely caused by the Electron upgrade; specifically the underlying changes to how Chrome handles middle-button-paste on Linux.

@ungb
Copy link

ungb commented Aug 3, 2017

I'm able to repro this issue with the repro steps provided.

@ungb
Copy link

ungb commented Aug 3, 2017

This looks related to electron upgrade as it also caused regression with double pasting on middle clicking(atom/atom#8648) that was fixed with atom/atom#14987.

@50Wliu 50Wliu added the triaged label Aug 3, 2017
@t-bltg
Copy link

t-bltg commented Aug 4, 2017

Is there a hotfix for this ? I keep pasting everywhere on closing tabs ...

@t-bltg
Copy link

t-bltg commented Aug 4, 2017

I've been playing around in dev mode atom -d, and it seems that removing event.preventDefault()) and returning false in TabBarView.prototype.onMouseDown in atom-beta/resources/app/node_modules/tabs/lib/tab-bar-view.js prevents the bug (following https://stackoverflow.com/q/1357118/5584077)

tab-bar-view.js

TabBarView.prototype.onMouseDown = function(event) {
  var ref, tab;
  tab = this.tabForElement(event.target);
  if (!tab) {
    return;
  }
  if (event.which === 3 || (event.which === 1 && event.ctrlKey === true)) {
    if ((ref = this.rightClickedTab) != null) {
      ref.element.classList.remove('right-clicked');
    }
    this.rightClickedTab = tab;
    this.rightClickedTab.element.classList.add('right-clicked');
    return event.preventDefault();
  } else if (event.which === 1 && !event.target.classList.contains('close-icon')) {
    return setImmediate((function(_this) {
      return function() {
        _this.pane.activateItem(tab.item);
        if (!_this.pane.isDestroyed()) {
          return _this.pane.activate();
        }
      };
    })(this));
  } else if (event.which === 2) {
    this.pane.destroyItem(tab.item);
    // return event.preventDefault();  // <====== comment
    return false;                      // <====== added
  }
};

so a patch on atom/tabs could be something like
tab-bar-view.coffee

diff --git a/lib/tab-bar-view.coffee b/lib/tab-bar-view.coffee
index eb5a2c2..0bcf6a5 100644
--- a/lib/tab-bar-view.coffee
+++ b/lib/tab-bar-view.coffee
@@ -415,7 +415,8 @@ class TabBarView
         @pane.activate() unless @pane.isDestroyed()
     else if event.which is 2
       @pane.destroyItem(tab.item)
-      event.preventDefault()
+      # event.preventDefault()
+      false
 
   onDoubleClick: (event) ->
     if tab = @tabForElement(event.target)

can anyone try this (i'm on atom-beta7 btw) ?

@lammas
Copy link

lammas commented Aug 5, 2017

Can confirm that this also worked for 1.19.0-beta4

jasonrudolph added a commit to atom/atom that referenced this issue Aug 7, 2017
On Linux, when the user performs a middle-button mouse click, Chromium
fires both a mouse-down event *and* a paste event. This commit teaches
the TextEditorComponent to ignore the paste event.

When the user performs a middle-mouse click on a tab, we get close the
tab and attempt to prevent Chromium's default processing for the event.
[1] This prevents Chromium's default processing for the *mouse down*
event, but then Chromium also fires a *paste* event, and that event
pastes the clipboard's current content into the newly-focused text
editor. 🙀

Since Atom already has its own logic for handling pasting, we
shouldn't (🤞) need to handle browser paste events. By ignoring the
browser paste events on Linux, we fix atom/tabs#461.

[1]
https://github.com/atom/tabs/blob/ce1d92e0abb669155caa178bb71166b9f16f329a/lib/tab-bar-view.coffee#L416-L418
jasonrudolph added a commit to atom/atom that referenced this issue Aug 7, 2017
On Linux, when the user performs a middle-button mouse click, Chromium
fires both a mouse-down event *and* a paste event. This commit teaches
the TextEditorComponent to ignore the paste event.

When the user performs a middle-mouse click on a tab, we get close the
tab and attempt to prevent Chromium's default processing for the event.
[1] This prevents Chromium's default processing for the *mouse down*
event, but then Chromium also fires a *paste* event, and that event
pastes the clipboard's current content into the newly-focused text
editor. 🙀

Since Atom already has its own logic for handling pasting, we
shouldn't (🤞) need to handle browser paste events. By ignoring the
browser paste events on Linux, we fix atom/tabs#461.

[1]
https://github.com/atom/tabs/blob/ce1d92e0abb669155caa178bb71166b9f16f329a/lib/tab-bar-view.coffee#L416-L418
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants