Fixes #498 - indentation guessing defaults to insertSpaces: true, tabSize: 4 when not enough hints
This commit is contained in:
parent
a72549198a
commit
d60cc73d82
|
@ -505,7 +505,7 @@ export class CommonEditorConfiguration extends EventEmitter implements EditorCom
|
|||
tabSizeIsAuto: false,
|
||||
tabSize: 4,
|
||||
insertSpacesIsAuto: false,
|
||||
insertSpaces: false
|
||||
insertSpaces: true
|
||||
};
|
||||
|
||||
if (opts.tabSize === 'auto') {
|
||||
|
|
|
@ -486,11 +486,11 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
|
|||
linesIndentedWithSpaces += (absoluteSpaceCounts[i] || 0);
|
||||
}
|
||||
|
||||
// Give preference to tabs over spaces (when evidence is the same)
|
||||
// Give preference to spaces over tabs (when evidence is the same)
|
||||
// or when there are not enough clues (too little indentation in the file)
|
||||
if (linesIndentedWithTabs >= linesIndentedWithSpaces) {
|
||||
return {
|
||||
insertSpaces: false,
|
||||
insertSpaces: true,
|
||||
tabSize: defaultTabSize
|
||||
};
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ export class TextModel extends OrderGuaranteeEventEmitter implements EditorCommo
|
|||
if (linesWithIndentationCount < 6 && linesIndentedWithTabs > 0) {
|
||||
// Making a guess with 6 indented lines, of which tabs are used besides spaces is very difficult
|
||||
return {
|
||||
insertSpaces: false,
|
||||
insertSpaces: true,
|
||||
tabSize: defaultTabSize
|
||||
};
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@ import Position = require('vs/editor/common/core/position');
|
|||
|
||||
function testGuessIndentation(expectedInsertSpaces:boolean, expectedTabSize:number, text:string[], msg?:string): void {
|
||||
var m = new TextModel.TextModel([], TextModel.TextModel.toRawText(text.join('\n')));
|
||||
var r = m.guessIndentation(1773);
|
||||
var r = m.guessIndentation(1337);
|
||||
m.dispose();
|
||||
|
||||
assert.equal(r.insertSpaces, expectedInsertSpaces, msg);
|
||||
if (expectedInsertSpaces) {
|
||||
assert.equal(r.tabSize, expectedTabSize, msg);
|
||||
} else {
|
||||
assert.equal(r.tabSize, 1773, msg);
|
||||
assert.equal(r.tabSize, 1337, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,26 +64,26 @@ suite('Editor Model - TextModel', () => {
|
|||
test('guess indentation 1', () => {
|
||||
|
||||
// Defaults to tabs
|
||||
guessesTabs([
|
||||
guessesSpaces(1337, [
|
||||
'x',
|
||||
'x'
|
||||
]);
|
||||
|
||||
// Gives preference to tabs
|
||||
guessesTabs([
|
||||
guessesSpaces(1337, [
|
||||
'\tx',
|
||||
'x'
|
||||
]);
|
||||
guessesTabs([
|
||||
guessesSpaces(1337, [
|
||||
'\tx',
|
||||
' x'
|
||||
]);
|
||||
guessesTabs([
|
||||
guessesSpaces(1337, [
|
||||
'\tx',
|
||||
' x'
|
||||
]);
|
||||
|
||||
guessesTabs([
|
||||
guessesSpaces(1337, [
|
||||
'x',
|
||||
' x',
|
||||
' x',
|
||||
|
@ -93,7 +93,7 @@ suite('Editor Model - TextModel', () => {
|
|||
' x',
|
||||
' x'
|
||||
], '7x1 - 1 space is never guessed as an indentation');
|
||||
guessesTabs([
|
||||
guessesSpaces(1337, [
|
||||
'',
|
||||
' ',
|
||||
' ',
|
||||
|
|
Loading…
Reference in a new issue