Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Use CMs electric chars #9387

Merged
merged 1 commit into from
Apr 8, 2015
Merged

Conversation

marcelgerber
Copy link
Contributor

This fixes multiple issues:
#1324, #8434, #8723, #8980, #9120

I verified #8395 (fixed by #8439) is still fixed.

There's one behaviour change (tracked via codemirror/codemirror5#2812):
In a switch statement (JS), the cursor automatically indents 2 units, but back-indents as soon as you type "case".

@peterflynn You once noted (on IRC) you saw flaws with CM's implementation, could you please take a look?
cc @JeffryBooher

@peterflynn
Copy link
Member

Two quick thoughts:

  1. IIRC one of the reasons we forked this in the first place was indentation jumping around when typing ":" in object literals. We'll need to make sure that stays fixed, and if not we should look into merging our fix for that issue upstream to CM so our code can stay more in sync.
  2. It seems worth doing a little more verification on Brackets doesn't recognize existing indentation when auto-indenting close braces #8395, since looking at the CM implementation it's pretty clear they don't have any of the code that was added in Recognize existing indentation when indenting close braces #8439 -- they always call indentLine() immediately and directly. If Brackets doesn't recognize existing indentation when auto-indenting close braces #8395 is indeed still fixed, it would be good to understand why.

@peterflynn
Copy link
Member

Oh, IIRC another bug was that typing ":" inside a comment would cause the indentation to jump also...

@marcelgerber
Copy link
Contributor Author

Well, #8395 is still fixed as I left the code in (see diff) :)

@peterflynn
Copy link
Member

Oh I see -- didn't realize you found a way to keep that. Looks like that code needs to be made multi-cursor-aware though, otherwise #8434 isn't really fully fixed.

@marcelgerber
Copy link
Contributor Author

I just did some further tests and couldn't find any issues with ":", at least in JS mode.
I'd still be happy if you could test it yourself.

@marcelgerber marcelgerber force-pushed the cm-electric-chars branch 2 times, most recently from 83c5d74 to 5423209 Compare October 4, 2014 17:36
@marcelgerber
Copy link
Contributor Author

@peterflynn FYI, I fixed the anti-orphan code to support multiple cursors.

@peterflynn
Copy link
Member

Cool, thanks for making that update! I don't have a lot of cycles next week to do any testing, but hopefully someone else on the team can pick this up sooner.

@pthiess
Copy link
Contributor

pthiess commented Oct 27, 2014

@marcelgerber Hey Marcel, we are locking down for 1.0 but it will go into the next release.

@prafulVaishnav
Copy link
Contributor

@marcelgerber Picking this for review.

/**
* @private
* Handle CodeMirror key events.
* @param {!Event} event
*/
Editor.prototype._handleKeypressEvents = function (event) {
this._checkElectricChars(event);
var keyStr = String.fromCharCode(event.which || event.keyCode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelgerber Hii.. Can you please write this in separate function as it is specific to electricChars handling.

@marcelgerber
Copy link
Contributor Author

@prafulVaishnav Done. Please let me know when you'd like to merge so I can squash commits.

@prafulVaishnav
Copy link
Contributor

@marcelgerber You can squash commit. I will merge it then.

@marcelgerber
Copy link
Contributor Author

@prafulVaishnav Ready.

var keyStr = String.fromCharCode(event.which || event.keyCode);

if (/[\]\{\}\)]/.test(keyStr)) {
this._removeWhitespaceAfterBrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcelgerber Please update the function name to _handleWhitespaceForElectricChars

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Fixed.

prafulVaishnav added a commit that referenced this pull request Apr 8, 2015
@prafulVaishnav prafulVaishnav merged commit 97ed87b into adobe:master Apr 8, 2015
@prafulVaishnav
Copy link
Contributor

@marcelgerber Thanks.. It must fix various issues. I will check and close them all.

@marcelgerber marcelgerber deleted the cm-electric-chars branch April 8, 2015 11:44
@marcelgerber
Copy link
Contributor Author

In the description above, I listed some issues that should be fixed now.

@marcelgerber
Copy link
Contributor Author

I've just had a look at all the referenced issues myself - they are indeed all fixed.
Note for #8723: Checkout 7c7d429 so the line numbers are correct.

@marcelgerber
Copy link
Contributor Author

I also filed codemirror/codemirror5#3188, suggesting an event on electric char indent, so we can call _handleWhitespaceForElectricChars every time an electric char is handled, to also handle languages with more special electric chars like XML, Verilog, Ruby, or even JavaScripts case and default properly.

@prafulVaishnav
Copy link
Contributor

@marcelgerber Thanks.. We will track it and once it is there we will make the change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants