Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smartIndent and indentWithTabs not working #612

Closed
samuela opened this issue Jun 29, 2012 · 11 comments
Closed

smartIndent and indentWithTabs not working #612

samuela opened this issue Jun 29, 2012 · 11 comments

Comments

@samuela
Copy link
Contributor

samuela commented Jun 29, 2012

smartIndent and indentWithTabs are not working as expected. See http://jsbin.com/ihunin/34/edit#preview for full explanations and examples. In the first CodeMirror instance, you can see that tabs are inserted instead of spaces and in the second, you can see that smart indentation does not follow the indentation settings and instead just inserts two spaces.

@marijnh
Copy link
Member

marijnh commented Jun 29, 2012

There are two sources of confusion here:

  • You have to set indentUnit and tabSize to the same number to get the behaviour you expected for the second editor
  • You have to bind the "Tab" key to something other than "defaultTab" ("indentAuto") is probably what you want in extraKeys.

@marijnh marijnh closed this as completed Jun 29, 2012
@samuela
Copy link
Contributor Author

samuela commented Jun 30, 2012

Thanks! Sorry for the confusion.. These properties do behave a little different than expected though. I'm not sure if this is just me but maybe some mention in the documentation would prevent this question from coming up again

@samuela
Copy link
Contributor Author

samuela commented Jun 30, 2012

I'm still running into some problems with indentAuto(). See http://jsbin.com/ihunin/49/edit#preview. Attaching it in extraKeys as a string seems to work but calling it by itself doesn't. Am I doing something wrong here?

@marijnh
Copy link
Member

marijnh commented Jul 1, 2012

indentAuto is a 'command', which are functions stored in CodeMirror.commands. You can call it through CodeMirror.commands.indentAuto(cm), wherecm` is your CodeMirror instance.

@samuela
Copy link
Contributor Author

samuela commented Jul 2, 2012

Right, and in the jsbin I called CodeMirror.commands.indentAuto(editor). Really though what I'd like to do is something like this::

CodeMirror.fromTextArea(document.getElementById("code"), {
    extraKeys: {
        "Tab": function(cm) {
            if(<blah blah blah>) {
                CodeMirror.commands.indentAuto(editor);
            }
        }
   }
});

But I can't get that to work.. The weird thing is that setting "Tab": "indentAuto" in extraKeys does work. I'll post another jsbin when I get a chance.

@samuela
Copy link
Contributor Author

samuela commented Jul 2, 2012

Ok I put together a jsbin here http://jsbin.com/ihunin/54/edit#preview. I'm not writing this on my usual computer so if I recall correctly, setting "Tab": "indentAuto" worked on Chrome but now it doesn't look like it's working on Safari 5. Setting "Tab": function(cm) { CodeMirror.commands.indentAuto(cm); } has never worked for me though.

@marijnh
Copy link
Member

marijnh commented Jul 3, 2012

Describe 'work'. The problem here is likely to be that your expectations of features don't agree to what the manual says.

When a keymap points at a string, it will interpret it as a property of CodeMirror.commands. Thus, the two invocations you gave are equivalent (and the second works just fine when I try it).

@samuela
Copy link
Contributor Author

samuela commented Jul 3, 2012

Right, and I understand that. Neither of them work for me on Safari. In the second one when I hit tab, I get the alert but no indent. Am I misunderstanding what indentAuto does?

@samuela
Copy link
Contributor Author

samuela commented Jul 3, 2012

Also, when indentAuto is called in an indented line, all of the indentation is deleted.. I expect indentAuto to insert either indentUnit spaces or one real tab depending on the options. Is this correct?

@marijnh
Copy link
Member

marijnh commented Jul 3, 2012

What indentAuto does is reset the line's indentation to the 'correct' indentation that the mode reported. You probably want the indentMore command instead.

@samuela
Copy link
Contributor Author

samuela commented Jul 3, 2012

Got it, that makes sense now. Thanks!

espadrine added a commit to espadrine/CodeMirror that referenced this issue Mar 3, 2013
Issues codemirror#988, codemirror#742, codemirror#612, etc. show that CodeMirror users tend to:

1. Not find how to make the Tab key insert spaces instead of a tab,
2. Miss how to use extraKeys to easily solve the issue.

Adding an example helps them find a solution immediately.
marijnh pushed a commit that referenced this issue Mar 4, 2013
Issues #988, #742, #612, etc. show that CodeMirror users tend to:

1. Not find how to make the Tab key insert spaces instead of a tab,
2. Miss how to use extraKeys to easily solve the issue.

Adding an example helps them find a solution immediately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants