* Opens the terminal within an element. * * @param parent The element to create the terminal within.
(parent: HTMLElement)
| 391 | * @param parent The element to create the terminal within. |
| 392 | */ |
| 393 | public open(parent: HTMLElement): void { |
| 394 | if (!parent) { |
| 395 | throw new Error('Terminal requires a parent element.'); |
| 396 | } |
| 397 | |
| 398 | if (!parent.isConnected) { |
| 399 | this._logService.debug('Terminal.open was called on an element that was not attached to the DOM'); |
| 400 | } |
| 401 | |
| 402 | // If the terminal is already opened |
| 403 | if (this.element?.ownerDocument.defaultView && this._coreBrowserService) { |
| 404 | // Adjust the window if needed |
| 405 | if (this.element.ownerDocument.defaultView !== this._coreBrowserService.window) { |
| 406 | this._coreBrowserService.window = this.element.ownerDocument.defaultView; |
| 407 | } |
| 408 | return; |
| 409 | } |
| 410 | |
| 411 | this._document = parent.ownerDocument; |
| 412 | if (this.options.documentOverride && this.options.documentOverride instanceof Document) { |
| 413 | this._document = this.optionsService.rawOptions.documentOverride as Document; |
| 414 | } |
| 415 | |
| 416 | // Create main element container |
| 417 | this.element = this._document.createElement('div'); |
| 418 | this.element.dir = 'ltr'; // xterm.css assumes LTR |
| 419 | this.element.classList.add('terminal'); |
| 420 | this.element.classList.add('xterm'); |
| 421 | parent.appendChild(this.element); |
| 422 | |
| 423 | // Performance: Use a document fragment to build the terminal |
| 424 | // viewport and helper elements detached from the DOM |
| 425 | const fragment = this._document.createDocumentFragment(); |
| 426 | this._viewportElement = this._document.createElement('div'); |
| 427 | this._viewportElement.classList.add('xterm-viewport'); |
| 428 | fragment.appendChild(this._viewportElement); |
| 429 | |
| 430 | this.screenElement = this._document.createElement('div'); |
| 431 | this.screenElement.classList.add('xterm-screen'); |
| 432 | this._register(addDisposableListener(this.screenElement, 'mousemove', (ev: MouseEvent) => this.updateCursorStyle(ev))); |
| 433 | // Create the container that will hold helpers like the textarea for |
| 434 | // capturing DOM Events. Then produce the helpers. |
| 435 | this._helperContainer = this._document.createElement('div'); |
| 436 | this._helperContainer.classList.add('xterm-helpers'); |
| 437 | this.screenElement.appendChild(this._helperContainer); |
| 438 | fragment.appendChild(this.screenElement); |
| 439 | |
| 440 | const textarea = this.textarea = this._document.createElement('textarea'); |
| 441 | this.textarea.classList.add('xterm-helper-textarea'); |
| 442 | this.textarea.setAttribute('aria-label', Strings.promptLabel.get()); |
| 443 | if (!Browser.isChromeOS) { |
| 444 | // ChromeVox on ChromeOS does not like this. See |
| 445 | // https://issuetracker.google.com/issues/260170397 |
| 446 | this.textarea.setAttribute('aria-multiline', 'false'); |
| 447 | } |
| 448 | this.textarea.setAttribute('autocorrect', 'off'); |
| 449 | this.textarea.setAttribute('autocapitalize', 'off'); |
| 450 | this.textarea.setAttribute('spellcheck', 'false'); |
nothing calls this directly
no test coverage detected