Skip to content

Commit

Permalink
Merge pull request #645 from sourcelair/issue-#640-do-not-focus-on-open
Browse files Browse the repository at this point in the history
Add `focus` argument in `Terminal.prototype.open`
  • Loading branch information
parisk committed Apr 30, 2017
2 parents 944da28 + 35f746c commit 66f6b88
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,9 @@ Terminal.prototype.insertRow = function (row) {
* Opens the terminal within an element.
*
* @param {HTMLElement} parent The element to create the terminal within.
* @param {boolean} focus Focus the terminal, after it gets instantiated in the DOM
*/
Terminal.prototype.open = function(parent) {
Terminal.prototype.open = function(parent, focus) {
var self=this, i=0, div;

this.parent = parent || this.parent;
Expand All @@ -629,7 +630,7 @@ Terminal.prototype.open = function(parent) {
this.element.classList.add('xterm-theme-' + this.theme);
this.setCursorBlinking(this.options.cursorBlink);

this.element.style.height
this.element.style.height;
this.element.setAttribute('tabindex', 0);

this.viewportElement = document.createElement('div');
Expand Down Expand Up @@ -696,8 +697,23 @@ Terminal.prototype.open = function(parent) {
// need to be taken on the document.
this.initGlobal();

// Ensure there is a Terminal.focus.
this.focus();
/**
* Automatic focus functionality.
* TODO: Default to `false` starting with xterm.js 3.0.
*/
if (typeof focus == 'undefined') {
let message = 'You did not pass the `focus` argument in `Terminal.prototype.open()`.\n';

message += 'The `focus` argument now defaults to `true` but starting with xterm.js 3.0 ';
message += 'it will default to `false`.';

console.warn(message);
focus = true;
}

if (focus) {
this.focus();
}

on(this.element, 'click', function() {
var selection = document.getSelection(),
Expand Down

0 comments on commit 66f6b88

Please sign in to comment.