Преглед на файлове

Merge pull request #3514 from blink1073/multiline-input

Fix stdin rendering and output text selection
Jason Grout преди 7 години
родител
ревизия
faaf5bf125
променени са 1 файла, в които са добавени 13 реда и са изтрити 13 реда
  1. 13 13
      packages/outputarea/src/widget.ts

+ 13 - 13
packages/outputarea/src/widget.ts

@@ -611,14 +611,10 @@ class Stdin extends Widget implements IStdin {
    * Construct a new input widget.
    */
   constructor(options: Stdin.IOptions) {
-    super({ node: Private.createInputWidgetNode() });
+    super({ node: Private.createInputWidgetNode(options.prompt, options.password) });
     this.addClass(STDIN_CLASS);
-    let text = this.node.firstChild as HTMLElement;
-    text.textContent = options.prompt;
-    this._input = this.node.lastChild as HTMLInputElement;
-    if (options.password) {
-      this._input.type = 'password';
-    }
+    this._input = this.node.getElementsByTagName('input')[0];
+    this._input.focus();
     this._future = options.future;
   }
 
@@ -646,7 +642,7 @@ class Stdin extends Widget implements IStdin {
         } else {
           rendered.textContent = input.value;
         }
-        this.node.replaceChild(rendered, input);
+        input.parentElement.replaceChild(rendered, input);
       }
     }
   }
@@ -716,14 +712,18 @@ namespace Private {
    * Create the node for an InputWidget.
    */
   export
-  function createInputWidgetNode(): HTMLElement {
+  function createInputWidgetNode(prompt: string, password: boolean): HTMLElement {
     let node = document.createElement('div');
-    let prompt = document.createElement('span');
-    prompt.className = STDIN_PROMPT_CLASS;
+    let promptNode = document.createElement('pre');
+    promptNode.className = STDIN_PROMPT_CLASS;
+    promptNode.textContent = prompt;
     let input = document.createElement('input');
     input.className = STDIN_INPUT_CLASS;
-    node.appendChild(prompt);
-    node.appendChild(input);
+    if (password) {
+      input.type = 'password';
+    }
+    node.appendChild(promptNode);
+    promptNode.appendChild(input);
     return node;
   }