question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v-html can not reselect content when content change!

See original GitHub issue

Version

2.5.2

Reproduction link

https://jsfiddle.net/weituotian/0rc7zq1b/5/

Steps to reproduce

  • select h11111111111111111
  • click rerender button
  • then you can see the selected can not be reselected

What is expected?

I hope I can update incrementally so that my html content can be selected back to the previous selection.

What is actually happening?

If the html changes, then the window.getSelection().addRange can not choose to go back to the previous content.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Justineocommented, Jul 6, 2018

Calm down plz.

it is because vue update the html, and there is impossible to reselect the previous selection!!!

Of course you can, you just need to decide how to record previous selections yourself, even with v-html.

Vue should be responsible for the issue after updating the dom element!

Absolutely not. By using v-html like this you are explicitly re-rendering all existing content, that’s why the selections are discarded. If you are just appending content, just try to keep previous content as much as possible and the selection will be preserved.

You can check on this: http://jsfiddle.net/eywraw8t/143042/

And btw, don’t take free help for granted.

0reactions
AfterThreeYearscommented, Jul 7, 2018

@Justineo The example may be written in error, It should be so

this.contents.push(Math.floor(Math.random() * 3))
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't select html text - Stack Overflow
The solution is to use margin-left not padding left. Share. Share a link to this answer.
Read more >
Can't change HTML content successfully - JavaScript - SitePoint
The problem is that the the text within <em> tags changes after the script is executed but I don't know why the text...
Read more >
The HTML Option element - MDN Web Docs - Mozilla
The content of this attribute represents the value to be submitted with the form, should this option be selected.
Read more >
user-select - CSS-Tricks
The user-select property in CSS controls how the text in an element is allowed to be selected. For example, it can be used...
Read more >
Changing fonts - Squarespace Help Center
Any site text currently using that font won't change, but if you switch to a different font, you can't switch back. Instead, we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found