@@ -33,6 +33,7 @@ export default class SelectRange extends Module {
3333 this . registerTableOption ( "selectableRangeClearCells" , false ) ; //allow clearing of active range
3434 this . registerTableOption ( "selectableRangeClearCellsValue" , undefined ) ; //value for cleared active range
3535 this . registerTableOption ( "selectableRangeAutoFocus" , true ) ; //focus on a cell after resetRanges
36+ this . registerTableOption ( "selectableRangeBlurEditOnNavigate" , undefined ) ; //prevent editing on navigation
3637
3738 this . registerTableFunction ( "getRangesData" , this . getRangesData . bind ( this ) ) ;
3839 this . registerTableFunction ( "getRanges" , this . getRanges . bind ( this ) ) ;
@@ -132,8 +133,8 @@ export default class SelectRange extends Module {
132133 this . subscribe ( "edit-editor-clear" , this . finishEditingCell . bind ( this ) ) ;
133134 this . subscribe ( "edit-blur" , this . restoreFocus . bind ( this ) ) ;
134135
135- this . subscribe ( "keybinding-nav-prev" , this . keyNavigate . bind ( this , "left " ) ) ;
136- this . subscribe ( "keybinding-nav-next" , this . keyNavigate . bind ( this , "right " ) ) ;
136+ this . subscribe ( "keybinding-nav-prev" , this . keyNavigate . bind ( this , "prev " ) ) ;
137+ this . subscribe ( "keybinding-nav-next" , this . keyNavigate . bind ( this , "next " ) ) ;
137138 this . subscribe ( "keybinding-nav-left" , this . keyNavigate . bind ( this , "left" ) ) ;
138139 this . subscribe ( "keybinding-nav-right" , this . keyNavigate . bind ( this , "right" ) ) ;
139140 this . subscribe ( "keybinding-nav-up" , this . keyNavigate . bind ( this , "up" ) ) ;
@@ -401,6 +402,25 @@ export default class SelectRange extends Module {
401402 ///////////////////////////////////
402403
403404 keyNavigate ( dir , e ) {
405+ if ( this . options ( "selectableRangeBlurEditOnNavigate" ) ) {
406+ const isEditing = this . chain ( "edit-check-editing" ) ;
407+
408+ if ( isEditing ) {
409+ if ( dir === 'next' || dir === 'prev' ) {
410+ this . dispatch ( "edit-cancel-cell" ) ;
411+ } else {
412+ // Prevent navigating while editing except for next/prev
413+ return false ;
414+ }
415+ }
416+ }
417+
418+ if ( dir === 'prev' ) {
419+ dir = 'left' ;
420+ } else if ( dir === 'next' ) {
421+ dir = 'right' ;
422+ }
423+
404424 if ( this . navigate ( false , false , dir ) ) {
405425 e . preventDefault ( ) ;
406426 }
0 commit comments