Merge pull request #1542 from nikonso/recreate-terminal
Add recreate terminal after disposing to the demo
This commit is contained in:
+29
-21
@@ -35,20 +35,22 @@ function setPadding() {
|
|||||||
|
|
||||||
createTerminal();
|
createTerminal();
|
||||||
|
|
||||||
addDomListener(paddingElement, 'change', setPadding);
|
const disposeRecreateButtonHandler = () => {
|
||||||
|
// If the terminal exists dispose of it, otherwise recreate it
|
||||||
|
if (term) {
|
||||||
|
term.dispose();
|
||||||
|
term = null;
|
||||||
|
window.term = null;
|
||||||
|
socket = null;
|
||||||
|
document.getElementById('dispose').innerHTML = 'Recreate Terminal';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
createTerminal();
|
||||||
|
document.getElementById('dispose').innerHTML = 'Dispose terminal';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
addDomListener(actionElements.findNext, 'keypress', function (e) {
|
document.getElementById('dispose').addEventListener('click', disposeRecreateButtonHandler);
|
||||||
if (e.key === "Enter") {
|
|
||||||
e.preventDefault();
|
|
||||||
term.findNext(actionElements.findNext.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
addDomListener(actionElements.findPrevious, 'keypress', function (e) {
|
|
||||||
if (e.key === "Enter") {
|
|
||||||
e.preventDefault();
|
|
||||||
term.findPrevious(actionElements.findPrevious.value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function createTerminal() {
|
function createTerminal() {
|
||||||
// Clean terminal
|
// Clean terminal
|
||||||
@@ -76,14 +78,20 @@ function createTerminal() {
|
|||||||
term.fit();
|
term.fit();
|
||||||
term.focus();
|
term.focus();
|
||||||
|
|
||||||
const buttonHandler = () => {
|
addDomListener(paddingElement, 'change', setPadding);
|
||||||
term.dispose();
|
|
||||||
term = null;
|
addDomListener(actionElements.findNext, 'keypress', function (e) {
|
||||||
window.term = null;
|
if (e.key === "Enter") {
|
||||||
socket = null;
|
e.preventDefault();
|
||||||
document.getElementById('dispose').removeEventListener('click', buttonHandler);
|
term.findNext(actionElements.findNext.value);
|
||||||
};
|
}
|
||||||
document.getElementById('dispose').addEventListener('click', buttonHandler);
|
});
|
||||||
|
addDomListener(actionElements.findPrevious, 'keypress', function (e) {
|
||||||
|
if (e.key === "Enter") {
|
||||||
|
e.preventDefault();
|
||||||
|
term.findPrevious(actionElements.findPrevious.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// fit is called within a setTimeout, cols and rows need this.
|
// fit is called within a setTimeout, cols and rows need this.
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user