提交 6ea6f1cb 编写于 作者: R rebornix

Fix #30858. Honor users intential indent when type

上级 0ba48366
......@@ -618,7 +618,9 @@ export class LanguageConfigurationRegistryImpl {
afterTypeText = endScopedLineTokens.getLineContent().substr(range.endColumn - 1 - scopedLineTokens.firstCharOffset);
}
if (indentRulesSupport.shouldDecrease(beforeTypeText + ch + afterTypeText)) {
// If previous content already matches decreaseIndentPattern, it means indentation of this line should already be adjusted
// Users might change the indentation by purpose and we should honor that instead of readjusting.
if (!indentRulesSupport.shouldDecrease(beforeTypeText + afterTypeText) && indentRulesSupport.shouldDecrease(beforeTypeText + ch + afterTypeText)) {
// after typing `ch`, the content matches decreaseIndentPattern, we should adjust the indent to a good manner.
// 1. Get inherited indent action
let r = this.getInheritIndentForLine(model, range.startLineNumber, false);
......
......@@ -3022,6 +3022,28 @@ suite('Editor Controller - Indentation Rules', () => {
assert.equal(model.getLineContent(5), '\t}e', 'This line should not decrease indent');
});
});
test('type honors users indentation adjustment', () => {
usingCursor({
text: [
'\tif (true ||',
'\t ) {',
'\t}',
'if (true ||',
') {',
'}'
],
languageIdentifier: mode.getLanguageIdentifier(),
modelOpts: { insertSpaces: false, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true }
}, (model, cursor) => {
moveTo(cursor, 2, 3, false);
assertCursor(cursor, new Selection(2, 3, 2, 3));
cursorCommand(cursor, H.Type, { text: ' ' }, 'keyboard');
assertCursor(cursor, new Selection(2, 4, 2, 4));
assert.equal(model.getLineContent(2), '\t ) {', 'This line should not decrease indent');
});
});
});
interface ICursorOpts {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册