"Open all external links in a new tab" does not work when you select some text

  1. Make sure that you have Open all external links in a new tab option checked in /my/preferences/interface Other interface options (It seems to be the default setting, anyway)
  2. Find any post with an external link – random examples in meta and in try
  3. Click the first external link you find in that post (preferably the same)

It opens in a new tab, good. :+1:

BUT:

  1. Make sure that you have Open all external links in a new tab option checked in /my/preferences/interface Other interface options (It seems to be the default setting, anyway)
  2. Open same post as previous test
  3. Select any text in this post (1+ letter, 1+ word, any selection will do) – You should see a floating Quote button
  4. Click the first external link you find in that post

:no_entry: :see_no_evil: :warning: Now the external link open in current tab, instead of new tab. :warning: :see_no_evil: :no_entry:


:information_source: Actually you can simply try with this post here:

  1. Click THIS EXTERNAL LINK – OK good :+1: new tab
  2. Select THIS TEXT
  3. Click the step 1 external link, again – NG :no_entry: current tab
4 Likes

I can confirm. I’m not entirely sure it’s worth fixing, as it seems like an edge case, where the user is asking for trouble.

1 Like

Because you think it might be tricky to fix?

I often click. I often select text.
So it bugs me very often.

I did mention this bug long time ago but I did not explain it as well as this time. :wink:

That is annoying.

If you don’t have the skills to submit a PR (I don’t think I do) then just using control-click to open in a new tab will work, isn’t hard to automatize, and will solve the problem on every site, even those that don’t open links in new tabs.

1 Like

I would use Ctrl+click but we have this nice option, called Open all external links in a new tab.

But what this option relay does is Open random external links in a new tab.

It took me months, if not years, to pinpoint a reproduction scheme.
It felt really random to me.

Maybe remove this option, for a consistent behaviour?

I remember trying to setup a Discourse dev environment for a simple CSS issue PR.
But, if I remember correctly, I gave up because my PC was too old and I could not install or run all requirements.

1 Like

I found back my previous failed attempt at installing a Discourse dev environment.
My personal Linux PC was too old and my professional Windows laptop had no hyper threading activated.

My new professional laptop is now apparently hyper threading* so I will see if I can follow the new instructions, without admin rights.

* wmic CPU Get NumberOfCores,NumberOfLogicalProcessors shows more logical cores than physical cores.

Hello,

I think it can fixable with CSS.

.cooked a {
  @include user-select(text);
}

I hope it helps, I haven’t really tested it yet but seems works fine. :slightly_smiling_face:

Edit: user-select: text should added to the link because not only the .cooked selected text affect it but every selected text on the site. I changed the code.

6 Likes

That looks like magic to me. I’d like to know how it works, can you explain this trick? :hugs:

2 Likes

Awesome sleuthing Don, would you like to submit a PR?

6 Likes

Thanks Sam, I just testing it more closely before submitting and it seems this is not enough unfortunately. This solution only works with Chrome.

5 Likes

Here’s the piece of code causing the bug (from app/assets/javascripts/discourse/app/lib/click-track.js)

    // Cancel click if triggered as part of selection.
    const selection = window.getSelection();
    if (selection.type === "Range" || selection.rangeCount > 0) {
      if (selectedText() !== "") {
        return true;
      }
    }

Removing this code solves the problem and doesn’t appear to break tests (I have some tests failing before and after the change for some reason but no new ones apparently).
So I’m wondering whether this code does anything useful because one thing it sure doesn’t do is what it says it does, otherwise the bug reporter would experience no link follow at all upon ‘select + click’ but that’s not his complaint.
Can someone share what this code is supposed to accomplish?

1 Like

Maybe it’s made to prevent opening links in new tabs when just selecting some text to quote our copy?

When the code you found is deactivated and when you have the “Open all external links in a new tab” option checked,

Could you try to select (mouse down, drag, mouse up) some text that includes links to see if it does not open any of them?

Try with a selection that surrounds links and also try with a selection that ends in the middle of a link, maybe.

The selection should always just select, not open links.

Yes, such selections work as expected: without following links or opening them in new tabs.

1 Like

I vaguely recall there was a workaround for a specific browser, maybe try in Safari/Firefox/Chrome with a selection to see if any trigger it?

1 Like

Works on Firefox, Chrome. How should I try Safari on Ubuntu?

1 Like

Is your dev server accessible on your wi-fi so that you could also test with your smartphone?

Maybe the touch screen finger drag events are triggering the open links.

You could add this smartphone browser (Firefox, Chromium-based or Safari) to your tested browser list. :sunglasses:

And, but the way, thank you so very much for your work on this bug!!

I found this reason for this cancel code, apparently:

Prevent a click if the user select content in a topic and release the mouse over a link.

https://meta.discourse.org/t/selecting-a-link-results-in-it-being-opened/14846
[deleted topic]

Interesting comment:

I only have access to windows platform for testing.

this fix can be tested easily as the file can be pasted as a whole into the console.

@sam you know which file we should paste in the console after loading a topic page?
@Aleksey_Bogdanov could give that file and I could paste it in my Windows Vivaldi, Firefox, Android 9 Kiwi browser consoles, and you could paste it in your iOS, Mac OS Safari.

I don’t think it works like that any more.

1 Like

No problem detected in Chrome and Firefox on Android although I struggle to select in Firefox as liberally.

1 Like

It was the same before your change, right?