Skip to content

Commit 8e477fa

Browse files
peyerlukgabrielhase
authored andcommitted
code(cursor-search): introduce switch context to mimic browser behavior
1 parent 82c54fc commit 8e477fa

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/dispatcher.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,27 @@ export default class Dispatcher {
168168
const cursor = this.selectionWatcher.getFreshSelection()
169169
if (!cursor || cursor.isSelection) return
170170

171+
// store position
172+
if (!this.switchContext) {
173+
this.switchContext = {
174+
positionX: cursor.getBoundingClientRect().left,
175+
events: ['cursor']
176+
}
177+
} else {
178+
this.switchContext.events = ['cursor']
179+
}
180+
171181
if (direction === 'up' && cursor.isAtFirstLine()) {
172182
event.preventDefault()
173183
event.stopPropagation()
184+
this.switchContext.events = ['switch', 'blur', 'focus', 'cursor']
174185
this.notify('switch', element, direction, cursor)
175186
}
176187

177188
if (direction === 'down' && cursor.isAtLastLine()) {
178189
event.preventDefault()
179190
event.stopPropagation()
191+
this.switchContext.events = ['switch', 'blur', 'focus', 'cursor']
180192
this.notify('switch', element, direction, cursor)
181193
}
182194
}

src/eventable.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ function getEventableModule (notifyContext) {
8484
args.splice(0, 2)
8585
}
8686

87+
if (this.switchContext) {
88+
const nextEvent = this.switchContext.events.shift()
89+
if (event !== nextEvent) this.switchContext = undefined
90+
}
91+
8792
const eventListeners = listeners[event]
8893
if (!eventListeners) return
8994

0 commit comments

Comments
 (0)