Skip to content

Commit 3ed553a

Browse files
authored
Merge pull request #4517 from azmy60/fix/nav-while-editing
blur editor after pressing next/prev
2 parents 4cbcd7a + 814958f commit 3ed553a

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/js/modules/Edit/Edit.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ export default class Edit extends Module{
7878
this.subscribe("keybinding-nav-up", this.navigateUp.bind(this, undefined));
7979
this.subscribe("keybinding-nav-down", this.navigateDown.bind(this, undefined));
8080
}
81+
82+
// Add event handlers for other modules to access editing state and functionality
83+
this.subscribe("edit-check-editing", this.checkEditing.bind(this));
84+
this.subscribe("edit-cancel-cell", this.cancelEditEvent.bind(this));
8185

8286
if(Object.keys(this.table.options).includes("editorEmptyValue")){
8387
this.convertEmptyValues = true;
@@ -451,6 +455,19 @@ export default class Edit extends Module{
451455
return this.currentCell ? this.currentCell.getComponent() : false;
452456
}
453457

458+
checkEditing(){
459+
return !!this.currentCell;
460+
}
461+
462+
cancelEditEvent(){
463+
if(this.currentCell){
464+
this.cancelEdit();
465+
return true;
466+
}
467+
return false;
468+
}
469+
470+
454471
clearEditor(cancel){
455472
var cell = this.currentCell,
456473
cellEl;

src/js/modules/SelectRange/SelectRange.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)