Selective bracket insertion/skipping for quotes #1065

Merged
merged 8 commits into from Nov 12, 2012

Conversation

Projects
None yet
3 participants
Member

lennartcl commented Oct 24, 2012

As a minor followup on #1055, this adds the same selective behavior to quotes and other minor fixes.

@ajaxorg/liskov

Member

nightwing commented Oct 24, 2012

i noticed this is more strict than sublime
sublime adds closing bracket if next character is a space
is this strictness intentional?

Member

nightwing commented Oct 25, 2012

I think this is still too restrictive, even o.foo|.bar isn't converted to o.foo(|).bar.
Textmate only checks for next letter being word_char which is much simpler and predictable.

Otherwise this looks good, so if you really want to keep current behavior, feel free to merge this.

Member

lennartcl commented Nov 2, 2012

Okay, it should definitely insert before the ., so consider that a bug :). The current implementation is based mostly on the Eclipse and Spoofax behavior, and their tokenization works a bit differently. Anyway, I relaxed it a bit more.

There's still one scenario that bothers me a bit, and I'm not sure what to do about it. It's what happens if you have code like

foo();
bar();

and want to put a try/catch or if or something around it. You'll get something like

try {}
foo();
bar();

which is quite annoying :( What Eclipse does is show try { and only insert the closing } if you hit enter again. Could that work for us with JavaScript? The only thing is that you wouldn't get a closing bracket when you want to write a function closure on one line :/ But I'd rather miss a closing bracket that get one too many. Any suggestions?

Contributor

mostafaeweda commented Nov 7, 2012

Yes, I agree with you
I prefer the editor not typing stuff for me that I'll have to delete rather than I add the closing bracket myself

Member

lennartcl commented Nov 12, 2012

@mostafaeweda Thanks for your feedback!

Alright, I updated the implementation to handle that scenario: curly brackets are now no longer inserted until you press enter:

try {

plus enter

gives

try {

}

Things are getting a bit more complicated as we go along, but it basically follows the spec from Eclipse and also does bracket skipping the same way as TextMate does it.

nightwing added a commit that referenced this pull request Nov 12, 2012

Merge pull request #1065 from ajaxorg/selective-bracket-insertion
Selective bracket insertion/skipping for quotes

@nightwing nightwing merged commit bd41009 into master Nov 12, 2012

1 check was pending

default The Travis build is in progress
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment