@@ -168,14 +168,18 @@ export default class Dispatcher {
168168
169169 const cursor = this . selectionWatcher . getSelection ( )
170170 if ( ! cursor || cursor . isSelection ) return
171- // Detect if the browser moved the cursor in the next tick.
172- // If the cursor stays at its position, fire the switch event.
173- setTimeout ( ( ) => {
174- var newCursor = this . selectionWatcher . forceCursor ( )
175- if ( newCursor . equals ( cursor ) ) {
176- this . notify ( 'switch' , element , direction , newCursor )
177- }
178- } )
171+
172+ if ( direction === 'up' && cursor . isAtFirstLine ( ) ) {
173+ event . preventDefault ( )
174+ event . stopPropagation ( )
175+ this . notify ( 'switch' , element , direction , cursor )
176+ }
177+
178+ if ( direction === 'down' && cursor . isAtLastLine ( ) ) {
179+ event . preventDefault ( )
180+ event . stopPropagation ( )
181+ this . notify ( 'switch' , element , direction , cursor )
182+ }
179183 }
180184
181185 /**
@@ -204,19 +208,11 @@ export default class Dispatcher {
204208
205209 this . keyboard
206210 . on ( 'up' , function ( event ) {
207- self . dispatchSwitchEvent ( event , this , 'before' )
208- } )
209-
210- . on ( 'left' , function ( event ) {
211- self . dispatchSwitchEvent ( event , this , 'before' )
212- } )
213-
214- . on ( 'right' , function ( event ) {
215- self . dispatchSwitchEvent ( event , this , 'after' )
211+ self . dispatchSwitchEvent ( event , this , 'up' )
216212 } )
217213
218214 . on ( 'down' , function ( event ) {
219- self . dispatchSwitchEvent ( event , this , 'after ' )
215+ self . dispatchSwitchEvent ( event , this , 'down ' )
220216 } )
221217
222218 . on ( 'backspace' , function ( event ) {
0 commit comments