Skip to content

Commit d83ff0f

Browse files
committed
refactor
1 parent 9738fbb commit d83ff0f

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/js/modules/Edit/Edit.js

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

8084
if(Object.keys(this.table.options).includes("editorEmptyValue")){
8185
this.convertEmptyValues = true;
@@ -449,6 +453,19 @@ export default class Edit extends Module{
449453
return this.currentCell ? this.currentCell.getComponent() : false;
450454
}
451455

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

src/js/modules/SelectRange/SelectRange.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,16 @@ export default class SelectRange extends Module {
404404
///////////////////////////////////
405405

406406
keyNavigate(dir, e){
407-
if(this.options("selectableRangeBlurEditOnNavigate") && this.table.modules.edit && this.table.modules.edit.currentCell){
408-
if(dir === 'next' || dir === 'prev'){
409-
// Cancel edit and move to the next cell if editing
410-
this.table.modules.edit.currentCell.getComponent().cancelEdit();
411-
}else{
412-
// Prevent navigating while editing except for next/prev
413-
return false;
407+
if(this.options("selectableRangeBlurEditOnNavigate")){
408+
const isEditing = this.chain("edit-check-editing");
409+
410+
if(isEditing){
411+
if(dir === 'next' || dir === 'prev'){
412+
this.dispatch("edit-cancel-cell");
413+
}else{
414+
// Prevent navigating while editing except for next/prev
415+
return false;
416+
}
414417
}
415418
}
416419

0 commit comments

Comments
 (0)