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

Insert Link: clicking on same-page links reloads the editor #10117

Closed
johanneswilm opened this issue Sep 23, 2018 · 11 comments
Closed

Insert Link: clicking on same-page links reloads the editor #10117

johanneswilm opened this issue Sep 23, 2018 · 11 comments
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Feature] UI Components Impacts or related to the UI component system [Type] Bug An existing feature does not function as intended

Comments

@johanneswilm
Copy link

Describe the bug
Internal links should just make the selection jump to the link's target. Instead they make the page reload.

To Reproduce
Steps to reproduce the behavior:

  1. Create headline with anchor value "myanchor"
  2. Create a link with target "#myanchor"
  3. Click on link within the editor
  4. The page reloads

Expected behavior
the caret should jump to the headline with anchor value "myanchor" and the page should not reload.

@designsimply designsimply added the Needs Testing Needs further testing to be confirmed. label Sep 24, 2018
@designsimply
Copy link
Member

Tested and confirmed that if I create a link to #myanchor and click the link in the floating link toolbar, it will open the editor in a new tab or window.

screen shot 2018-09-24 at 2 26 12 pm

@designsimply designsimply changed the title clicking on inline links reloads the page Insert Link: clicking on same-page links reloads the editor Sep 24, 2018
@designsimply designsimply added [Type] Enhancement A suggestion for improvement. [Feature] UI Components Impacts or related to the UI component system Needs Decision Needs a decision to be actionable or relevant and removed Needs Testing Needs further testing to be confirmed. labels Sep 24, 2018
@gziolo gziolo added [Type] Bug An existing feature does not function as intended Needs Dev Ready for, and needs developer efforts Good First Issue An issue that's suitable for someone looking to contribute for the first time and removed Needs Decision Needs a decision to be actionable or relevant [Type] Enhancement A suggestion for improvement. labels May 23, 2019
@talldan
Copy link
Contributor

talldan commented Apr 22, 2020

Currently still an issue.

@gwwar
Copy link
Contributor

gwwar commented Mar 25, 2021

Verified that this is still an issue 👍

internallinks.mp4

@gwwar
Copy link
Contributor

gwwar commented Mar 25, 2021

While implementing this, we may also want to keep in mind allowing browser link copy -> pasting a link on text, retaining the right link

pastelink.mp4

See #28115 (comment)

@arthur791004
Copy link
Contributor

Hi all, I think the current expected behavior described above is great but I have another thoughts. There is an external link icon which indicates it would open the new tab after clicking. Therefore, as a user, I might expect that when I clicked it, it would open the new tab and scroll to anchor. However, the page should not be edit mode because I want to test the behavior in other people's point rather than mine.

In short, the relative anchor link should have the same behavior with absolute link in this demo video #10117 (comment)

Does it make sense?

@skorasaurus
Copy link
Member

still an issue on gutenberg 13.0.0.

@carolinan
Copy link
Contributor

Yes, still an issue.
Mac OS, Chrome, WordPress 6.0 and Gutenberg trunk (13.6.x).

Screen.Recording.2022-07-08.at.07.43.21.mov

I wonder if it would be better (and certainly easier?) to prevent actions when clicking on a link that starts with #, rather than try to move focus to the link target in the editor.

@carolinan carolinan added the [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) label Jul 8, 2022
@carolinan
Copy link
Contributor

I wonder why it is labeling local links -non anchor links to existing content on the same install -as external 🤔

@carolinan carolinan removed Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts labels Jul 28, 2022
@gwwar
Copy link
Contributor

gwwar commented Aug 6, 2022

I took a quick look at this and I wasn't sure what the ideal behavior is.

  • If we'd like to open the url to a preview page with the anchor selected, one problem to work through is that the link-preview component exists in the block-editor package, and should not have any awareness of WordPress details (such as where a published post will be) . See the Modularity page for more details.
  • We could make the behavior jump to the linked anchor block in the editor, but it feels a bit expensive to do this. Primarily we'd need to search over all blocks to see if we save an anchor attribute (or alternatively parse content to see if we have a matching id).

Eg very roughly something like the following

// likely too expensive to be worth it.
const blocks = wp.data.select('core/block-editor').getBlocks()
// check each block to see if it has an anchor attribute, or has a matching id in content
wp.data.dispatch( 'core/block-editor' ).selectBlock(clientId)

I wonder if it makes the most sense to simply do nothing when we click on this type of anchor link.

Let me know if folks think of other options or ideas.

@carolinan
Copy link
Contributor

Yes "do nothing" was implemented in #42259.

@youknowriad
Copy link
Contributor

Going to close this as the "do nothing" option above seems the most sensible and has been implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Feature] UI Components Impacts or related to the UI component system [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

9 participants