Skip to content

Commit

Permalink
Remove @ts-ignore (#37212)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Nov 8, 2017
1 parent 9095c39 commit 7747dfe
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 248 deletions.
4 changes: 1 addition & 3 deletions src/vs/editor/common/commonCodeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,6 @@ export abstract class CommonCodeEditor extends Disposable implements editorCommo
class EditorContextKeysManager extends Disposable {

private _editor: CommonCodeEditor;
// @ts-ignore unused property
private _editorId: IContextKey<string>;
private _editorFocus: IContextKey<boolean>;
private _editorTextFocus: IContextKey<boolean>;
private _editorTabMovesFocus: IContextKey<boolean>;
Expand All @@ -1053,7 +1051,7 @@ class EditorContextKeysManager extends Disposable {

this._editor = editor;

this._editorId = contextKeyService.createKey('editorId', editor.getId());
contextKeyService.createKey('editorId', editor.getId());
this._editorFocus = EditorContextKeys.focus.bindTo(contextKeyService);
this._editorTextFocus = EditorContextKeys.textFocus.bindTo(contextKeyService);
this._editorTabMovesFocus = EditorContextKeys.tabMovesFocus.bindTo(contextKeyService);
Expand Down
238 changes: 117 additions & 121 deletions src/vs/editor/common/controller/coreCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1650,148 +1650,144 @@ export namespace CoreEditingCommands {
});

}
// @ts-ignore unused namespace
namespace Config {

function findFocusedEditor(accessor: ServicesAccessor): editorCommon.ICommonCodeEditor {
return accessor.get(ICodeEditorService).getFocusedCodeEditor();
}
function findFocusedEditor(accessor: ServicesAccessor): editorCommon.ICommonCodeEditor {
return accessor.get(ICodeEditorService).getFocusedCodeEditor();
}

function getWorkbenchActiveEditor(accessor: ServicesAccessor): editorCommon.ICommonCodeEditor {
const editorService = accessor.get(IEditorService);
let activeEditor = (<any>editorService).getActiveEditor && (<any>editorService).getActiveEditor();
return getCodeEditor(activeEditor);
}
function getWorkbenchActiveEditor(accessor: ServicesAccessor): editorCommon.ICommonCodeEditor {
const editorService = accessor.get(IEditorService);
let activeEditor = (<any>editorService).getActiveEditor && (<any>editorService).getActiveEditor();
return getCodeEditor(activeEditor);
}

function registerCommand(command: Command) {
KeybindingsRegistry.registerCommandAndKeybindingRule(command.toCommandAndKeybindingRule(CORE_WEIGHT));
}
function registerCommand(command: Command) {
KeybindingsRegistry.registerCommandAndKeybindingRule(command.toCommandAndKeybindingRule(CORE_WEIGHT));
}

/**
* A command that will:
* 1. invoke a command on the focused editor.
* 2. otherwise, invoke a browser built-in command on the `activeElement`.
* 3. otherwise, invoke a command on the workbench active editor.
*/
class EditorOrNativeTextInputCommand extends Command {
/**
* A command that will:
* 1. invoke a command on the focused editor.
* 2. otherwise, invoke a browser built-in command on the `activeElement`.
* 3. otherwise, invoke a command on the workbench active editor.
*/
class EditorOrNativeTextInputCommand extends Command {

private readonly _editorHandler: string | EditorCommand;
private readonly _inputHandler: string;

constructor(opts: ICommandOptions & { editorHandler: string | EditorCommand; inputHandler: string; }) {
super(opts);
this._editorHandler = opts.editorHandler;
this._inputHandler = opts.inputHandler;
}

private readonly _editorHandler: string | EditorCommand;
private readonly _inputHandler: string;
public runCommand(accessor: ServicesAccessor, args: any): void {

constructor(opts: ICommandOptions & { editorHandler: string | EditorCommand; inputHandler: string; }) {
super(opts);
this._editorHandler = opts.editorHandler;
this._inputHandler = opts.inputHandler;
let focusedEditor = findFocusedEditor(accessor);
// Only if editor text focus (i.e. not if editor has widget focus).
if (focusedEditor && focusedEditor.isFocused()) {
return this._runEditorHandler(focusedEditor, args);
}

public runCommand(accessor: ServicesAccessor, args: any): void {

let focusedEditor = findFocusedEditor(accessor);
// Only if editor text focus (i.e. not if editor has widget focus).
if (focusedEditor && focusedEditor.isFocused()) {
return this._runEditorHandler(focusedEditor, args);
}

// Ignore this action when user is focused on an element that allows for entering text
let activeElement = <HTMLElement>document.activeElement;
if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) {
document.execCommand(this._inputHandler);
return;
}

// Redirecting to last active editor
let activeEditor = getWorkbenchActiveEditor(accessor);
if (activeEditor) {
activeEditor.focus();
return this._runEditorHandler(activeEditor, args);
}
// Ignore this action when user is focused on an element that allows for entering text
let activeElement = <HTMLElement>document.activeElement;
if (activeElement && ['input', 'textarea'].indexOf(activeElement.tagName.toLowerCase()) >= 0) {
document.execCommand(this._inputHandler);
return;
}

private _runEditorHandler(editor: editorCommon.ICommonCodeEditor, args: any): void {
let HANDLER = this._editorHandler;
if (typeof HANDLER === 'string') {
editor.trigger('keyboard', HANDLER, args);
} else {
args = args || {};
args.source = 'keyboard';
HANDLER.runEditorCommand(null, editor, args);
}
// Redirecting to last active editor
let activeEditor = getWorkbenchActiveEditor(accessor);
if (activeEditor) {
activeEditor.focus();
return this._runEditorHandler(activeEditor, args);
}
}

registerCommand(new EditorOrNativeTextInputCommand({
editorHandler: CoreNavigationCommands.SelectAll,
inputHandler: 'selectAll',
id: 'editor.action.selectAll',
precondition: null,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: null,
primary: KeyMod.CtrlCmd | KeyCode.KEY_A
private _runEditorHandler(editor: editorCommon.ICommonCodeEditor, args: any): void {
let HANDLER = this._editorHandler;
if (typeof HANDLER === 'string') {
editor.trigger('keyboard', HANDLER, args);
} else {
args = args || {};
args.source = 'keyboard';
HANDLER.runEditorCommand(null, editor, args);
}
}));

registerCommand(new EditorOrNativeTextInputCommand({
editorHandler: H.Undo,
inputHandler: 'undo',
id: H.Undo,
precondition: EditorContextKeys.writable,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.textFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_Z
}
}));

registerCommand(new EditorOrNativeTextInputCommand({
editorHandler: H.Redo,
inputHandler: 'redo',
id: H.Redo,
precondition: EditorContextKeys.writable,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.textFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_Y,
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z],
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z }
}
}));
}
}

/**
* A command that will invoke a command on the focused editor.
*/
class EditorHandlerCommand extends Command {
registerCommand(new EditorOrNativeTextInputCommand({
editorHandler: CoreNavigationCommands.SelectAll,
inputHandler: 'selectAll',
id: 'editor.action.selectAll',
precondition: null,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: null,
primary: KeyMod.CtrlCmd | KeyCode.KEY_A
}
}));

registerCommand(new EditorOrNativeTextInputCommand({
editorHandler: H.Undo,
inputHandler: 'undo',
id: H.Undo,
precondition: EditorContextKeys.writable,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.textFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_Z
}
}));

