]> git.proxmox.com Git - mirror_xterm.js.git/commitdiff
Add base viewport, set line height
authorDaniel Imms <daimms@microsoft.com>
Tue, 2 Aug 2016 19:42:10 +0000 (12:42 -0700)
committerDaniel Imms <daimms@microsoft.com>
Tue, 2 Aug 2016 19:42:13 +0000 (12:42 -0700)
Fixes #149

src/xterm.css
src/xterm.js

index 07b82dd5b9f9a418d5c0448db8759092db27b945..9328689269a1ca135888b59db022910459a66742 100644 (file)
     display: block;
 }
 
+.terminal .xterm-char-measure-element {
+    display: inline-block;
+    visibility: hidden;
+    position: absolute;
+    left: -9999em;
+}
+
 /*
  *  Determine default colors for xterm.js
  */
 .terminal .xterm-bg-color-255 {
     background-color: #eeeeee;
 }
-
-/**
- * All terminal rows should have explicitly declared height,
- * in order to allow child elements to adjust.
- */
-.terminal .xterm-rows > div {
-    line-height: normal;
-}
index 012334942a21c4b25610feeb37ae088299ed1cca..a1ac3a01fba4873880492a87aa6fe6c6fdb0e839 100644 (file)
       this.textarea.style.top = '';
     }
 
+    function Viewport(terminal, viewportElement, charMeasureElement) {
+      this.terminal = terminal;
+      this.viewportElement = viewportElement;
+      this.charMeasureElement = charMeasureElement;
+      this.currentHeight = 0;
+
+      this.terminal.on('refresh', this.refreshRowHeight.bind(this));
+    }
+
+    Viewport.prototype.refreshRowHeight = function() {
+      var size = this.charMeasureElement.getBoundingClientRect();
+      if (size.height > 0 && size.height !== this.currentHeight) {
+        this.currentHeight = size.height;
+        this.terminal.rowContainer.style.lineHeight = size.height + 'px';
+        this.terminal.rowContainer.style.height = size.height * this.terminal.rows;
+      }
+    }
+
     /**
      * States
      */
       return row;
     };
 
-
     /**
      * Opens the terminal within an element.
      *
       this.element.classList.add('terminal');
       this.element.classList.add('xterm');
       this.element.classList.add('xterm-theme-' + this.theme);
+
+      this.element.style.height
       this.element.setAttribute('tabindex', 0);
 
+      this.viewportElement = document.createElement('div');
+      this.viewportElement.classList.add('xterm-viewport');
+      this.element.appendChild(this.viewportElement);
+
       /*
       * Create the container that will hold the lines of the terminal and then
       * produce the lines the lines.
       */
       this.rowContainer = document.createElement('div');
       this.rowContainer.classList.add('xterm-rows');
-      this.element.appendChild(this.rowContainer);
+      this.viewportElement.appendChild(this.rowContainer);
       this.children = [];
 
       /*
       this.compositionHelper = new CompositionHelper(this.textarea, this.compositionView, this);
       this.helperContainer.appendChild(this.compositionView);
 
+      this.charMeasureElement = document.createElement('div');
+      this.charMeasureElement.classList.add('xterm-char-measure-element');
+      this.charMeasureElement.innerHTML = 'W';
+      this.helperContainer.appendChild(this.charMeasureElement);
+
+      this.viewport = new Viewport(this, this.viewportElement, this.charMeasureElement);
+
       for (; i < this.rows; i++) {
         this.insertRow();
       }
       if (end - start >= this.rows / 2) {
         parent = this.element.parentNode;
         if (parent) {
-          this.element.removeChild(this.rowContainer);
+          this.viewportElement.removeChild(this.rowContainer);
         }
       }
 
       }
 
       if (parent) {
-        this.element.appendChild(this.rowContainer);
+        this.viewportElement.appendChild(this.rowContainer);
       }
 
       this.emit('refresh', {element: this.element, start: start, end: end});