mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
Fix #29881. Null guard
This commit is contained in:
parent
42ae1fc0f6
commit
8b4e4428b7
|
@ -502,23 +502,25 @@ export class AutoIndentOnPaste implements IEditorContribution {
|
|||
}
|
||||
};
|
||||
let indentOfSecondLine = LanguageConfigurationRegistry.getGoodIndentForLine(virtualModel, model.getLanguageIdentifier().id, startLineNumber + 1, indentConverter);
|
||||
let newSpaceCntOfSecondLine = IndentUtil.getSpaceCnt(indentOfSecondLine, tabSize);
|
||||
let oldSpaceCntOfSecondLine = IndentUtil.getSpaceCnt(strings.getLeadingWhitespace(model.getLineContent(startLineNumber + 1)), tabSize);
|
||||
if (indentOfSecondLine !== null) {
|
||||
let newSpaceCntOfSecondLine = IndentUtil.getSpaceCnt(indentOfSecondLine, tabSize);
|
||||
let oldSpaceCntOfSecondLine = IndentUtil.getSpaceCnt(strings.getLeadingWhitespace(model.getLineContent(startLineNumber + 1)), tabSize);
|
||||
|
||||
if (newSpaceCntOfSecondLine !== oldSpaceCntOfSecondLine) {
|
||||
let spaceCntOffset = newSpaceCntOfSecondLine - oldSpaceCntOfSecondLine;
|
||||
for (let i = startLineNumber + 1; i <= range.endLineNumber; i++) {
|
||||
let lineContent = model.getLineContent(i);
|
||||
let originalIndent = strings.getLeadingWhitespace(lineContent);
|
||||
let originalSpacesCnt = IndentUtil.getSpaceCnt(originalIndent, tabSize);
|
||||
let newSpacesCnt = originalSpacesCnt + spaceCntOffset;
|
||||
let newIndent = IndentUtil.generateIndent(newSpacesCnt, tabSize, insertSpaces);
|
||||
if (newSpaceCntOfSecondLine !== oldSpaceCntOfSecondLine) {
|
||||
let spaceCntOffset = newSpaceCntOfSecondLine - oldSpaceCntOfSecondLine;
|
||||
for (let i = startLineNumber + 1; i <= range.endLineNumber; i++) {
|
||||
let lineContent = model.getLineContent(i);
|
||||
let originalIndent = strings.getLeadingWhitespace(lineContent);
|
||||
let originalSpacesCnt = IndentUtil.getSpaceCnt(originalIndent, tabSize);
|
||||
let newSpacesCnt = originalSpacesCnt + spaceCntOffset;
|
||||
let newIndent = IndentUtil.generateIndent(newSpacesCnt, tabSize, insertSpaces);
|
||||
|
||||
if (newIndent !== originalIndent) {
|
||||
textEdits.push({
|
||||
range: new Range(i, 1, i, originalIndent.length + 1),
|
||||
text: newIndent
|
||||
});
|
||||
if (newIndent !== originalIndent) {
|
||||
textEdits.push({
|
||||
range: new Range(i, 1, i, originalIndent.length + 1),
|
||||
text: newIndent
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue