hterm: pause cursor blinking while the user is typing
Whenever we see a keystroke from the user, we should pause the cursor
blinking momentarily. This is a common behavior in other terminals,
and it helps when typing a lot, or moving the cursor around with the
arrow keys.
Bug: chromium:773092
Change-Id: I2a963ed9195cd7325c27024b6add688ca1ea6ace
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/1870832
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/hterm/js/hterm_terminal.js b/hterm/js/hterm_terminal.js
index 9477256..320dab1 100644
--- a/hterm/js/hterm_terminal.js
+++ b/hterm/js/hterm_terminal.js
@@ -85,6 +85,9 @@
// Cursor blink on/off cycle in ms, overwritten by prefs once they're loaded.
this.cursorBlinkCycle_ = [100, 100];
+ // Whether to temporarily disable blinking.
+ this.cursorBlinkPause_ = false;
+
// Pre-bound onCursorBlink_ handler, so we don't have to do this for each
// cursor on/off servicing.
this.myOnCursorBlink_ = this.onCursorBlink_.bind(this);
@@ -2834,6 +2837,32 @@
};
/**
+ * Pause blinking temporarily.
+ *
+ * When the cursor moves around, it can be helpful to momentarily pause the
+ * blinking. This could be when the user is typing in things, or when they're
+ * moving around with the arrow keys.
+ */
+hterm.Terminal.prototype.pauseCursorBlink_ = function() {
+ if (!this.options_.cursorBlink) {
+ return;
+ }
+
+ this.cursorBlinkPause_ = true;
+
+ // If a timeout is already pending, reset the clock due to the new input.
+ if (this.timeouts_.cursorBlinkPause) {
+ clearTimeout(this.timeouts_.cursorBlinkPause);
+ }
+ // After 500ms, resume blinking. That seems like a good balance between user
+ // input timings & responsiveness to resume.
+ this.timeouts_.cursorBlinkPause = setTimeout(() => {
+ delete this.timeouts_.cursorBlinkPause;
+ this.cursorBlinkPause_ = false;
+ }, 500);
+};
+
+/**
* Synchronizes the visible cursor and document selection with the current
* cursor coordinates.
*
@@ -3442,6 +3471,8 @@
if (this.scrollOnKeystroke_)
this.scrollPort_.scrollRowToBottom(this.getRowCount());
+ this.pauseCursorBlink_();
+
this.io.onVTKeystroke(string);
};
@@ -3812,7 +3843,8 @@
}
if (this.cursorNode_.getAttribute('focus') == 'false' ||
- this.cursorNode_.style.opacity == '0') {
+ this.cursorNode_.style.opacity == '0' ||
+ this.cursorBlinkPause_) {
this.cursorNode_.style.opacity = '1';
this.timeouts_.cursorBlink = setTimeout(this.myOnCursorBlink_,
this.cursorBlinkCycle_[0]);