Skip to content

Commit ed20f81

Browse files
committed
Fix microsoft#29972. We should not adjust indent on comments.
1 parent 5c34f3f commit ed20f81

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

extensions/typescript/src/typescriptMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ class LanguageProvider {
300300
// ^(.*\*/)?\s*\}.*$
301301
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
302302
// ^.*\{[^}"']*$
303-
increaseIndentPattern: /^.*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/,
303+
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/,
304304
indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/
305305
},
306306
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,

src/vs/editor/test/common/controller/cursor.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ suite('Editor Controller - Cursor Configuration', () => {
22822282
suite('Editor Controller - Indentation Rules', () => {
22832283
let mode = new IndentRulesMode({
22842284
decreaseIndentPattern: /^\s*((?!\S.*\/[*]).*[*]\/\s*)?[})\]]|^\s*(case\b.*|default):\s*(\/\/.*|\/[*].*[*]\/\s*)?$/,
2285-
increaseIndentPattern: /(\{[^}"'`]*|\([^)"']*|\[[^\]"']*|^\s*(\{\}|\(\)|\[\]|(case\b.*|default):))\s*(\/\/.*|\/[*].*[*]\/\s*)?$/,
2285+
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"']*|\[[^\]"']*|^\s*(\{\}|\(\)|\[\]|(case\b.*|default):))\s*(\/\/.*|\/[*].*[*]\/\s*)?$/,
22862286
indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/,
22872287
unIndentedLinePattern: /^(?!.*([;{}]|\S:)\s*(\/\/.*|\/[*].*[*]\/\s*)?$)(?!.*(\{[^}"']*|\([^)"']*|\[[^\]"']*|^\s*(\{\}|\(\)|\[\]|(case\b.*|default):))\s*(\/\/.*|\/[*].*[*]\/\s*)?$)(?!^\s*((?!\S.*\/[*]).*[*]\/\s*)?[})\]]|^\s*(case\b.*|default):\s*(\/\/.*|\/[*].*[*]\/\s*)?$)(?!^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$))/
22882288
});
@@ -3080,6 +3080,26 @@ suite('Editor Controller - Indentation Rules', () => {
30803080
assert.equal(model.getLineContent(2), '\t ) {', 'This line should not decrease indent');
30813081
});
30823082
});
3083+
3084+
test('bug 29972: if a line is line comment, open bracket should not indent next line', () => {
3085+
usingCursor({
3086+
text: [
3087+
'if (true) {',
3088+
'\t// {',
3089+
'\t\t'
3090+
],
3091+
languageIdentifier: mode.getLanguageIdentifier(),
3092+
modelOpts: { insertSpaces: false, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true },
3093+
editorOpts: { autoIndent: true }
3094+
}, (model, cursor) => {
3095+
moveTo(cursor, 3, 3, false);
3096+
assertCursor(cursor, new Selection(3, 3, 3, 3));
3097+
3098+
cursorCommand(cursor, H.Type, { text: '}' }, 'keyboard');
3099+
assertCursor(cursor, new Selection(3, 2, 3, 2));
3100+
assert.equal(model.getLineContent(3), '}');
3101+
});
3102+
});
30833103
});
30843104

30853105
interface ICursorOpts {

0 commit comments

Comments
 (0)