Skip to content

Commit

Permalink
selection.grid.RowModel: onNavKeyRow() => decouple the logic from eve…
Browse files Browse the repository at this point in the history
…nt data #6238
  • Loading branch information
tobiu committed Jan 14, 2025
1 parent 6fa6340 commit 53e3d84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 37 deletions.
3 changes: 1 addition & 2 deletions src/grid/View.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,9 @@ class GridView extends Component {

/**
* @param {Object} record
* @param {Number} [index]
* @returns {String}
*/
getRowId(record, index) {
getRowId(record) {
return `${this.id}__tr__${record[this.store.getKeyProperty()]}`
}

Expand Down
52 changes: 17 additions & 35 deletions src/selection/grid/RowModel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,63 +57,45 @@ class RowModel extends BaseModel {
return this.view.vdom.cn[0].cn[1].cn[index].id
}

/**
* Finds the matching table row for a given event path
* @param {Object} path The event path
* @returns {Object|null} The node containing the table row class or null
* @protected
*/
static getRowNode(path) {
let i = 0,
len = path.length,
node = null;

for (; i < len; i++) {
if (path[i].cls.includes('neo-grid-row')) {
node = path[i]
}
}

return node
}

/**
* @param {Object} data
*/
onKeyDownDown(data) {
this.onNavKeyRow(data, 1)
this.onNavKeyRow(1)
}

/**
* @param {Object} data
*/
onKeyDownUp(data) {
this.onNavKeyRow(data, -1)
this.onNavKeyRow(-1)
}

/**
* @param {Object} data
* @param {Number} step
*/
onNavKeyRow(data, step) {
onNavKeyRow(step) {
let me = this,
node = RowModel.getRowNode(data.path),
{view} = me,
{view} = me.view,
{store} = view,
vdomNode = VDomUtil.find(view.vdom, node.id),
newIndex = (vdomNode.index + step) % store.getCount(),
{parentNode} = vdomNode,
id;
currentIndex = 0,
newIndex, newRecord, rowId;

if (me.hasSelection()) {
currentIndex = store.indexOf(view.getRecordByRowId(me.items[0]))
}

newIndex = (currentIndex + step) % store.getCount();

while (newIndex < 0) {
newIndex += store.getCount()
}

id = parentNode.cn[newIndex].id;
newRecord = store.getAt(newIndex);
rowId = view.getRowId(newRecord);

if (id) {
me.select(id);
view.focus(id);
if (rowId) {
me.select(rowId);

view.fire('select', {
record: store.getAt(newIndex)
Expand All @@ -127,7 +109,7 @@ class RowModel extends BaseModel {
onRowClick(data) {
let me = this,
id = data.data.currentTarget,
{view} = me,
{view} = me.view,
isSelected, record;

if (id) {
Expand Down

0 comments on commit 53e3d84

Please sign in to comment.