Skip to content

Commit 8e562d6

Browse files
committed
More CharCode work & adoption
1 parent 6fee06d commit 8e562d6

10 files changed

Lines changed: 348 additions & 95 deletions

File tree

src/vs/base/common/charCode.ts

Lines changed: 164 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*--------------------------------------------------------------------------------------------*/
55
'use strict';
66

7+
// Names from https://blog.codinghorror.com/ascii-pronunciation-rules-for-programmers/
8+
79
/**
810
* An inlined enum containing useful character codes (to be used with String.charCodeAt).
911
* Please leave the const keyword such that it gets inlined when compiled to JavaScript!
@@ -14,43 +16,200 @@ export const enum CharCode {
1416
LineFeed = 10,
1517
CarriageReturn = 13,
1618
Space = 32,
17-
19+
/**
20+
* The `!` character.
21+
*/
22+
ExclamationMark = 33,
23+
/**
24+
* The `"` character.
25+
*/
26+
DoubleQuote = 34,
27+
/**
28+
* The `#` character.
29+
*/
30+
Hash = 35,
1831
/**
1932
* The `$` character.
2033
*/
21-
Dollar = 36,
22-
34+
DollarSign = 36,
35+
/**
36+
* The `%` character.
37+
*/
38+
PercentSign = 37,
39+
/**
40+
* The `&` character.
41+
*/
42+
Ampersand = 38,
43+
/**
44+
* The `'` character.
45+
*/
46+
SingleQuote = 39,
47+
/**
48+
* The `(` character.
49+
*/
50+
OpenParen = 40,
51+
/**
52+
* The `)` character.
53+
*/
54+
CloseParen = 41,
55+
/**
56+
* The `*` character.
57+
*/
58+
Asterisk = 42,
59+
/**
60+
* The `+` character.
61+
*/
62+
Plus = 43,
63+
/**
64+
* The `,` character.
65+
*/
66+
Comma = 44,
67+
/**
68+
* The `-` character.
69+
*/
70+
Dash = 45,
71+
/**
72+
* The `.` character.
73+
*/
74+
Period = 46,
2375
/**
2476
* The `/` character.
2577
*/
2678
Slash = 47,
2779

2880
Digit0 = 48,
2981
Digit1 = 49,
82+
Digit2 = 50,
83+
Digit3 = 51,
84+
Digit4 = 52,
85+
Digit5 = 53,
86+
Digit6 = 54,
87+
Digit7 = 55,
88+
Digit8 = 56,
3089
Digit9 = 57,
3190

3291
/**
3392
* The `:` character.
3493
*/
3594
Colon = 58,
95+
/**
96+
* The `;` character.
97+
*/
98+
Semicolon = 59,
99+
/**
100+
* The `<` character.
101+
*/
102+
LessThan = 60,
103+
/**
104+
* The `=` character.
105+
*/
106+
Equals = 61,
107+
/**
108+
* The `>` character.
109+
*/
110+
GreaterThan = 62,
111+
/**
112+
* The `?` character.
113+
*/
114+
QuestionMark = 63,
115+
/**
116+
* The `@` character.
117+
*/
118+
AtSign = 64,
36119

37120
A = 65,
121+
B = 66,
122+
C = 67,
123+
D = 68,
124+
E = 69,
125+
F = 70,
126+
G = 71,
127+
H = 72,
128+
I = 73,
129+
J = 74,
130+
K = 75,
131+
L = 76,
132+
M = 77,
133+
N = 78,
134+
O = 79,
135+
P = 80,
136+
Q = 81,
137+
R = 82,
138+
S = 83,
139+
T = 84,
140+
U = 85,
141+
V = 86,
142+
W = 87,
143+
X = 88,
144+
Y = 89,
38145
Z = 90,
39146

147+
/**
148+
* The `[` character.
149+
*/
150+
OpenSquareBracket = 91,
40151
/**
41152
* The `\` character.
42153
*/
43154
Backslash = 92,
44-
155+
/**
156+
* The `]` character.
157+
*/
158+
CloseSquareBracket = 93,
159+
/**
160+
* The `^` character.
161+
*/
162+
Caret = 94,
163+
/**
164+
* The `_` character.
165+
*/
166+
Underline = 95,
45167
/**
46168
* The ``(`)`` character.
47169
*/
48170
BackTick = 96,
49171

50172
a = 97,
173+
b = 98,
174+
c = 99,
175+
d = 100,
176+
e = 101,
177+
f = 102,
178+
g = 103,
179+
h = 104,
180+
i = 105,
181+
j = 106,
182+
k = 107,
183+
l = 108,
184+
m = 109,
51185
n = 110,
186+
o = 111,
187+
p = 112,
188+
q = 113,
189+
r = 114,
190+
s = 115,
52191
t = 116,
192+
u = 117,
193+
v = 118,
194+
w = 119,
195+
x = 120,
196+
y = 121,
53197
z = 122,
54198

