* Adds a new tab * * @param {String} input The text to start the editor with * @param {Integer} currsorPos The line to start the cursor on
(input, cursorPos)
| 84 | */ |
| 85 | |
| 86 | newTab(input, cursorPos) { |
| 87 | |
| 88 | // Generate HTML |
| 89 | const tabEl = $(Tab.generateTabHeaderTemplate(this.totalTabsCreated)) |
| 90 | const contentEl = $(Tab.generateTabContentTemplate(this.totalTabsCreated)) |
| 91 | |
| 92 | // Setup listener to remove tab |
| 93 | const removeButton = tabEl.find('.ui-icon-close') |
| 94 | removeButton.click(() => this.removeTab(tabEl)) |
| 95 | |
| 96 | // Append tab to tab Bar |
| 97 | this.tabBar.find('li:last-child').before(tabEl) |
| 98 | this.container.append(contentEl) |
| 99 | |
| 100 | // Create the new tab |
| 101 | const newTab = new Tab(contentEl) |
| 102 | newTab.setTheme(this.theme) |
| 103 | this.tabs.push(newTab) |
| 104 | |
| 105 | // Refresh tabs and set new tab as active |
| 106 | this.container.tabs('refresh') |
| 107 | this.container.tabs('option', 'active', this.tabs.length - 1) |
| 108 | |
| 109 | if (input) { |
| 110 | newTab.editor.setValue(input) |
| 111 | newTab.editor.setCursor(cursorPos || 0) |
| 112 | } |
| 113 | |
| 114 | this.totalTabsCreated += 1 |
| 115 | |
| 116 | if (this.tabs.length > 1 && this.container.hasClass('tab-bar-hidden')) { |
| 117 | this.showTabBar() |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Shows tab bar |
no test coverage detected