From 8e477fa3cd188dbcbb9ee03f3fd0fcee3e73002c Mon Sep 17 00:00:00 2001 From: Lukas Date: Fri, 25 Jun 2021 16:48:46 +0200 Subject: [PATCH] code(cursor-search): introduce switch context to mimic browser behavior --- src/dispatcher.js | 12 ++++++++++++ src/eventable.js | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/dispatcher.js b/src/dispatcher.js index d5d28a63..3a048d3b 100644 --- a/src/dispatcher.js +++ b/src/dispatcher.js @@ -168,15 +168,27 @@ export default class Dispatcher { const cursor = this.selectionWatcher.getFreshSelection() if (!cursor || cursor.isSelection) return + // store position + if (!this.switchContext) { + this.switchContext = { + positionX: cursor.getBoundingClientRect().left, + events: ['cursor'] + } + } else { + this.switchContext.events = ['cursor'] + } + if (direction === 'up' && cursor.isAtFirstLine()) { event.preventDefault() event.stopPropagation() + this.switchContext.events = ['switch', 'blur', 'focus', 'cursor'] this.notify('switch', element, direction, cursor) } if (direction === 'down' && cursor.isAtLastLine()) { event.preventDefault() event.stopPropagation() + this.switchContext.events = ['switch', 'blur', 'focus', 'cursor'] this.notify('switch', element, direction, cursor) } } diff --git a/src/eventable.js b/src/eventable.js index 2c80c0b3..8487be5b 100644 --- a/src/eventable.js +++ b/src/eventable.js @@ -84,6 +84,11 @@ function getEventableModule (notifyContext) { args.splice(0, 2) } + if (this.switchContext) { + const nextEvent = this.switchContext.events.shift() + if (event !== nextEvent) this.switchContext = undefined + } + const eventListeners = listeners[event] if (!eventListeners) return