55-
199+
/**
200+
* The `{` character.
201+
*/
202+
OpenCurlyBrace = 123,
203+
/**
204+
* The `|` character.
205+
*/
206+
Pipe = 124,
207+
/**
208+
* The `}` character.
209+
*/
210+
CloseCurlyBrace = 125,
211+
/**
212+
* The `~` character.
213+
*/
214+
Tilde = 126,
56215
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
'use strict';
6+
7+
import * as assert from 'assert';
8+
import {CharCode} from 'vs/base/common/charCode';
9+
10+
suite('CharCode', () => {
11+
test('has good values', () => {
12+
13+
function assertValue(actual:CharCode, expected:string): void {
14+
assert.equal(actual, expected.charCodeAt(0), 'char code ok for <<' + expected + '>>');
15+
}
16+
17+
assertValue(CharCode.Tab, '\t');
18+
assertValue(CharCode.LineFeed, '\n');
19+
assertValue(CharCode.CarriageReturn, '\r');
20+
assertValue(CharCode.Space, ' ');
21+
assertValue(CharCode.ExclamationMark, '!');
22+
assertValue(CharCode.DoubleQuote, '"');
23+
assertValue(CharCode.Hash, '#');
24+
assertValue(CharCode.DollarSign, '$');
25+
assertValue(CharCode.PercentSign, '%');
26+
assertValue(CharCode.Ampersand, '&');
27+
assertValue(CharCode.SingleQuote, '\'');
28+
assertValue(CharCode.OpenParen, '(');
29+
assertValue(CharCode.CloseParen, ')');
30+
assertValue(CharCode.Asterisk, '*');
31+
assertValue(CharCode.Plus, '+');
32+
assertValue(CharCode.Comma, ',');
33+
assertValue(CharCode.Dash, '-');
34+
assertValue(CharCode.Period, '.');
35+
assertValue(CharCode.Slash, '/');
36+
37+
assertValue(CharCode.Digit0, '0');
38+
assertValue(CharCode.Digit1, '1');
39+
assertValue(CharCode.Digit2, '2');
40+
assertValue(CharCode.Digit3, '3');
41+
assertValue(CharCode.Digit4, '4');
42+
assertValue(CharCode.Digit5, '5');
43+
assertValue(CharCode.Digit6, '6');
44+
assertValue(CharCode.Digit7, '7');
45+
assertValue(CharCode.Digit8, '8');
46+
assertValue(CharCode.Digit9, '9');
47+
48+
assertValue(CharCode.Colon, ':');
49+
assertValue(CharCode.Semicolon, ';');
50+
assertValue(CharCode.LessThan, '<');
51+
assertValue(CharCode.Equals, '=');
52+
assertValue(CharCode.GreaterThan, '>');
53+
assertValue(CharCode.QuestionMark, '?');
54+
assertValue(CharCode.AtSign, '@');
55+
56+
assertValue(CharCode.A, 'A');
57+
assertValue(CharCode.B, 'B');
58+
assertValue(CharCode.C, 'C');
59+
assertValue(CharCode.D, 'D');
60+
assertValue(CharCode.E, 'E');
61+
assertValue(CharCode.F, 'F');
62+
assertValue(CharCode.G, 'G');
63+
assertValue(CharCode.H, 'H');
64+
assertValue(CharCode.I, 'I');
65+
assertValue(CharCode.J, 'J');
66+
assertValue(CharCode.K, 'K');
67+
assertValue(CharCode.L, 'L');
68+
assertValue(CharCode.M, 'M');
69+
assertValue(CharCode.N, 'N');
70+
assertValue(CharCode.O, 'O');
71+
assertValue(CharCode.P, 'P');
72+
assertValue(CharCode.Q, 'Q');
73+
assertValue(CharCode.R, 'R');
74+
assertValue(CharCode.S, 'S');
75+
assertValue(CharCode.T, 'T');
76+
assertValue(CharCode.U, 'U');
77+
assertValue(CharCode.V, 'V');
78+
assertValue(CharCode.W, 'W');
79+
assertValue(CharCode.X, 'X');
80+
assertValue(CharCode.Y, 'Y');
81+
assertValue(CharCode.Z, 'Z');
82+
83+
assertValue(CharCode.OpenSquareBracket, '[');
84+
assertValue(CharCode.Backslash, '\\');
85+
assertValue(CharCode.CloseSquareBracket, ']');
86+
assertValue(CharCode.Caret, '^');
87+
assertValue(CharCode.Underline, '_');
88+
assertValue(CharCode.BackTick, '`');
89+
90+
assertValue(CharCode.a, 'a');
91+
assertValue(CharCode.b, 'b');
92+
assertValue(CharCode.c, 'c');
93+
assertValue(CharCode.d, 'd');
94+
assertValue(CharCode.e, 'e');
95+
assertValue(CharCode.f, 'f');
96+
assertValue(CharCode.g, 'g');
97+
assertValue(CharCode.h, 'h');
98+
assertValue(CharCode.i, 'i');
99+
assertValue(CharCode.j, 'j');
100+
assertValue(CharCode.k, 'k');
101+
assertValue(CharCode.l, 'l');
102+
assertValue(CharCode.m, 'm');
103+
assertValue(CharCode.n, 'n');
104+
assertValue(CharCode.o, 'o');
105+
assertValue(CharCode.p, 'p');
106+
assertValue(CharCode.q, 'q');
107+
assertValue(CharCode.r, 'r');
108+
assertValue(CharCode.s, 's');
109+
assertValue(CharCode.t, 't');
110+
assertValue(CharCode.u, 'u');
111+
assertValue(CharCode.v, 'v');
112+
assertValue(CharCode.w, 'w');
113+
assertValue(CharCode.x, 'x');
114+
assertValue(CharCode.y, 'y');
115+
assertValue(CharCode.z, 'z');
116+
117+
assertValue(CharCode.OpenCurlyBrace, '{');
118+
assertValue(CharCode.Pipe, '|');
119+
assertValue(CharCode.CloseCurlyBrace, '}');
120+
assertValue(CharCode.Tilde, '~');
121+
});
122+
});

src/vs/editor/common/commands/shiftCommand.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {Range} from 'vs/editor/common/core/range';
1010
import {Selection} from 'vs/editor/common/core/selection';
1111
import {ICommand, ICursorStateComputerData, IEditOperationBuilder, ITokenizedModel} from 'vs/editor/common/editorCommon';
1212
import {LanguageConfigurationRegistry} from 'vs/editor/common/modes/languageConfigurationRegistry';
13+
import {CharCode} from 'vs/base/common/charCode';
1314

1415
export interface IShiftCommandOpts {
1516
isUnshift: boolean;
@@ -53,7 +54,6 @@ export class ShiftCommand implements ICommand {
5354
public getEditOperations(model: ITokenizedModel, builder: IEditOperationBuilder): void {
5455
let startLine = this._selection.startLineNumber;
5556
let endLine = this._selection.endLineNumber;
56-
let _SPACE = ' '.charCodeAt(0);
5757

5858
if (this._selection.endColumn === 1 && startLine !== endLine) {
5959
endLine = endLine - 1;
@@ -106,7 +106,7 @@ export class ShiftCommand implements ICommand {
106106
extraSpaces = previousLineExtraSpaces;
107107
if (enterAction.appendText) {
108108
for (let j = 0, lenJ = enterAction.appendText.length; j < lenJ && extraSpaces < tabSize; j++) {
109-
if (enterAction.appendText.charCodeAt(j) === _SPACE) {
109+
if (enterAction.appendText.charCodeAt(j) === CharCode.Space) {
110110
extraSpaces++;
111111
} else {
112112
break;
@@ -119,7 +119,7 @@ export class ShiftCommand implements ICommand {
119119

120120
// Act as if `prefixSpaces` is not part of the indentation
121121
for (let j = 0; j < extraSpaces; j++) {
122-
if (indentationEndIndex === 0 || lineText.charCodeAt(indentationEndIndex - 1) !== _SPACE) {
122+
if (indentationEndIndex === 0 || lineText.charCodeAt(indentationEndIndex - 1) !== CharCode.Space) {
123123
break;
124124
}
125125
indentationEndIndex--;

src/vs/editor/common/controller/cursorMoveHelper.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export interface IConfiguration {
5050
getIndentationOptions(): IInternalIndentationOptions;
5151
}
5252

53-
function isHighSurrogate(model, lineNumber, column) {
54-
var code = model.getLineContent(lineNumber).charCodeAt(column - 1);
53+
function isHighSurrogate(model:ICursorMoveHelperModel, lineNumber:number, column:number) {
54+
let code = model.getLineContent(lineNumber).charCodeAt(column - 1);
5555
return 0xD800 <= code && code <= 0xDBFF;
5656
}
5757

58-
function isLowSurrogate(model, lineNumber, column) {
59-
var code = model.getLineContent(lineNumber).charCodeAt(column - 1);
58+
function isLowSurrogate(model:ICursorMoveHelperModel, lineNumber:number, column:number) {
59+
let code = model.getLineContent(lineNumber).charCodeAt(column - 1);
6060
return 0xDC00 <= code && code <= 0xDFFF;
6161
}
6262

0 commit comments

Comments
 (0)