[Qt-creator] It's time to fix double redundant quotes

Nikolai Kosjar nikolai.kosjar at theqtcompany.com
Wed Mar 9 14:09:41 CET 2016


Hi!

Let me summarize for myself and others the ways we can add quotes to 
some text. Default settings are assumed, the relevant one is:

  [x] Automatically insert matching characters.


a) Insert quote before text:
   Type: "foo
   This results in: "foo"
   The closing quote was added after typing the initial ".
   Looks fine.

b) Insert quotes afterwards by using selection.
    1. Type: foo bar
    2. Select the typed text
    3. Hit "
   This results in: "foo bar"
   Looks fine.

c) Insert quotes afterwards by starting with the closing quote
   You have: foo bar
   Type: "
   This results in: foo bar""
   Ops 1: The second " was not intended.
   Hit backspace.
   Ops 2: Both quotes are removed and you are the beginning again.


Note that if you hit " and another one is added, your cursor is then 
between the quotes: "|". Hitting backspace here removes then both 
quotes. If the cursor is behind both quotes (e.g. you've moved it there 
manually), only one quote is removed. This also applies to () and [], 
but not to {} (thinking of lambdas we probably should include that one, 
too).

Although the option in the settings is named "Automatically insert 
matching characters" it seems to also handle the removal of the pairs, 
at least when the cursor is in-between. We probably should change this 
if we do not introduce further options.

I agree that we should address the "Ops 2" from above, that is not 
removing both quotes if the cursor is in-between them. This will make it 
inconsistent when looking at () and [], but I think that's justified in 
this case. The problem here is the single quote by itself - you can't 
tell whether it's an opening or closing one without further information 
(typing ')' does not add you the opening one automatically).

Regarding "Ops 1", I don't think we can reliably detect whether the 
users inserts an opening or closing quote. Your heuristic is not enough:

On 03/08/2016 11:10 PM, Jason H wrote:
> Fundamentally, I want to changes to the behavior:
> 1. If the character after the cursor is not whitespace, do NOT double quote ("")

Would break case a) from above for e.g. function arguments:

	foo(|)
	foo(|,1)

> 2. If backspacing over a double quote, do not remove both double quotes.

Agree, see above.


Nikolai



More information about the Qt-creator mailing list