Skip to content

Commit

Permalink
table.plugin.CellEditing: connect to cell based selection models #6154
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Dec 18, 2024
1 parent 6abd35a commit 71937b2
Showing 1 changed file with 57 additions and 6 deletions.
63 changes: 57 additions & 6 deletions src/table/plugin/CellEditing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,26 @@ class CellEditing extends Plugin {
construct(config) {
super.construct(config);

let me = this;
let me = this,
{owner} = me,
{selectionModel} = owner;

owner.on({
cellDoubleClick : me.onCellDoubleClick,
focusLeave : me.onFocusLeave,
selectionModelChange: me.onSelectionModelChange,
scope : me
});

// Connect an already registered selectionModel instance
if (Neo.typeOf(selectionModel) === 'NeoInstance') {
me.onSelectionModelChange({value: selectionModel})
}

me.owner.on({
cellDoubleClick: me.onCellDoubleClick,
focusLeave : me.onFocusLeave,
scope : me
owner.keys.add({
Enter: 'onTableKeyDown',
Space: 'onTableKeyDown',
scope: me
})
}

Expand Down Expand Up @@ -186,7 +200,7 @@ class CellEditing extends Plugin {
record = store.getAt(index);

await me.submitEditor();
await me.mountEditor(record, field.dataField);
await me.mountEditor(record, field.dataField)
}

/**
Expand All @@ -197,6 +211,43 @@ class CellEditing extends Plugin {
await this.unmountEditor()
}

/**
* @param {Object} data
*/
onSelectionChange(data) {
// todo: Once we separate cell selections & focus, we can use this event to mount editors
// console.log('onSelectionChange', data);
}

/**
* @param {Object} data
*/
onSelectionModelChange(data) {
let selectionModel = data.value;

if (selectionModel.ntype.includes('cell')) {
selectionModel.on('selectionChange', this.onSelectionChange, this)
}
}

/**
* @param {Object} data
* @returns {Promise<void>}
*/
async onTableKeyDown(data) {
let me = this,
{target} = data,
tableView = me.owner.view,
dataField, record;

if (!me.mountedEditor && target.cls?.includes('neo-selected')) {
dataField = tableView.getCellDataField(target.id);
record = tableView.getRecord(target.id);

await me.mountEditor(record, dataField)
}
}

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

0 comments on commit 71937b2

Please sign in to comment.