File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed
WooCommerce/Classes/POS/Presentation/Barcode Scanning Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -30,16 +30,9 @@ final class HIDBarcodeParser {
3030 return
3131 }
3232
33- let currentTime = timeProvider. now ( )
34-
35- // If characters are entered too slowly, it's probably typing and we should ignore it
36- if let lastTime = lastKeyPressTime,
37- currentTime. timeIntervalSince ( lastTime) > configuration. maximumInterCharacterTime {
38- onScan ( . failure( HIDBarcodeParserError . timedOut ( barcode: buffer) ) )
39- resetScan ( )
40- }
41-
42- lastKeyPressTime = currentTime
33+ // If characters are entered too slowly, it's probably typing and we should ignore the old input.
34+ // The key we just recieved is still considered for adding to the buffer – we may simply reset the buffer first.
35+ checkForTimeoutBetweenKeystrokes ( )
4336
4437 let character = key. characters
4538 if configuration. terminatingStrings. contains ( character) {
@@ -67,6 +60,18 @@ final class HIDBarcodeParser {
6760 return true
6861 }
6962
63+ private func checkForTimeoutBetweenKeystrokes( ) {
64+ let currentTime = timeProvider. now ( )
65+
66+ if let lastTime = lastKeyPressTime,
67+ currentTime. timeIntervalSince ( lastTime) > configuration. maximumInterCharacterTime {
68+ onScan ( . failure( HIDBarcodeParserError . timedOut ( barcode: buffer) ) )
69+ resetScan ( )
70+ }
71+
72+ lastKeyPressTime = currentTime
73+ }
74+
7075 private let excludedKeys : [ UIKeyboardHIDUsage ] = [
7176 . keyboardCapsLock,
7277 . keyboardF1,
You can’t perform that action at this time.
0 commit comments