atom / toggle-quotes

An Atom package to toggle between single and double quotes
MIT License
77 stars 36 forks source link

[Tree-sitter] Introduces unexpected quote marks #61

Closed Aerijo closed 6 years ago

Aerijo commented 6 years ago

Description

The following applies to Tree-sitter grammars

When the cursor is at the beginning (adjacent right of the start quote mark), toggling quotes will introduce new quote characters

Steps to Reproduce

  1. Get a togglable string (e.g., print("foo") in Python)
  2. Place cursor between " and f
  3. Toggle quotes

Expected behavior: [What you expect to happen]

print('foo')

Actual behavior: [What actually happens]

print(''foo")

EDIT: To be clear, this happens to anything scoped as a string, in any language. The cause is that we are not accounting for Points being between characters, while we get the syntax node of a character. The default behaviour is to get the character to the left of the Point; on the edges this leads to unwanted behaviour.

Reproduces how often: [What percentage of the time does it reproduce?] 100%

Versions

toggle-quotes 1.1.1

Notes

It seems to be grabbing the node of the " rather than the entire string.

Aerijo commented 6 years ago

Requiring the string length be > 1 fixes this. Is it ever possible to have a 1-length string?

Also, there's a similar bug where you can toggle from the outer right, but not the outer left. It's related to how we convert from a point to an index, which requires "shifting" to the left; on the left, we shift to the (, on the right we shift to the ".

lee-dohm commented 6 years ago

Which version of Atom are you using? Nightly? Beta?

Aerijo commented 6 years ago

@lee-dohm Beta, but it happens when building from master too. I don't know how to use nightly. The issue itself is entirely related to this package though.

Ben3eeE commented 6 years ago

I see the same behavior with toggle-quotes 1.1.1 and 1.31.0-nightly8 with the text console.log('hi'); in a javascript file.

AlexWayfer commented 6 years ago

It's annoying bug. Will you make a new release with this fix?

Ben3eeE commented 6 years ago

@AlexWayfer Oops, sorry that we missed to release a new version. I just published 1.1.2.

AlexWayfer commented 6 years ago

Thank you.