registerCommand(new EditorOrNativeTextInputCommand({
editorHandler: H.Redo,
inputHandler: 'redo',
id: H.Redo,
precondition: EditorContextKeys.writable,
kbOpts: {
weight: CORE_WEIGHT,
kbExpr: EditorContextKeys.textFocus,
primary: KeyMod.CtrlCmd | KeyCode.KEY_Y,
secondary: [KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z],
mac: { primary: KeyMod.CtrlCmd | KeyMod.Shift | KeyCode.KEY_Z }
}
}));

private readonly _handlerId: string;
/**
* A command that will invoke a command on the focused editor.
*/
class EditorHandlerCommand extends Command {

constructor(id: string, handlerId: string) {
super({
id: id,
precondition: null
});
this._handlerId = handlerId;
}
private readonly _handlerId: string;

public runCommand(accessor: ServicesAccessor, args: any): void {
const editor = findFocusedEditor(accessor);
if (!editor) {
return;
}
constructor(id: string, handlerId: string) {
super({
id: id,
precondition: null
});
this._handlerId = handlerId;
}

editor.trigger('keyboard', this._handlerId, args);
public runCommand(accessor: ServicesAccessor, args: any): void {
const editor = findFocusedEditor(accessor);
if (!editor) {
return;
}
}

function registerOverwritableCommand(handlerId: string): void {
registerCommand(new EditorHandlerCommand('default:' + handlerId, handlerId));
registerCommand(new EditorHandlerCommand(handlerId, handlerId));
editor.trigger('keyboard', this._handlerId, args);
}
}

registerOverwritableCommand(H.Type);
registerOverwritableCommand(H.ReplacePreviousChar);
registerOverwritableCommand(H.CompositionStart);
registerOverwritableCommand(H.CompositionEnd);
registerOverwritableCommand(H.Paste);
registerOverwritableCommand(H.Cut);

function registerOverwritableCommand(handlerId: string): void {
registerCommand(new EditorHandlerCommand('default:' + handlerId, handlerId));
registerCommand(new EditorHandlerCommand(handlerId, handlerId));
}

registerOverwritableCommand(H.Type);
registerOverwritableCommand(H.ReplacePreviousChar);
registerOverwritableCommand(H.CompositionStart);
registerOverwritableCommand(H.CompositionEnd);
registerOverwritableCommand(H.Paste);
registerOverwritableCommand(H.Cut);
13 changes: 6 additions & 7 deletions src/vs/editor/common/core/uint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
export class Uint8Matrix {

private _data: Uint8Array;
// @ts-ignore unused property
private _rows: number;
private _cols: number;
public readonly rows: number;
public readonly cols: number;

constructor(rows: number, cols: number, defaultValue: number) {
let data = new Uint8Array(rows * cols);
Expand All @@ -18,16 +17,16 @@ export class Uint8Matrix {
}

this._data = data;
this._rows = rows;
this._cols = cols;
this.rows = rows;
this.cols = cols;
}

public get(row: number, col: number): number {
return this._data[row * this._cols + col];
return this._data[row * this.cols + col];
}

public set(row: number, col: number, value: number): void {
this._data[row * this._cols + col] = value;
this._data[row * this.cols + col] = value;
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/vs/editor/common/modes/languageConfigurationRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ export class RichEditSupport {
empty = false;
onEnter.brackets = conf.brackets;
}
if (conf.indentationRules) {
empty = false;
onEnter.indentationRules = conf.indentationRules;
}
if (conf.onEnterRules) {
empty = false;
onEnter.regExpRules = conf.onEnterRules;
Expand Down
7 changes: 1 addition & 6 deletions src/vs/editor/common/modes/supports/onEnter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

import { onUnexpectedError } from 'vs/base/common/errors';
import * as strings from 'vs/base/common/strings';
import { CharacterPair, IndentationRule, IndentAction, EnterAction, OnEnterRule } from 'vs/editor/common/modes/languageConfiguration';
import { CharacterPair, IndentAction, EnterAction, OnEnterRule } from 'vs/editor/common/modes/languageConfiguration';

export interface IOnEnterSupportOptions {
brackets?: CharacterPair[];
indentationRules?: IndentationRule;
regExpRules?: OnEnterRule[];
}

Expand All @@ -24,8 +23,6 @@ interface IProcessedBracketPair {
export class OnEnterSupport {

private readonly _brackets: IProcessedBracketPair[];
// @ts-ignore unused property
private readonly _indentationRules: IndentationRule;
private readonly _regExpRules: OnEnterRule[];

constructor(opts?: IOnEnterSupportOptions) {
Expand All @@ -45,7 +42,6 @@ export class OnEnterSupport {
};
});
this._regExpRules = opts.regExpRules || [];
this._indentationRules = opts.indentationRules;
}

public onEnter(oneLineAboveText: string, beforeEnterText: string, afterEnterText: string): EnterAction {
Expand Down Expand Up @@ -114,4 +110,3 @@ export class OnEnterSupport {
}
}
}

Loading

0 comments on commit 7747dfe

Please sign in to comment.