Skip to content

Commit

Permalink
Add timeout to avoid null activeTextEditor.
Browse files Browse the repository at this point in the history
  • Loading branch information
aioutecism committed Dec 21, 2016
1 parent 9af7e81 commit 198cf85
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions src/Actions/BlockCursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,41 @@ import {window, TextEditorCursorStyle} from 'vscode';
export class ActionBlockCursor {

static on(): Thenable<boolean> {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

// Workaround for VSCode API's bug: https://github.com/Microsoft/vscode/issues/17513
// TODO: Remove next line when the bug is fixed.
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Line;
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Block;

return Promise.resolve(true);
return new Promise((resovle) => {
setTimeout(() => {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

// Workaround for VSCode API's bug: https://github.com/Microsoft/vscode/issues/17513
// TODO: Remove next line when the bug is fixed.
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Underline;
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Block;

resovle(true);
}, 0);
});
}

static off(): Thenable<boolean> {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

// Workaround for VSCode API's bug: https://github.com/Microsoft/vscode/issues/17513
// TODO: Remove next line when the bug is fixed.
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Block;
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Line;

return Promise.resolve(true);
return new Promise((resovle) => {
setTimeout(() => {
const activeTextEditor = window.activeTextEditor;

if (! activeTextEditor) {
return Promise.resolve(false);
}

// Workaround for VSCode API's bug: https://github.com/Microsoft/vscode/issues/17513
// TODO: Remove next line when the bug is fixed.
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Underline;
activeTextEditor.options.cursorStyle = TextEditorCursorStyle.Line;

resovle(true);
}, 0);
});
}

}

0 comments on commit 198cf85

Please sign in to comment.