From 6a341a6e25d2ae17cca2bc641330b0bd4d0bd753 Mon Sep 17 00:00:00 2001 From: lee Date: Fri, 4 Oct 2024 23:20:14 +0900 Subject: [PATCH] #8743 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 모바일 keydown이벤트 동작하지 않는 문제 수정. --- extern/util/CanvasInput.js | 27 ++++++++++++++------------- src/class/pixi/etc/PIXICanvasInput.js | 13 ++++++++++++- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/extern/util/CanvasInput.js b/extern/util/CanvasInput.js index 766d4a2ded..a6091802ff 100755 --- a/extern/util/CanvasInput.js +++ b/extern/util/CanvasInput.js @@ -62,7 +62,7 @@ self._selection = [0, 0]; self._wasOver = false; self._topPosition = o.topPosition; // parse box shadow - + self._hasHiddenFocus = false; self.boxShadow(self._boxShadow, true); // calculate the full width and height with padding, borders and shadows self._calcWH(); // setup the off-DOM canvas @@ -142,14 +142,6 @@ true ); // create the hidden input element - window.addEventListener('keydown', (e) => { - if (self._hasFocus) { - var keyCode = e.keyCode || e.which; - console.log('window keydown', keyCode); - // self.keydown(e, self); - } - }, true); - self._hiddenInput = document.createElement('input'); self._hiddenInput.className = 'entryCanvasHiddenInput'; self._hiddenInput.type = 'text'; @@ -189,6 +181,13 @@ } }); // add this to the buffer + self._hiddenInput.addEventListener('focus', function(e) { + self._hasHiddenFocus = true; + }); + self._hiddenInput.addEventListener('blur', function(e) { + self._hasHiddenFocus = false; + }); + inputs.push(self); self._inputsIndex = inputs.length - 1; // draw the text box @@ -775,7 +774,9 @@ input.addEventListener( 'blur', function() { - self.blur(self); + if (!self._hasHiddenFocus) { + self.blur(self); + } }, false ); @@ -784,7 +785,7 @@ } // move the real focus to the hidden input var hasSelection = self._selection[0] > 0 || self._selection[1] > 0; - + self._hasHiddenFocus = true; self._hiddenInput.focus(); self._hiddenInput.selectionStart = hasSelection ? self._selection[0] : self._cursorPos; @@ -830,12 +831,12 @@ * @return {CanvasInput} */ keydown: function keydown(e, self) { - var keyCode = e.keyCode || e.which; + var keyCode = e.which; var isShift = e.shiftKey; var key = null; var startText; var endText; // make sure the correct text field is being updated - console.log('keydown', keyCode); + if (!self._hasFocus) { return; } // fire custom user event diff --git a/src/class/pixi/etc/PIXICanvasInput.js b/src/class/pixi/etc/PIXICanvasInput.js index 6031a42cf0..e800e4407e 100644 --- a/src/class/pixi/etc/PIXICanvasInput.js +++ b/src/class/pixi/etc/PIXICanvasInput.js @@ -59,6 +59,7 @@ import * as PIXI from 'pixi.js'; self._selection = [0, 0]; self._wasOver = false; self._topPosition = o.topPosition; + self._hasHiddenFocus = false; // parse box shadow self.boxShadow(self._boxShadow, true); @@ -183,6 +184,13 @@ import * as PIXI from 'pixi.js'; } }); + self._hiddenInput.addEventListener('focus', function(e) { + self._hasHiddenFocus = true; + }); + self._hiddenInput.addEventListener('blur', function(e) { + self._hasHiddenFocus = false; + }); + // add this to the buffer inputs.push(self); self._inputsIndex = inputs.length - 1; @@ -794,7 +802,9 @@ import * as PIXI from 'pixi.js'; input.addEventListener( 'blur', () => { - self.blur(self); + if (!self._hasHiddenFocus) { + self.blur(self); + } }, false ); @@ -804,6 +814,7 @@ import * as PIXI from 'pixi.js'; // move the real focus to the hidden input const hasSelection = self._selection[0] > 0 || self._selection[1] > 0; + self._hasHiddenFocus = true; self._hiddenInput.focus(); self._hiddenInput.selectionStart = hasSelection ? self._selection[0] : self._cursorPos; self._hiddenInput.selectionEnd = hasSelection ? self._selection[1] : self._cursorPos;