提交 1155cdf6 编写于 作者: P Peng Lyu

Fix #62143. Indentation guess may not be too eager with alignment.

上级 6e498530
......@@ -158,8 +158,19 @@ export function guessIndentation(source: ITextBuffer, defaultTabSize: number, de
spacesDiff(previousLineText, previousLineIndentation, currentLineText, currentLineIndentation, tmp);
if (tmp.looksLikeAlignment) {
// skip this line entirely
continue;
// if defaultInsertSpaces === true && the spaces count == tabSize, we may want to count it as valid indentation
//
// - item1
// - item2
//
// otherwise skip this line entirely
//
// const a = 1,
// b = 2;
if (!(defaultInsertSpaces && defaultTabSize === tmp.spacesDiff)) {
continue;
}
}
let currentSpacesDiff = tmp.spacesDiff;
......
......@@ -608,6 +608,46 @@ suite('Editor Model - TextModel', () => {
]);
});
test('issue #62143: Broken indentation detection', () => {
// works before the fix
assertGuess(true, 2, [
'x',
'x',
' x',
' x'
]);
// works before the fix
assertGuess(true, 2, [
'x',
' - item2',
' - item3'
]);
// works before the fix
testGuessIndentation(true, 2, true, 2, [
'x x',
' x',
' x',
]);
// fails before the fix
// empty space inline breaks the indentation guess
testGuessIndentation(true, 2, true, 2, [
'x x',
' x',
' x',
' x'
]);
testGuessIndentation(true, 2, true, 2, [
'<!--test1.md -->',
'- item1',
' - item2',
' - item3'
]);
});
test('validatePosition', () => {
let m = TextModel.createFromString('line one\nline two');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册