Skip to content

Commit

Permalink
Mitigate microsoft#22900. Use setInterval instead of animation for bl…
Browse files Browse the repository at this point in the history
…inking on mac and linux.
  • Loading branch information
rebornix committed Mar 23, 2017
1 parent 209f12a commit 99a6160
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Expand Up @@ -81,7 +81,7 @@
}
}

.cursor-blink {
.windows .cursor-blink {
animation: monaco-cursor-blink 1s step-start 0s infinite;
}

Expand Down
29 changes: 24 additions & 5 deletions src/vs/editor/browser/viewParts/viewCursors/viewCursors.ts
Expand Up @@ -7,14 +7,15 @@

import 'vs/css!./viewCursors';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { isWindows } from 'vs/base/common/platform';
import { ClassNames } from 'vs/editor/browser/editorBrowser';
import { ViewPart } from 'vs/editor/browser/view/viewPart';
import { Position } from 'vs/editor/common/core/position';
import { IViewCursorRenderData, ViewCursor } from 'vs/editor/browser/viewParts/viewCursors/viewCursor';
import { ViewContext } from 'vs/editor/common/view/viewContext';
import { RenderingContext, RestrictedRenderingContext } from 'vs/editor/common/view/renderingContext';
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
import { TimeoutTimer } from 'vs/base/common/async';
import { TimeoutTimer, IntervalTimer } from 'vs/base/common/async';
import * as viewEvents from 'vs/editor/common/view/viewEvents';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { editorCursor } from 'vs/editor/common/view/editorColorRegistry';
Expand All @@ -33,6 +34,7 @@ export class ViewCursors extends ViewPart {
private _domNode: FastDomNode<HTMLElement>;

private _startCursorBlinkAnimation: TimeoutTimer;
private _cursorFlatBlinkInterval: IntervalTimer;
private _blinkingEnabled: boolean;

private _editorHasFocus: boolean;
Expand All @@ -59,6 +61,8 @@ export class ViewCursors extends ViewPart {
this._domNode.domNode.appendChild(this._primaryCursor.getDomNode());

this._startCursorBlinkAnimation = new TimeoutTimer();
this._cursorFlatBlinkInterval = new IntervalTimer();

this._blinkingEnabled = false;

this._editorHasFocus = false;
Expand All @@ -68,6 +72,7 @@ export class ViewCursors extends ViewPart {
public dispose(): void {
super.dispose();
this._startCursorBlinkAnimation.dispose();
this._cursorFlatBlinkInterval.dispose();
}

public getDomNode(): HTMLElement {
Expand Down Expand Up @@ -206,13 +211,17 @@ export class ViewCursors extends ViewPart {

private _updateBlinking(): void {
this._startCursorBlinkAnimation.cancel();
this._cursorFlatBlinkInterval.cancel();

let blinkingStyle = this._getCursorBlinking();

// hidden and solid are special as they involve no animations
let isHidden = (blinkingStyle === editorCommon.TextEditorCursorBlinkingStyle.Hidden);
let isSolid = (blinkingStyle === editorCommon.TextEditorCursorBlinkingStyle.Solid);

// flat blinking is handled by JavaScript on Mac and Linux to save battery life due to Chromium step timing issue https://bugs.chromium.org/p/chromium/issues/detail?id=361587
let isFlatBlinkingOnInx = (blinkingStyle === editorCommon.TextEditorCursorBlinkingStyle.Blink) && !isWindows;

if (isHidden) {
this._hide();
} else {
Expand All @@ -223,10 +232,20 @@ export class ViewCursors extends ViewPart {
this._updateDomClassName();

if (!isHidden && !isSolid) {
this._startCursorBlinkAnimation.setIfNotSet(() => {
this._blinkingEnabled = true;
this._updateDomClassName();
}, ViewCursors.BLINK_INTERVAL);
if (isFlatBlinkingOnInx) {
this._cursorFlatBlinkInterval.cancelAndSet(() => {
if (this._isVisible) {
this._hide();
} else {
this._show();
}
}, ViewCursors.BLINK_INTERVAL);
} else {
this._startCursorBlinkAnimation.setIfNotSet(() => {
this._blinkingEnabled = true;
this._updateDomClassName();
}, ViewCursors.BLINK_INTERVAL);
}
}
}
// --- end blinking logic
Expand Down

0 comments on commit 99a6160

Please sign in to comment.