From 4c1590bb6f7d5bc4bb76ad488cba83ee46585c93 Mon Sep 17 00:00:00 2001 From: wschmrdr Date: Sat, 22 Dec 2018 21:47:12 -0500 Subject: [PATCH] Adding a Paste Event to Update View Accounting for Text added via menu or special Linux style of pasting. --- CanvasInput.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CanvasInput.js b/CanvasInput.js index 6df2eeb..dcc88ed 100644 --- a/CanvasInput.js +++ b/CanvasInput.js @@ -169,6 +169,20 @@ } }); + // setup the paste listener + self._hiddenInput.addEventListener('paste', function(e) { + // Hidden input's value isn't updated until after the paste event is finished. + // Delay the updates until it's done so the pasted value exists. + setTimeout(function() { + // update the canvas input state information from the hidden input + self._value = self._hiddenInput.value; + self._cursorPos = self._hiddenInput.selectionStart; + // update selection to hidden input's selection in case user did keyboard-based selection + self._selection = [self._hiddenInput.selectionStart, self._hiddenInput.selectionEnd]; + self.render(); + }, 1); + }); + // add this to the buffer inputs.push(self); self._inputsIndex = inputs.length - 1;