Skip to content

Commit

Permalink
table.plugin.CellEditing: selectCell() #6164
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Dec 18, 2024
1 parent 71937b2 commit 9b913d0
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions src/table/plugin/CellEditing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class CellEditing extends Plugin {
* @protected
*/
ntype: 'plugin-table-cell-editing',
/**
* @member {String} cellCls='neo-table-cell'
*/
cellCls: 'neo-table-cell',
/**
* @member {Boolean} disabled_=false
*/
Expand Down Expand Up @@ -169,21 +173,23 @@ class CellEditing extends Plugin {
}

/**
* @param {Object} path
* @param {Object} data
* @param {Neo.form.field.Base} field
* @returns {Promise<void>}
*/
async onEditorKeyEnter(path, field) {
await this.submitEditor()
async onEditorKeyEnter(data, field) {
await this.submitEditor();
this.selectCell(data)
}

/**
* @param {Object} path
* @param {Object} data
* @param {Neo.form.field.Base} field
* @returns {Promise<void>}
*/
async onEditorKeyEscape(path, field) {
await this.unmountEditor()
async onEditorKeyEscape(data, field) {
await this.unmountEditor();
this.selectCell(data)
}

/**
Expand Down Expand Up @@ -248,6 +254,31 @@ class CellEditing extends Plugin {
}
}

/**
* @param {Object} data
* @param {Object[]} data.path
*/
selectCell({path}) {
let me = this,
{selectionModel} = me.owner,
i = 0,
len = path.length,
cellId;

for (; i < len; i++) {
if (path[i].cls?.includes(me.cellCls)) {
cellId = path[i].id;
break
}
}

if (cellId) {
selectionModel?.deselect(cellId, true); // the cell might still count as selected => silent deselect first
selectionModel?.select(cellId);
me.owner.focus(cellId)
}
}

/**
* If the field is valid:
* Updates the record field, in case the value of the editor changed,
Expand Down

0 comments on commit 9b913d0

Please sign in to comment.