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

Fix some indent problems #250

Merged
merged 4 commits into from
Feb 14, 2012
Merged

Fix some indent problems #250

merged 4 commits into from
Feb 14, 2012

Conversation

gruehle
Copy link
Member

@gruehle gruehle commented Feb 13, 2012

@njx

  • Pressing the TAB key on an empty line no longer inserts an additional tab.
  • Fixed problem that occasionally added an additional space character when typing a tab.
  • Disable built-in "electric chars" feature and replace with a less heavy-handed version. The new version does the following:
    • Only runs when closing braces are typed: "]", "}", or ")"
    • Only runs if the line is all whitespace (except the closing brace)
      This should eliminate the majority of the odd and unpredictable auto-indent behaviors.

This fixes issues #155 and #193.

* Pressing the TAB key on an empty line no longer inserts an additional tab.
* Fixed problem that occasionally added an additional space character when typing a tab.
* Disable built-in "electric chars" feature and replace with a less heavy-handed version. The new version does the following:
 * Only runs when closing braces are typed: "]", "}", or ")"
 * Only runs if the line is all whitespace (except the closing brace)
This should eliminate the majority of the odd and unpredictable auto-indent behaviors.
},
onKeyEvent: function (instance, event) {
if (event.type === "keypress") {
var keyStr = String.fromCharCode(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.

CodeMirror does this:

        var ch = String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode);

I'm assuming this is to deal with browsers that handle keyCode/charCode differently. Should we do the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, I had no idea how much of a mess JavaScript keyboard handling was until I read this page:
http://unixpapa.com/js/key.html

Luckily, for us, using keypress and checking for ASCII characters is easy:
http://stackoverflow.com/questions/1444477/keycode-and-charcode

Code updated.

@njx
Copy link
Contributor

njx commented Feb 14, 2012

Done with first review.

@njx
Copy link
Contributor

njx commented Feb 14, 2012

Just tested this and it isn't working for me. If I'm in a blank JS file and I type:

function foo() {
    blah();

then hit Return after blah(); and type the close-brace, it indents it to the right instead of pulling it back over to the left.

@njx
Copy link
Contributor

njx commented Feb 14, 2012

It looks like the problem is the "smart" argument--if I remove it, it does the right thing. So it must not be the case that passing "smart" is the same as passing nothing.

@gruehle
Copy link
Member Author

gruehle commented Feb 14, 2012

Passing 'smart' wasn't so smart after all... removed.

njx added a commit that referenced this pull request Feb 14, 2012
@njx njx merged commit 6879724 into master Feb 14, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants