Skip to content

Commit d41a001

Browse files
committed
Convert Handler to a const enum
1 parent 13194d5 commit d41a001

3 files changed

Lines changed: 21 additions & 26 deletions

File tree

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -663,15 +663,13 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
663663
}
664664

665665
public trigger(source: string | null | undefined, handlerId: string, payload: any): void {
666-
const H = editorCommon.Handler;
667-
668-
if (handlerId === H.CompositionStart) {
666+
if (handlerId === editorCommon.Handler.CompositionStart) {
669667
this._isDoingComposition = true;
670668
this._selectionsWhenCompositionStarted = this.getSelections().slice(0);
671669
return;
672670
}
673671

674-
if (handlerId === H.CompositionEnd) {
672+
if (handlerId === editorCommon.Handler.CompositionEnd) {
675673
this._isDoingComposition = false;
676674
}
677675

@@ -694,32 +692,32 @@ export class Cursor extends viewEvents.ViewEventEmitter implements ICursors {
694692

695693
try {
696694
switch (handlerId) {
697-
case H.Type:
695+
case editorCommon.Handler.Type:
698696
this._type(source, <string>payload.text);
699697
break;
700698

701-
case H.ReplacePreviousChar:
699+
case editorCommon.Handler.ReplacePreviousChar:
702700
this._replacePreviousChar(<string>payload.text, <number>payload.replaceCharCnt);
703701
break;
704702

705-
case H.Paste:
703+
case editorCommon.Handler.Paste:
706704
cursorChangeReason = CursorChangeReason.Paste;
707705
this._paste(<string>payload.text, <boolean>payload.pasteOnNewLine, <string[]>payload.multicursorText || []);
708706
break;
709707

710-
case H.Cut:
708+
case editorCommon.Handler.Cut:
711709
this._cut();
712710
break;
713711

714-
case H.ExecuteCommand:
712+
case editorCommon.Handler.ExecuteCommand:
715713
this._externalExecuteCommand(<editorCommon.ICommand>payload);
716714
break;
717715

718-
case H.ExecuteCommands:
716+
case editorCommon.Handler.ExecuteCommands:
719717
this._externalExecuteCommands(<editorCommon.ICommand[]>payload);
720718
break;
721719

722-
case H.CompositionEnd:
720+
case editorCommon.Handler.CompositionEnd:
723721
this._interpretCompositionEnd(source);
724722
break;
725723
}

src/vs/editor/common/editorCommon.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,13 @@ export const EditorType = {
688688
* Built-in commands.
689689
* @internal
690690
*/
691-
export const Handler = {
692-
ExecuteCommand: 'executeCommand',
693-
ExecuteCommands: 'executeCommands',
694-
695-
Type: 'type',
696-
ReplacePreviousChar: 'replacePreviousChar',
697-
CompositionStart: 'compositionStart',
698-
CompositionEnd: 'compositionEnd',
699-
Paste: 'paste',
700-
Cut: 'cut',
701-
};
691+
export const enum Handler {
692+
ExecuteCommand = 'executeCommand',
693+
ExecuteCommands = 'executeCommands',
694+
Type = 'type',
695+
ReplacePreviousChar = 'replacePreviousChar',
696+
CompositionStart = 'compositionStart',
697+
CompositionEnd = 'compositionEnd',
698+
Paste = 'paste',
699+
Cut = 'cut',
700+
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Position } from 'vs/editor/common/core/position';
1212
import { Range } from 'vs/editor/common/core/range';
1313
import { Selection } from 'vs/editor/common/core/selection';
1414
import { TokenizationResult2 } from 'vs/editor/common/core/token';
15-
import { Handler, ICommand, ICursorStateComputerData, IEditOperationBuilder } from 'vs/editor/common/editorCommon';
15+
import { Handler as H, ICommand, ICursorStateComputerData, IEditOperationBuilder } from 'vs/editor/common/editorCommon';
1616
import { EndOfLinePreference, EndOfLineSequence, ITextModel } from 'vs/editor/common/model';
1717
import { TextModel } from 'vs/editor/common/model/textModel';
1818
import { IState, ITokenizationSupport, LanguageIdentifier, TokenizationRegistry } from 'vs/editor/common/modes';
@@ -24,8 +24,6 @@ import { IRelaxedTextModelCreationOptions, createTextModel } from 'vs/editor/tes
2424
import { MockMode } from 'vs/editor/test/common/mocks/mockMode';
2525
import { javascriptOnEnterRules } from 'vs/editor/test/common/modes/supports/javascriptOnEnterRules';
2626

27-
const H = Handler;
28-
2927
// --------- utils
3028

3129
function cursorCommand(cursor: Cursor, command: string, extraData?: any, overwriteSource?: string) {
@@ -2686,7 +2684,7 @@ suite('Editor Controller - Cursor Configuration', () => {
26862684

26872685
}
26882686

2689-
cursor.trigger('autoFormat', Handler.ExecuteCommand, new TestCommand());
2687+
cursor.trigger('autoFormat', H.ExecuteCommand, new TestCommand());
26902688
assert.equal(model.getLineContent(1), 'function foo(params: string) {');
26912689
assert.equal(model.getLineContent(2), ' ');
26922690
assert.equal(model.getLineContent(3), '}');

0 commit comments

Comments
 (0)