]> git.proxmox.com Git - mirror_xterm.js.git/blobdiff - src/xterm.js
Merge changes from #828
[mirror_xterm.js.git] / src / xterm.js
index d1406ccbe102cc2c383d28fda6bf6d964a09ee49..5aa069e796c688b291265b60ae1d1920291a772c 100644 (file)
@@ -146,13 +146,7 @@ function Terminal(options) {
   this.cursorHidden = false;
   this.convertEol;
   this.queue = '';
-<<<<<<< HEAD
-  this.scrollTop = 0;
-  this.scrollBottom = this.rows - 1;
   this.customKeyEventHandler = null;
-=======
-  this.customKeydownHandler = null;
->>>>>>> Move `scrollTop` and `scrollBottom` into `Buffer`
   this.cursorBlinkInterval = null;
 
   // modes
@@ -161,7 +155,6 @@ function Terminal(options) {
   this.originMode = false;
   this.insertMode = false;
   this.wraparoundMode = true; // defaults: xterm - true, vt100 - false
-  this.normal = null;
 
   // charset
   this.charset = null;
@@ -231,13 +224,9 @@ function Terminal(options) {
   this.buffers = new BufferSet(this);
   this.buffer = this.buffers.active;  // Convenience shortcut;
   this.buffers.on('activate', function (buffer) {
-    this.buffer = buffer;
+    this._terminal.buffer = buffer;
   });
 
-  /**
-   * An array of all lines in the entire buffer, including the prompt. The lines are array of
-   * characters which are 2-length arrays where [0] is an attribute and [1] is the character.
-   */
   var i = this.rows;
 
   while (i--) {
@@ -420,7 +409,7 @@ Terminal.prototype.setOption = function(key, value) {
       }
 
       if (this.options[key] !== value) {
-        if (this.buffer.length > value) {
+        if (this.buffer.lines.length > value) {
           const amountToTrim = this.buffer.lines.length - value;
           const needsRefresh = (this.buffer.ydisp - amountToTrim < 0);
           this.buffer.lines.trimStart(amountToTrim);
@@ -440,7 +429,7 @@ Terminal.prototype.setOption = function(key, value) {
   switch (key) {
     case 'cursorBlink': this.setCursorBlinking(value); break;
     case 'cursorStyle':
-      // Style 'block' applies with no class
+      this.element.classList.toggle(`xterm-cursor-style-block`, value === 'block');
       this.element.classList.toggle(`xterm-cursor-style-underline`, value === 'underline');
       this.element.classList.toggle(`xterm-cursor-style-bar`, value === 'bar');
       break;
@@ -503,7 +492,7 @@ Terminal.prototype.blur = function() {
  */
 Terminal.bindBlur = function (term) {
   on(term.textarea, 'blur', function (ev) {
-    term.refresh(term.y, term.y);
+    term.refresh(term.buffer.y, term.buffer.y);
     if (term.sendFocus) {
       term.send(C0.ESC + '[O');
     }
@@ -528,7 +517,7 @@ Terminal.prototype.initGlobal = function() {
   on(this.element, 'copy', event => {
     // If mouse events are active it means the selection manager is disabled and
     // copy should be handled by the host program.
-    if (this.mouseEvents) {
+    if (!term.hasSelection()) {
       return;
     }
     copyHandler(event, term, this.selectionManager);
@@ -650,6 +639,7 @@ Terminal.prototype.open = function(parent, focus) {
   this.element.classList.add('terminal');
   this.element.classList.add('xterm');
   this.element.classList.add('xterm-theme-' + this.theme);
+  this.element.classList.add(`xterm-cursor-style-${this.options.cursorStyle}`);
   this.setCursorBlinking(this.options.cursorBlink);
 
   this.element.setAttribute('tabindex', 0);
@@ -715,7 +705,9 @@ Terminal.prototype.open = function(parent, focus) {
 
   this.viewport = new Viewport(this, this.viewportElement, this.viewportScrollArea, this.charMeasure);
   this.renderer = new Renderer(this);
-  this.selectionManager = new SelectionManager(this, this.buffer.lines, this.rowContainer, this.charMeasure);
+  this.selectionManager = new SelectionManager(
+    this, this.buffer.lines, this.rowContainer, this.charMeasure
+  );
   this.selectionManager.on('refresh', data => {
     this.renderer.refreshSelection(data.start, data.end);
   });
@@ -755,15 +747,6 @@ Terminal.prototype.open = function(parent, focus) {
     this.focus();
   }
 
-  on(this.element, 'click', function() {
-    var selection = document.getSelection(),
-        collapsed = selection.isCollapsed,
-        isRange = typeof collapsed == 'boolean' ? !collapsed : selection.type == 'Range';
-    if (!isRange) {
-      self.focus();
-    }
-  });
-
   // Listen for mouse events and translate
   // them into terminal mouse protocols.
   this.bindMouse();
@@ -1034,14 +1017,17 @@ Terminal.prototype.bindMouse = function() {
   }
 
   on(el, 'mousedown', function(ev) {
+
+    // Prevent the focus on the textarea from getting lost
+    // and make sure we get focused on mousedown
+    ev.preventDefault();
+    self.focus();
+
     if (!self.mouseEvents) return;
 
     // send the button
     sendButton(ev);
 
-    // ensure focus
-    self.focus();
-
     // fix for odd bug
     //if (self.vt200Mouse && !self.normalMouse) {
     if (self.vt200Mouse) {
@@ -1950,6 +1936,9 @@ Terminal.prototype.resize = function(x, y) {
     ch = [this.defAttr, ' ', 1]; // does xterm use the default attr?
     i = this.buffer.lines.length;
     while (i--) {
+      if (this.buffer.lines.get(i) === undefined) {
+        this.buffer.lines.set(i, this.blankLine());
+      }
       while (this.buffer.lines.get(i).length < x) {
         this.buffer.lines.get(i).push(ch);
       }
@@ -2026,8 +2015,6 @@ Terminal.prototype.resize = function(x, y) {
 
   this.refresh(0, this.rows - 1);
 
-  this.normal = null;
-
   this.geometry = [this.cols, this.rows];
   this.emit('resize', {terminal: this, cols: x, rows: y});
 };
@@ -2209,7 +2196,7 @@ Terminal.prototype.ch = function(cur) {
 
 
 /**
- * Evaluate if the current erminal is the given argument.
+ * Evaluate if the current terminal is the given argument.
  * @param {object} term The terminal to evaluate
  */
 Terminal.prototype.is = function(term) {
@@ -2305,9 +2292,13 @@ Terminal.prototype.reset = function() {
   this.options.cols = this.cols;
   var customKeyEventHandler = this.customKeyEventHandler;
   var cursorBlinkInterval = this.cursorBlinkInterval;
+  var inputHandler = this.inputHandler;
+  var buffers = this.buffers;
   Terminal.call(this, this.options);
   this.customKeyEventHandler = customKeyEventHandler;
   this.cursorBlinkInterval = cursorBlinkInterval;
+  this.inputHandler = inputHandler;
+  this.buffers = buffers;
   this.refresh(0, this.rows - 1);
   this.viewport.syncScrollArea();
 };