Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Users should have intelligent autoindenting in the notebook #442

Closed
certik opened this Issue · 13 comments

3 participants

@certik

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.

@ellisonbg
Owner

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

@certik

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.

@certik

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.

@certik

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.

@ellisonbg
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/

@certik

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.

@ellisonbg
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.

@certik

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.

@jasongrout
Owner

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

@ellisonbg
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.

@ellisonbg
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.

@ellisonbg ellisonbg was assigned
@ellisonbg
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?

@ellisonbg
Owner

Implemented in htmlnotebook branch.

@ellisonbg ellisonbg closed this
@damianavila damianavila referenced this issue from a commit
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.