mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Merge pull request #167687 from ssigwart/tabWithEnter
Fix paste removing indent
This commit is contained in:
commit
a18f1c39ea
|
@ -93,6 +93,19 @@ export function getInheritIndentForLine(
|
|||
};
|
||||
}
|
||||
|
||||
// Use no indent if this is the first non-blank line
|
||||
for (let priorLineNumber = lineNumber - 1; priorLineNumber > 0; priorLineNumber--) {
|
||||
if (model.getLineContent(priorLineNumber) !== '') {
|
||||
break;
|
||||
}
|
||||
if (priorLineNumber === 1) {
|
||||
return {
|
||||
indentation: '',
|
||||
action: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const precedingUnIgnoredLine = getPrecedingValidLine(model, lineNumber, indentRulesSupport);
|
||||
if (precedingUnIgnoredLine < 0) {
|
||||
return null;
|
||||
|
|
|
@ -265,3 +265,54 @@ suite('Editor Contrib - Auto Indent On Paste', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('Editor Contrib - Keep Indent On Paste', () => {
|
||||
let disposables: DisposableStore;
|
||||
|
||||
setup(() => {
|
||||
disposables = new DisposableStore();
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
disposables.dispose();
|
||||
});
|
||||
|
||||
test('issue #167299: Blank line removes indent', () => {
|
||||
const languageId = 'blankLineRemovesIndent';
|
||||
const model = createTextModel("", languageId, {});
|
||||
disposables.add(model);
|
||||
withTestCodeEditor(model, { autoIndent: 'full' }, (editor, viewModel, instantiationService) => {
|
||||
const languageService = instantiationService.get(ILanguageService);
|
||||
const languageConfigurationService = instantiationService.get(ILanguageConfigurationService);
|
||||
disposables.add(languageService.registerLanguage({ id: languageId }));
|
||||
disposables.add(languageConfigurationService.register(languageId, {
|
||||
brackets: [
|
||||
['{', '}'],
|
||||
['[', ']'],
|
||||
['(', ')']
|
||||
],
|
||||
indentationRules: javascriptIndentationRules,
|
||||
onEnterRules: javascriptOnEnterRules
|
||||
}));
|
||||
|
||||
const autoIndentOnPasteController = editor.registerAndInstantiateContribution(AutoIndentOnPaste.ID, AutoIndentOnPaste);
|
||||
const pasteText = [
|
||||
'',
|
||||
'export type IncludeReference =',
|
||||
' | BaseReference',
|
||||
' | SelfReference',
|
||||
' | RelativeReference;',
|
||||
'',
|
||||
'export const enum IncludeReferenceKind {',
|
||||
' Base,',
|
||||
' Self,',
|
||||
' RelativeReference,',
|
||||
'}'
|
||||
].join('\n');
|
||||
|
||||
viewModel.paste(pasteText, true, undefined, 'keyboard');
|
||||
autoIndentOnPasteController.trigger(new Range(1, 1, 11, 2));
|
||||
assert.strictEqual(model.getValue(), pasteText);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue