#319 ✓resolved
Jonathan Castello

Automatic quote balancing trips up

Reported by Jonathan Castello | September 21st, 2010 @ 08:38 AM

Entering a quote (") results in two quotes being written (which is fine). But when I remove the second quote and type " again, it inserts another pair of quotes, leaving my overall quotes unbalanced unless I manually delete the third quote.

Comments and changes to this ticket

  • tim.felgentreff (at student.hpi.uni-potsdam)

    tim.felgentreff (at student.hpi.uni-potsdam) October 11th, 2010 @ 09:27 AM

    I would think this is the intended behaviour.

  • tim.felgentreff (at student.hpi.uni-potsdam)
  • tim.felgentreff (at student.hpi.uni-potsdam)

    tim.felgentreff (at student.hpi.uni-potsdam) October 24th, 2010 @ 08:33 AM

    • Tag changed from possibly_invalid to needs info
  • Jonathan Castello

    Jonathan Castello October 24th, 2010 @ 09:22 AM

    It's rather annoying, and other editors (such as Aptana Studio) properly add only one quote if the cursor is within an unfinished string.

  • Jonathan Castello

    Jonathan Castello October 24th, 2010 @ 09:22 AM

    It's rather annoying, and other editors (such as Aptana Studio) properly add only one quote if the cursor is within an unfinished string.

  • tim.felgentreff (at student.hpi.uni-potsdam)

    tim.felgentreff (at student.hpi.uni-potsdam) October 24th, 2010 @ 09:41 AM

    Does Aptana handle all combinations of %w[], %{}, "", '' with contained quotes properly, too? Because I often use different string delimiters depending on which characters I want to use in my strings. Quite often, If I have a single quote somewhere, I still want double-quotes somewhere else.
    e.g. %{Ruby's String delimiters are 'awesome'}
    In this case I still want to get the auto-closed quotes around awesome.

  • Jonathan Castello

    Jonathan Castello October 24th, 2010 @ 09:48 AM

    It handles each set of balanced characters separately, it looks like. So I'd type {' and it would give me {''}. I personally find that behavior very reasonable.

    That said, if I were to type out your example naturally, I get %{Ruby's String delimiters are 'awesome''}, i.e. with an extra quote at the end. I don't think a system can easily determine whether you're using a single quote as an apostrophe or as quotes, so Aptana automatically doubles the quote in "Ruby's", and treats the start of 'awesome' as the end of that string.

  • Daniel Lucraft

    Daniel Lucraft October 24th, 2010 @ 09:52 AM

    • State changed from “new” to “open”

    Textmate also has the Aptana behaviour, so this is valid I think.

    Not sure how textmate "knows" though. It works in Plain Text mode, which has no concept of language grammar at all. Got to figure that out next to solve this.

  • tim.felgentreff (at student.hpi.uni-potsdam)

    tim.felgentreff (at student.hpi.uni-potsdam) October 24th, 2010 @ 09:54 AM

    • State changed from “open” to “new”
    • Tag cleared.
  • tim.felgentreff (at student.hpi.uni-potsdam)
  • Daniel Lucraft

    Daniel Lucraft October 24th, 2010 @ 09:54 AM

    • Tag set to needs info

    Let me expand on that last comment. If I'm in a line like this:

    ...
    foo " bar <cursor> baz
    ...
    

    If I type " now, am I opening or closing a string? There's no real way to know.

    Unless it goes on a line only basis as a 90% solution. Let me check that.

  • Daniel Lucraft

    Daniel Lucraft October 24th, 2010 @ 09:58 AM

    OK, from what I can tell, Textmate just does it on a current-line only basis. So in this situation, it will get it wrong:

    foo " bar
    baz " qux <cursor>
    

    Because it will just insert one " when it should insert "". Ie. it thinks you are closing a string even though you are opening one.

    But the case of having strings just on one line is so much more common that moving to this heuristic would improve our handling a lot. Let's do it.

  • Jonathan Castello

    Jonathan Castello October 24th, 2010 @ 10:00 AM

    • Tag cleared.

    "", '', (), [], and {} are all supported by Aptana, which is sensible: each one is primarily found balanced in every language I've used so far. However, <> is not, probably because it's even more widespread in singular form as comparison operators. A grammar-agnostic editor shouldn't have a hard time deciding what to balance, AFAICT.

  • Daniel Lucraft

    Daniel Lucraft October 24th, 2010 @ 10:06 AM

    We have a context sensitive matcher. So <> is paired in HTML, but not in Ruby, etc. We can reuse that for this.

  • Jonathan Castello

    Jonathan Castello October 24th, 2010 @ 11:26 AM

    Also, it seems Aptana can do it over multiple lines. If I type " then remove the second quote so I get just one ", then hit enter and type " again, I properly get one " on each line. (As a bonus, it puts a square around the first quote to show which one the second quote matches.)

  • Daniel Lucraft

    Daniel Lucraft October 24th, 2010 @ 11:27 AM

    That's cool. I suspect that is because Aptana is parsing the Ruby?

    In general, we can't do that.

  • Daniel Lucraft

    Daniel Lucraft October 24th, 2010 @ 11:36 AM

    • State changed from “open” to “resolved”

    OK, I've updated the logic.

    IF the front and back pair characters are the same, say X.
    IF the character X occurs an odd numbers of times on the cursor line preceding the cursor.
    THEN the usual insert XX logic is overridden and only X will be inserted when you type X.

    I'd love to have more clever logic around this. But it's extremely hard to get this perfectly right, so this seems pragmatic.

    And with that, I'm closing the bug. Thanks for the report, this will be in 0.8

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A programmer's text editor for Gnome.

People watching this ticket

Pages