@@ -168,16 +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- event . preventDefault ( )
177- event . stopPropagation ( )
178- this . notify ( 'switch' , element , direction , newCursor )
179- }
180- } , 0 )
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+ }
181183 }
182184
183185 /**
@@ -205,16 +207,14 @@ export default class Dispatcher {
205207 const self = this
206208
207209 this . keyboard
208- . on ( 'left up' , function ( event ) {
209- self . dispatchSwitchEvent ( event , this , 'before ' )
210+ . on ( 'up' , function ( event ) {
211+ self . dispatchSwitchEvent ( event , this , 'up ' )
210212 } )
211213
212- . on ( 'right down' , function ( event ) {
213- self . dispatchSwitchEvent ( event , this , 'after ' )
214+ . on ( 'down' , function ( event ) {
215+ self . dispatchSwitchEvent ( event , this , 'down ' )
214216 } )
215217
216- . on ( 'tab shiftTab esc' , ( ) => { } )
217-
218218 . on ( 'backspace' , function ( event ) {
219219 const range = self . selectionWatcher . getFreshRange ( )
220220 if ( ! range . isCursor ) return self . triggerChangeEvent ( this )
0 commit comments