From 967b1379fe97dc30af0cd5fe85cc63536cb2a501 Mon Sep 17 00:00:00 2001 From: serapath Date: Wed, 12 Sep 2018 00:08:48 +0100 Subject: [PATCH] add html filter on terminal paste --- src/app/panels/terminal.js | 41 +++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/app/panels/terminal.js b/src/app/panels/terminal.js index b9c7829679..4ee8c563f6 100644 --- a/src/app/panels/terminal.js +++ b/src/app/panels/terminal.js @@ -102,7 +102,7 @@ class Terminal { if (self._view.el) return self._view.el self._view.journal = yo`
` self._view.input = yo` - + ` self._view.input.innerText = '\n' self._view.cli = yo` @@ -141,14 +141,6 @@ class Terminal { ` - setInterval(() => { - self._view.pendingTxCount.innerHTML = self._opts.udapp.pendingTransactionsCount() - }, 1000) - - function listenOnNetwork (ev) { - self.event.trigger('listenOnNetWork', [ev.currentTarget.checked]) - } - self._view.term = yo`
@@ -163,7 +155,38 @@ class Terminal { ${self._view.term}
` + setInterval(() => { + self._view.pendingTxCount.innerHTML = self._opts.udapp.pendingTransactionsCount() + }, 1000) + function listenOnNetwork (ev) { + self.event.trigger('listenOnNetWork', [ev.currentTarget.checked]) + } + function paste (event) { + const selection = window.getSelection() + if (!selection.rangeCount) return false + event.preventDefault() + event.stopPropagation() + var clipboard = (event.clipboardData || window.clipboardData) + var text = clipboard.getData('text/plain') + text = text.replace(/[^\x20-\xFF]/gi, '') // remove non-UTF-8 characters + var temp = document.createElement('div') + temp.innerHTML = text + var textnode = document.createTextNode(temp.textContent) + selection.getRangeAt(0).insertNode(textnode) + selection.empty() + self.scroll2bottom() + placeCaretAtEnd(event.currentTarget) + } + function placeCaretAtEnd (el) { + el.focus() + var range = document.createRange() + range.selectNodeContents(el) + range.collapse(false) + var sel = window.getSelection() + sel.removeAllRanges() + sel.addRange(range) + } function throttle (fn, wait) { var time = Date.now() return function debounce () {