Skip to content

Commit a6ff7c5

Browse files
committed
Don't align indentation with previous body when there is content on a line
FIX: Fix an issue where the indentation logic would too eagerly align lines to the body directly above them. Closes codemirror/dev#1564
1 parent 34dbda2 commit a6ff7c5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/python.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const pythonLanguage = LRLanguage.define({
5656
props: [
5757
indentNodeProp.add({
5858
Body: context => {
59-
let inner = innerBody(context)
60-
return indentBody(context, inner || context.node) ?? context.continue()
59+
let body = /^\s*(#|$)/.test(context.textAfter) && innerBody(context) || context.node
60+
return indentBody(context, body) ?? context.continue()
6161
},
6262

6363
MatchBody: context => {
@@ -67,7 +67,7 @@ export const pythonLanguage = LRLanguage.define({
6767

6868
IfStatement: cx => /^\s*(else:|elif )/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
6969
"ForStatement WhileStatement": cx => /^\s*else:/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
70-
TryStatement: cx => /^\s*(except |finally:|else:)/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
70+
TryStatement: cx => /^\s*(except[ :]|finally:|else:)/.test(cx.textAfter) ? cx.baseIndent : cx.continue(),
7171
MatchStatement: cx => {
7272
if (/^\s*case /.test(cx.textAfter)) return cx.baseIndent + cx.unit
7373
return cx.continue()

0 commit comments

Comments
 (0)