Skip to content
This repository

Users should have intelligent autoindenting in the notebook #442

Closed
certik opened this Issue May 14, 2011 · 13 comments

3 participants

Ondřej Čertík Brian E. Granger Jason Grout
Ondřej Čertík
certik commented May 14, 2011

If you write this:

def f(x):
    a = 5
b = 5

the b=5 part should be automatically indented in the function f(x). But it isn't, and that's a bug. This is in codemirror.

Brian E. Granger
Owner

Are you sure, I thought I turned autoindenting off (which it should be by default).

Ondřej Čertík
certik commented May 14, 2011

I tried again, and indeed, all autoindenting is off. Sorry for that, I must have made a mistake.

But I vote to have the following feature on: "keep the indentation level". so if I am indented twice (2x4spaces), I would like to just keep pressing "enter", instead of always pressing "tab" twice in order to continue writing the function.

Ondřej Čertík
certik commented May 14, 2011

And I vote for the following feature "if you press BACKSPACE", it would delete 4 spaces at once, assuming only spaces are to the left of the cursor. That way, it is supper easy to get to the beginning of the line, after the function definition is done.

That's how my VIM is configured, and I never had any problems with this behavior.

Ondřej Čertík
certik commented May 16, 2011

So this option in notebook.js is responsible for it:

        enterMode : 'flat',

Documentation is here:
http://codemirror.net/manual.html
and both keep and indent options work better imho.

The only annoying thing is that backspace doesn't delete 4 spaces. I'll see if I can implement it.

But I like 'indent' the most.

Brian E. Granger
Owner

In general I am not fond of autoindentation, but I am open to it possibly if we can get backspace to delete 4 spaces at a time. Otherwise you have to type 4 key strokes to dedent a level, which will only anger users. The golden rule of UI design is "don't anger your users" But all of the final usability decisions like this will be answered by doing actual usability studies with real users. This site was highly recommended to me:

http://www.usertesting.com/

Ondřej Čertík
certik commented May 16, 2011

You will anger some users anyway. For example I am angered with the flat mode (default), because it doesn't keep the indentation, so it's really not usable for me. At least using keep would be great. Fortunately, this is easy to fix, just one line of code, so no big deal.

However, the backspace is also annoying (super annoying to be honest), so it needs to be fixed. I have looked into it, but not have time at the moment, but eventually I'll get to it.

Brian E. Granger
Owner

I agree that some users will always be angered or annoyed. The goal of usability testing is to identify what those annoyances are and for whom. For example, if usability testing shows that 90% of users prefer "keep" for the indentation mode, then we will use that, even if 10% of users don't like it. But, in things like this, we will eventually have a config section that allows advanced (or annoyed) users to adjust things to their liking.

In spite of all of this, I do think that "keep" is probably a good default if we can fix the backspace bug. But until then, I think we should leave it as is.

One last important point on this. We (developers) tend to be horrible judges in areas like this because we are not "typical" users. I am guilty of this as much as any of us.

Ondřej Čertík
certik commented May 16, 2011

I agree. Keeping indentation, that is such a basic thing, that I thought that every editor should do. Even when I was learning to do programing, in Turbo Pascal, at the age of 7, the editor was keeping indentation. Honestly, I would enable "keep" mode by default and be done with it.

And implement backspace later, as time permits.

Jason Grout

Note that shift-tab should dedent 4 spaces. Is that a good compromise?

Brian E. Granger
Owner

I am fine with shift-tab working like this, but not as a substitute for fixing the backspace bug. I have posted to the codemirror list about this issue and will keep everyone updated.

Brian E. Granger
Owner

Here is the response of the CodeMirror devs:

Bind your own handler to the backspace key using onKeyEvent, and have
that check for whitespace before the cursor and remove up to four
spaces if present.

This should not be too difficult, so I think we should take this approach.

Brian E. Granger
Owner

@certik: I have implemented autoindentation and auto-4-space-delete in the htmlnotebook branch. Could you test and confirm it is behaving as you expect?

Brian E. Granger
Owner

Implemented in htmlnotebook branch.

Brian E. Granger ellisonbg closed this August 09, 2011
Damián Avila damianavila referenced this issue from a commit July 30, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.