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

Issue with Python indented structures in JupyterLab #16196

Open
divyansshhh opened this issue Apr 19, 2024 · 2 comments · May be fixed by #16306
Open

Issue with Python indented structures in JupyterLab #16196

divyansshhh opened this issue Apr 19, 2024 · 2 comments · May be fixed by #16306
Labels

Comments

@divyansshhh
Copy link
Contributor

Description

Consider the following snippet -

def fn():
    print("hi")
    for i in range(10):
        print("hello")

If the cursor is at the end of the last line and enter is pressed twice, the user is sent outside the function definition which is unintuitive. Attaching a gif demonstrating this -
enter-indentation

This happens even when defining functions in a class.

Reproduce

Expected behavior

I would expect the behavior to be the same as lab3/vscode.

vscode-enter-indentation

Context

  • JupyterLab version: 4.1.5
@jupyterlab-probot jupyterlab-probot bot added the status:Needs Triage Applied to new issues that need triage label Apr 19, 2024
@krassowski
Copy link
Member

krassowski commented Apr 19, 2024

For reproduction upstream: Playground example

and with indentOnInput addon.

@krassowski
Copy link
Member

krassowski commented Apr 19, 2024

Dedenting is intentional in the lang-python implementation by CodeMirror according to this code comment and the reasoning was given here: codemirror/lang-python#4 (comment)

I think this is the worst example, where the user intends to end the block, leave a blank line and start a new block of code but the indentation is forced into alignment with the body:

gif

However, I think that dedent on enter should only move you one block back, not two blocks back. I can reproduce the suboptimal behaviour in CodeMirror playground:

should-have-dedented-once

And because there is no dedent when typing function definition (indent on input is not implemented for Python for this case):

no-dedent-on-method

The current implementation is de facto fighting the user who tries to add a method to a class definition (whether they decide to add a new line per convention, or to start writing in the first new line they end up with wrong indentation anyways).

I opened an issue upstream to discuss: codemirror/dev#1370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants