mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
Fix #29972. We should not adjust indent on comments.
This commit is contained in:
@@ -300,7 +300,7 @@ class LanguageProvider {
|
|||||||
// ^(.*\*/)?\s*\}.*$
|
// ^(.*\*/)?\s*\}.*$
|
||||||
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
|
decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/,
|
||||||
// ^.*\{[^}"']*$
|
// ^.*\{[^}"']*$
|
||||||
increaseIndentPattern: /^.*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/,
|
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/,
|
||||||
indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/
|
indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/
|
||||||
},
|
},
|
||||||
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
|
||||||
|
|||||||
@@ -2282,7 +2282,7 @@ suite('Editor Controller - Cursor Configuration', () => {
|
|||||||
suite('Editor Controller - Indentation Rules', () => {
|
suite('Editor Controller - Indentation Rules', () => {
|
||||||
let mode = new IndentRulesMode({
|
let mode = new IndentRulesMode({
|
||||||
decreaseIndentPattern: /^\s*((?!\S.*\/[*]).*[*]\/\s*)?[})\]]|^\s*(case\b.*|default):\s*(\/\/.*|\/[*].*[*]\/\s*)?$/,
|
decreaseIndentPattern: /^\s*((?!\S.*\/[*]).*[*]\/\s*)?[})\]]|^\s*(case\b.*|default):\s*(\/\/.*|\/[*].*[*]\/\s*)?$/,
|
||||||
increaseIndentPattern: /(\{[^}"'`]*|\([^)"']*|\[[^\]"']*|^\s*(\{\}|\(\)|\[\]|(case\b.*|default):))\s*(\/\/.*|\/[*].*[*]\/\s*)?$/,
|
increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"']*|\[[^\]"']*|^\s*(\{\}|\(\)|\[\]|(case\b.*|default):))\s*(\/\/.*|\/[*].*[*]\/\s*)?$/,
|
||||||
indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/,
|
indentNextLinePattern: /^\s*(for|while|if|else)\b(?!.*[;{}]\s*(\/\/.*|\/[*].*[*]\/\s*)?$)/,
|
||||||
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*)?$))/
|
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*)?$))/
|
||||||
});
|
});
|
||||||
@@ -3080,6 +3080,26 @@ suite('Editor Controller - Indentation Rules', () => {
|
|||||||
assert.equal(model.getLineContent(2), '\t ) {', 'This line should not decrease indent');
|
assert.equal(model.getLineContent(2), '\t ) {', 'This line should not decrease indent');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('bug 29972: if a line is line comment, open bracket should not indent next line', () => {
|
||||||
|
usingCursor({
|
||||||
|
text: [
|
||||||
|
'if (true) {',
|
||||||
|
'\t// {',
|
||||||
|
'\t\t'
|
||||||
|
],
|
||||||
|
languageIdentifier: mode.getLanguageIdentifier(),
|
||||||
|
modelOpts: { insertSpaces: false, tabSize: 4, detectIndentation: false, defaultEOL: DefaultEndOfLine.LF, trimAutoWhitespace: true },
|
||||||
|
editorOpts: { autoIndent: true }
|
||||||
|
}, (model, cursor) => {
|
||||||
|
moveTo(cursor, 3, 3, false);
|
||||||
|
assertCursor(cursor, new Selection(3, 3, 3, 3));
|
||||||
|
|
||||||
|
cursorCommand(cursor, H.Type, { text: '}' }, 'keyboard');
|
||||||
|
assertCursor(cursor, new Selection(3, 2, 3, 2));
|
||||||
|
assert.equal(model.getLineContent(3), '}');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
interface ICursorOpts {
|
interface ICursorOpts {
|
||||||
|
|||||||
Reference in New Issue
Block a user