/**
* Focus the terminal. Delegates focus handling to the terminal's DOM element.
- *
- * @public
*/
Terminal.prototype.focus = function() {
- return this.element.focus();
+ if (document.activeElement === this.textarea) {
+ return;
+ }
+
+ if (this.sendFocus) {
+ this.send('\x1b[I');
+ }
+
+ this.element.classList.add('focus');
+ this.showCursor();
+ this.textarea.focus();
+ Terminal.focus = this;
};
/**
/**
* Blur the terminal. Delegates blur handling to the terminal's DOM element.
- *
- * @public
*/
Terminal.prototype.blur = function() {
- return this.element.blur();
+ if (Terminal.focus !== this) {
+ return;
+ }
+
+ this.element.classList.remove('focus');
+ this.cursorState = 0;
+ this.refresh(this.y, this.y);
+ this.textarea.blur();
+ if (this.sendFocus) {
+ this.send('\x1b[0]');
+ }
+ Terminal.focus = null;
};
/**
this.write(data + '\r\n');
};
- // Key Resources:
- // https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
+ /**
+ * Handle a keydown event
+ * Key Resources:
+ * - https://developer.mozilla.org/en-US/docs/DOM/KeyboardEvent
+ * @param {KeyboardEvent} ev The keydown event to be handled.
+ */
Terminal.prototype.keyDown = function(ev) {
+ // TODO: Ignore event if currently composing text
+
var self = this;
var result = this.evaluateKeyEscapeSequence(ev);