Skip to content

Commit

Permalink
Support both lumino 1 and 2 for selections
Browse files Browse the repository at this point in the history
Signed-off-by: martinRenou <martin.renou@gmail.com>
  • Loading branch information
martinRenou committed Sep 5, 2023
1 parent d7e402e commit b694767
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions js/datagrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,47 @@ export class DataGridModel extends DOMWidgetModel {

this.synchingWithKernel = true;

const selectionIter = sender.selections();
const selections: any[] = [];
let selectionNode = null;
while ((selectionNode = selectionIter.next())) {
const selection = selectionNode.value;
selections.push({
r1: Math.min(selection.r1, selection.r2),
r2: Math.max(selection.r1, selection.r2),
c1: Math.min(selection.c1, selection.c2),
c2: Math.max(selection.c1, selection.c2),
});

let selectionIter = sender.selections();
// @ts-ignore
if (typeof selectionIter.iter === 'function') {
// Lumino 1 (JupyterLab 3)
let selection = null;

// @ts-ignore
selectionIter = selectionIter.iter()

while ((selection = selectionIter.next())) {
selections.push({
// @ts-ignore
r1: Math.min(selection.r1, selection.r2),
// @ts-ignore
r2: Math.max(selection.r1, selection.r2),
// @ts-ignore
c1: Math.min(selection.c1, selection.c2),
// @ts-ignore
c2: Math.max(selection.c1, selection.c2),
});
}
} else {
// Lumino 2 (JupyterLab 4)
let selectionNode = null;

while (selectionNode = selectionIter.next()) {
if (selectionNode.done) {
break;
}

const selection = selectionNode.value;

selections.push({
r1: Math.min(selection.r1, selection.r2),
r2: Math.max(selection.r1, selection.r2),
c1: Math.min(selection.c1, selection.c2),
c2: Math.max(selection.c1, selection.c2),
});
}
}

this.set('selections', selections);
Expand Down

0 comments on commit b694767

Please sign in to comment.