From 6e9656aac717ea371048139a7c6f62ac44c1b8d6 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Wed, 7 Feb 2024 21:46:37 +0000 Subject: [PATCH 1/3] Fix scrolling on `g g` and `G` --- package.json | 1 - src/labCommands.ts | 13 ++++--------- yarn.lock | 1 - 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index f6e7b86..84752e4 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,6 @@ "@lumino/commands": "^2.0.1", "@lumino/coreutils": "^2.0.0", "@lumino/disposable": "^2.1.2", - "@lumino/domutils": "^2.0.0", "@replit/codemirror-vim": "^6.0.14", "react": "^18.2.0" }, diff --git a/src/labCommands.ts b/src/labCommands.ts index 2de2a1f..e52950a 100644 --- a/src/labCommands.ts +++ b/src/labCommands.ts @@ -10,7 +10,6 @@ import { import { ReadonlyPartialJSONObject } from '@lumino/coreutils'; import { IDisposable } from '@lumino/disposable'; -import { ElementExt } from '@lumino/domutils'; export function addNotebookCommands( app: JupyterFrontEnd, @@ -246,10 +245,8 @@ export function addNotebookCommands( content.activeCellIndex = 0; content.deselectAll(); if (content.activeCell !== null) { - ElementExt.scrollIntoViewIfNeeded( - content.node, - content.activeCell.node - ); + // note: using `scrollToItem` because `scrollToCell` changes mode (activate the cell) + content.scrollToItem(content.activeCellIndex, 'smart'); } } }, @@ -265,10 +262,8 @@ export function addNotebookCommands( content.activeCellIndex = current.content.widgets.length - 1; content.deselectAll(); if (content.activeCell !== null) { - ElementExt.scrollIntoViewIfNeeded( - content.node, - content.activeCell.node - ); + // note: using `scrollToItem` because `scrollToCell` changes mode (activate the cell) + content.scrollToItem(content.activeCellIndex, 'smart'); } } }, diff --git a/yarn.lock b/yarn.lock index 9cdf018..3b855cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -31,7 +31,6 @@ __metadata: "@lumino/commands": ^2.0.1 "@lumino/coreutils": ^2.0.0 "@lumino/disposable": ^2.1.2 - "@lumino/domutils": ^2.0.0 "@replit/codemirror-vim": ^6.0.14 "@types/codemirror": ^0.0.87 "@types/json-schema": ^7.0.11 From be7c0178ccbb0c4355c917eff325850a54c8d50b Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Thu, 8 Feb 2024 08:44:10 +0000 Subject: [PATCH 2/3] Ensure cell is focused after scrolling Co-authored-by: ianhi --- src/labCommands.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/labCommands.ts b/src/labCommands.ts index e52950a..939a8e0 100644 --- a/src/labCommands.ts +++ b/src/labCommands.ts @@ -237,7 +237,7 @@ export function addNotebookCommands( }), commands.addCommand('vim:select-first-cell', { label: 'Select First Cell', - execute: args => { + execute: async (args) => { const current = getCurrent(args); if (current) { @@ -246,7 +246,8 @@ export function addNotebookCommands( content.deselectAll(); if (content.activeCell !== null) { // note: using `scrollToItem` because `scrollToCell` changes mode (activate the cell) - content.scrollToItem(content.activeCellIndex, 'smart'); + await content.scrollToItem(content.activeCellIndex, 'smart'); + content.activeCell.node.focus(); } } }, @@ -254,7 +255,7 @@ export function addNotebookCommands( }), commands.addCommand('vim:select-last-cell', { label: 'Select Last Cell', - execute: args => { + execute: async (args) => { const current = getCurrent(args); if (current) { @@ -262,8 +263,9 @@ export function addNotebookCommands( content.activeCellIndex = current.content.widgets.length - 1; content.deselectAll(); if (content.activeCell !== null) { - // note: using `scrollToItem` because `scrollToCell` changes mode (activate the cell) - content.scrollToItem(content.activeCellIndex, 'smart'); + // note: using `scrollToItem` because `scrollToCell` changes mode (activates the cell) + await content.scrollToItem(content.activeCellIndex, 'smart'); + content.activeCell.node.focus(); } } }, From 414cb0922a94f8fa0c3a67da6ba3f66c1520eaf3 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Thu, 8 Feb 2024 08:45:51 +0000 Subject: [PATCH 3/3] Lint --- src/labCommands.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/labCommands.ts b/src/labCommands.ts index 939a8e0..69d4d79 100644 --- a/src/labCommands.ts +++ b/src/labCommands.ts @@ -237,7 +237,7 @@ export function addNotebookCommands( }), commands.addCommand('vim:select-first-cell', { label: 'Select First Cell', - execute: async (args) => { + execute: async args => { const current = getCurrent(args); if (current) { @@ -255,7 +255,7 @@ export function addNotebookCommands( }), commands.addCommand('vim:select-last-cell', { label: 'Select Last Cell', - execute: async (args) => { + execute: async args => { const current = getCurrent(args); if (current) {