From 852769acea143559f9602936372f7240cee246d0 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 8 Mar 2017 21:07:29 +0300 Subject: [PATCH] refactoring -- now pausing of repeating key handling is a keyboard feature... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/keyboard.js | 41 ++++++++++----------------------- ui (gen4)/lib/keyboard.js | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 29 deletions(-) diff --git a/ui (gen4)/features/keyboard.js b/ui (gen4)/features/keyboard.js index e6782f33..04f172a3 100755 --- a/ui (gen4)/features/keyboard.js +++ b/ui (gen4)/features/keyboard.js @@ -673,10 +673,16 @@ var KeyboardActions = actions.Actions({ `, { keepDialogTitle: true }, function(key, no_match){ + var that = this // get/set the handler... var handler = this.__key_press_handler = this.__key_press_handler - || keyboard.makeKeyboardHandler(this.keyboard, null, this) + //|| keyboard.makeKeyboardHandler(this.keyboard, null, this) + || keyboard.makePausableKeyboardHandler( + this.keyboard, + null, + this, + function(){ return that.config['keyboard-repeat-pause-check'] }) // do the call... return handler(key, no_match) }], @@ -689,24 +695,6 @@ var KeyboardActions = actions.Actions({ return this.__keyboard_handler ? 'on' : 'off' } - // repeat stop checker... - var check = (function(){ - if(this.config['keyboard-repeat-pause-check'] > 0 - && this.__keyboard_repeat_paused){ - var that = this - this.__keyboard_repeat_pause_timeout - && clearTimeout(this.__keyboard_repeat_pause_timeout) - - this.__keyboard_repeat_pause_timeout = setTimeout(function(){ - delete that.__keyboard_repeat_paused - delete that.__keyboard_repeat_pause_timeout - }, this.config['keyboard-repeat-pause-check'] || 100) - - return false - } - return true - }).bind(this) - var kb = this.keyboard // start/reset keyboard handling... @@ -725,15 +713,7 @@ var KeyboardActions = actions.Actions({ && target.off('keydown', this.__keyboard_handler) // make the base handler... - var handler = - keyboard.stoppableKeyboardRepeat( - this.keyPress.bind(this), - /*/ log unbound keys... - function(evt){ - return that.keyPress(evt, function(evt, k){ - window.DEBUG && console.log('KEY:', k) }) }, - //*/ - check) + var handler = this.keyPress.bind(this) // setup base keyboard for devel, in case something breaks... // This branch does not drop keys... @@ -771,7 +751,10 @@ var KeyboardActions = actions.Actions({ This is useful for stopping repeating (held down) keys after some event.`, - function(){ this.__keyboard_repeat_paused = true }], + function(){ + this.config['keyboard-repeat-pause-check'] > 0 + && this.keyboard.pauseRepeat + && this.keyboard.pauseRepeat() }], }) var Keyboard = diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index 74500377..97e0cbf4 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -1049,6 +1049,48 @@ function makeKeyboardHandler(keyboard, unhandled, actions){ +//--------------------------------------------------------------------- +// Pausable base event handler wrapper of Keyboard... +// +// This is the same as .makeKeyboardHandler(..) but adds ability to +// pause repeating key handling... +// +// This will extend the keyboard object by adding: +// .pauseRepeat() - will pause repeating keys... +// +var makePausableKeyboardHandler = +module.makePausableKeyboardHandler = +function makePausableKeyboardHandler(keyboard, unhandled, actions, check_interval){ + + var kb = keyboard instanceof Keyboard ? + keyboard + //: Keyboard(keyboard, checkGlobalMode) + : Keyboard(keyboard) + + kb.pauseRepeat = function(){ this.__repeat_paused = true } + + return stoppableKeyboardRepeat( + makeKeyboardHandler(kb, unhandled, actions), + function(){ + if(kb.__repeat_paused){ + var that = this + kb.__repeat_pause_timeout + && clearTimeout(kb.__repeat_pause_timeout) + + kb.__repeat_pause_timeout = setTimeout(function(){ + delete kb.__repeat_paused + delete kb.__repeat_pause_timeout + }, (check_interval instanceof Function ? + check_interval.call(actions) + : (check_interval || 100))) + + return false + } + return true + }) +} + + //--------------------------------------------------------------------- // handler wrappers...