Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandru Dima <alexdima@microsoft.com>2022-05-10 17:18:43 +0300
committerGitHub <noreply@github.com>2022-05-10 17:18:43 +0300
commit9a1e8d12fb12c8c5b659fb65292675d165bfa1f3 (patch)
tree826ebbf0e1060b7528b316d9e7332758925b7761
parentae7d4f417abb6d7b72b52df1f73bce9a8adef9ae (diff)
Fixes #148256: `\t` should jump to next indent tab stop and not just add the tab width (#149164)
-rw-r--r--src/vs/editor/common/core/indentation.ts3
-rw-r--r--src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts2
-rw-r--r--src/vs/editor/test/browser/controller/cursor.test.ts27
-rw-r--r--src/vs/editor/test/common/model/textModel.test.ts27
4 files changed, 45 insertions, 14 deletions
diff --git a/src/vs/editor/common/core/indentation.ts b/src/vs/editor/common/core/indentation.ts
index 0134b97c376..d4cd6d0e71a 100644
--- a/src/vs/editor/common/core/indentation.ts
+++ b/src/vs/editor/common/core/indentation.ts
@@ -4,12 +4,13 @@
*--------------------------------------------------------------------------------------------*/
import * as strings from 'vs/base/common/strings';
+import { CursorColumns } from 'vs/editor/common/core/cursorColumns';
function _normalizeIndentationFromWhitespace(str: string, indentSize: number, insertSpaces: boolean): string {
let spacesCnt = 0;
for (let i = 0; i < str.length; i++) {
if (str.charAt(i) === '\t') {
- spacesCnt += indentSize;
+ spacesCnt = CursorColumns.nextIndentTabStop(spacesCnt, indentSize);
} else {
spacesCnt++;
}
diff --git a/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts b/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts
index 0c2f31c225b..7ce812e34ee 100644
--- a/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts
+++ b/src/vs/editor/contrib/snippet/test/browser/snippetSession.test.ts
@@ -63,7 +63,7 @@ suite('SnippetSession', function () {
assertNormalized(new Position(1, 1), 'foo\rbar', 'foo\nbar');
assertNormalized(new Position(1, 1), 'foo\rbar', 'foo\nbar');
assertNormalized(new Position(2, 5), 'foo\r\tbar', 'foo\n bar');
- assertNormalized(new Position(2, 3), 'foo\r\tbar', 'foo\n bar');
+ assertNormalized(new Position(2, 3), 'foo\r\tbar', 'foo\n bar');
assertNormalized(new Position(2, 5), 'foo\r\tbar\nfoo', 'foo\n bar\n foo');
//Indentation issue with choice elements that span multiple lines #46266
diff --git a/src/vs/editor/test/browser/controller/cursor.test.ts b/src/vs/editor/test/browser/controller/cursor.test.ts
index 3f8f9fc7786..745e7388b60 100644
--- a/src/vs/editor/test/browser/controller/cursor.test.ts
+++ b/src/vs/editor/test/browser/controller/cursor.test.ts
@@ -3225,6 +3225,33 @@ suite('Editor Controller', () => {
});
});
+ test('issue #148256: Pressing Enter creates line with bad indent with insertSpaces: true', () => {
+ usingCursor({
+ text: [
+ ' \t'
+ ],
+ }, (editor, model, viewModel) => {
+ moveTo(editor, viewModel, 1, 4, false);
+ viewModel.type('\n', 'keyboard');
+ assert.strictEqual(model.getValue(), ' \t\n ');
+ });
+ });
+
+ test('issue #148256: Pressing Enter creates line with bad indent with insertSpaces: false', () => {
+ usingCursor({
+ text: [
+ ' \t'
+ ]
+ }, (editor, model, viewModel) => {
+ model.updateOptions({
+ insertSpaces: false
+ });
+ moveTo(editor, viewModel, 1, 4, false);
+ viewModel.type('\n', 'keyboard');
+ assert.strictEqual(model.getValue(), ' \t\n\t');
+ });
+ });
+
test('removeAutoWhitespace off', () => {
usingCursor({
text: [
diff --git a/src/vs/editor/test/common/model/textModel.test.ts b/src/vs/editor/test/common/model/textModel.test.ts
index b1ebbf29c20..3cf9ae5c028 100644
--- a/src/vs/editor/test/common/model/textModel.test.ts
+++ b/src/vs/editor/test/common/model/textModel.test.ts
@@ -915,10 +915,11 @@ suite('Editor Model - TextModel', () => {
assert.strictEqual(model.normalizeIndentation(' '), ' ');
assert.strictEqual(model.normalizeIndentation(' '), ' ');
assert.strictEqual(model.normalizeIndentation(''), '');
- assert.strictEqual(model.normalizeIndentation(' \t '), '\t\t');
- assert.strictEqual(model.normalizeIndentation(' \t '), '\t ');
- assert.strictEqual(model.normalizeIndentation(' \t '), '\t ');
- assert.strictEqual(model.normalizeIndentation(' \t'), '\t ');
+ assert.strictEqual(model.normalizeIndentation(' \t '), '\t\t');
+ assert.strictEqual(model.normalizeIndentation(' \t '), '\t ');
+ assert.strictEqual(model.normalizeIndentation(' \t '), '\t ');
+ assert.strictEqual(model.normalizeIndentation(' \t '), '\t ');
+ assert.strictEqual(model.normalizeIndentation(' \t'), '\t');
assert.strictEqual(model.normalizeIndentation('\ta'), '\ta');
assert.strictEqual(model.normalizeIndentation(' a'), '\ta');
@@ -926,10 +927,11 @@ suite('Editor Model - TextModel', () => {
assert.strictEqual(model.normalizeIndentation(' a'), ' a');
assert.strictEqual(model.normalizeIndentation(' a'), ' a');
assert.strictEqual(model.normalizeIndentation('a'), 'a');
- assert.strictEqual(model.normalizeIndentation(' \t a'), '\t\ta');
- assert.strictEqual(model.normalizeIndentation(' \t a'), '\t a');
- assert.strictEqual(model.normalizeIndentation(' \t a'), '\t a');
- assert.strictEqual(model.normalizeIndentation(' \ta'), '\t a');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), '\t\ta');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), '\t a');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), '\t a');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), '\t a');
+ assert.strictEqual(model.normalizeIndentation(' \ta'), '\ta');
model.dispose();
});
@@ -943,10 +945,11 @@ suite('Editor Model - TextModel', () => {
assert.strictEqual(model.normalizeIndentation(' a'), ' a');
assert.strictEqual(model.normalizeIndentation(' a'), ' a');
assert.strictEqual(model.normalizeIndentation('a'), 'a');
- assert.strictEqual(model.normalizeIndentation(' \t a'), ' a');
- assert.strictEqual(model.normalizeIndentation(' \t a'), ' a');
- assert.strictEqual(model.normalizeIndentation(' \t a'), ' a');
- assert.strictEqual(model.normalizeIndentation(' \ta'), ' a');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), ' a');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), ' a');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), ' a');
+ assert.strictEqual(model.normalizeIndentation(' \t a'), ' a');
+ assert.strictEqual(model.normalizeIndentation(' \ta'), ' a');
model.dispose();
});