@codemirror/lang-python
Advanced tools
Comparing version 6.1.5 to 6.1.6
@@ -0,1 +1,7 @@ | ||
## 6.1.6 (2024-04-29) | ||
### Bug fixes | ||
Improve the way indentation for the current body is preserved when inenting new lines. | ||
## 6.1.5 (2024-03-28) | ||
@@ -2,0 +8,0 @@ |
@@ -195,2 +195,28 @@ import { parser } from '@lezer/python'; | ||
function innerBody(context) { | ||
let { node, pos } = context; | ||
let lineIndent = context.lineIndent(pos, -1); | ||
let found = null; | ||
for (;;) { | ||
let before = node.childBefore(pos); | ||
if (!before) { | ||
break; | ||
} | ||
else if (before.name == "Comment") { | ||
pos = before.from; | ||
} | ||
else if (before.name == "Body") { | ||
if (context.baseIndentFor(before) + context.unit <= lineIndent) | ||
found = before; | ||
node = before; | ||
} | ||
else if (before.type.is("Statement")) { | ||
node = before; | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
return found; | ||
} | ||
function indentBody(context, node) { | ||
@@ -223,3 +249,7 @@ let base = context.baseIndentFor(node); | ||
/*@__PURE__*/indentNodeProp.add({ | ||
Body: context => { var _a; return (_a = indentBody(context, context.node)) !== null && _a !== void 0 ? _a : context.continue(); }, | ||
Body: context => { | ||
var _a; | ||
let inner = innerBody(context); | ||
return (_a = indentBody(context, inner || context.node)) !== null && _a !== void 0 ? _a : context.continue(); | ||
}, | ||
IfStatement: cx => /^\s*(else:|elif )/.test(cx.textAfter) ? cx.baseIndent : cx.continue(), | ||
@@ -233,18 +263,5 @@ "ForStatement WhileStatement": cx => /^\s*else:/.test(cx.textAfter) ? cx.baseIndent : cx.continue(), | ||
Script: context => { | ||
if (context.pos + /\s*/.exec(context.textAfter)[0].length >= context.node.to) { | ||
let endBody = null; | ||
for (let cur = context.node, to = cur.to;;) { | ||
cur = cur.lastChild; | ||
if (!cur || cur.to != to) | ||
break; | ||
if (cur.type.name == "Body") | ||
endBody = cur; | ||
} | ||
if (endBody) { | ||
let bodyIndent = indentBody(context, endBody); | ||
if (bodyIndent != null) | ||
return bodyIndent; | ||
} | ||
} | ||
return context.continue(); | ||
var _a; | ||
let inner = innerBody(context); | ||
return (_a = (inner && indentBody(context, inner))) !== null && _a !== void 0 ? _a : context.continue(); | ||
} | ||
@@ -251,0 +268,0 @@ }), |
{ | ||
"name": "@codemirror/lang-python", | ||
"version": "6.1.5", | ||
"version": "6.1.6", | ||
"description": "Python language support for the CodeMirror code editor", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
34526
605