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

Incorrect results when combining sequences of typeString (wrapped in HTML tag) and deleteChars #220

Open
sn3p opened this issue Jun 4, 2024 · 0 comments

Comments

@sn3p
Copy link

sn3p commented Jun 4, 2024

I'm trying to add multiple strings, each wrapped in a HTML tag, and delete them again.
I'm not sure if I'm overlooking something or if this is a bug.

This codepen illustrates the problem:
https://codepen.io/snap/pen/YzbVeJL?editors=1010

Problem

When doing .typeString("<i>World</i>") followed by .deleteChars("World".length), an empty <i> element remains in the DOM. Not really a problem in most cases.

But when repeating the above sequence twice or more, the element and string is not completely cleared. This is only happening when wrapping the string in a HTML tag:

new Typewriter("#typewriter")
  .typeString("Hello")
  .typeString("<i> World</i>")
  .deleteChars("World".length)
  .typeString("<i> World</i>")
  .deleteChars(" World".length)
  .deleteChars("Hello".length)
  .start()

When strings are not wrapped in a HTML tag it works just fine:

new Typewriter("#typewriter")
  .typeString("Hello")
  .typeString(" World")
  .deleteChars(" World".length)
  .typeString("World")
  .deleteChars(" World".length)
  .deleteChars("Hello".length)
  .start()

Workaround

When appending a space before the opening HTML tag it seems to work fine:

new Typewriter("#typewriter")
  .typeString("Hello")
  .typeString(" <i>World</i>")
  .deleteChars(" World".length)
  .typeString(" <i>World</i>")
  .deleteChars(" World".length)
  .deleteChars("Hello".length)
  .start()
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

No branches or pull requests

1 participant