Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Arrow keys navigation causes double cell hops #77

Merged
merged 4 commits into from
Mar 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions src/codemirrorCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,53 @@ export class VimCellManager {

// JUPYTER PATCH BEGIN
// here we insert the jumps to the next cells

if (line < first || line > last) {
// var currentCell = ns.notebook.get_selected_cell();
// var currentCell = tracker.activeCell;
// var key = '';
// `currentCell !== null should not be needed since `activeCell`
// is already check against null (row 61). Added to avoid warning.
if (currentCell !== null && currentCell.model.type === 'markdown') {
(currentCell as MarkdownCell).rendered = true;
if (!motionArgs.handleArrow) {
// markdown cells tends to improperly handle arrow keys movement,
// on the way up the cell is rendered, but down movement is ignored
// when use arrows the cell will remain unrendered (need to shift+enter)
// However, this is the same as Jupyter default behaviour
(currentCell as MarkdownCell).rendered = true;
}
// currentCell.execute();
}
if (motionArgs.forward) {
// ns.notebook.select_next();
this._commands.execute('notebook:move-cursor-down');
if (!motionArgs.handleArrow) {
this._commands.execute('notebook:move-cursor-down');
} else {
// This block preventing double cell hop when you use arrow keys for navigation
// also arrow key navigation works properly when current cursor position
// at the beginning of line for up move, and at the end for down move
const cursor = cm.getCursor();
const last_char = cm.doc.getLine(last).length;
if (cursor.line !== last || cursor.ch !== last_char) {
cm.setCursor({ line: last, ch: last_char });
this._commands.execute('notebook:move-cursor-down');
}
}
// key = 'j';
} else {
// ns.notebook.select_prev();
this._commands.execute('notebook:move-cursor-up');
if (!motionArgs.handleArrow) {
this._commands.execute('notebook:move-cursor-up');
} else {
// This block preventing double cell hop when you use arrow keys for navigation
// also arrow key navigation works properly when current cursor position
// at the beginning of line for up move, and at the end for down move
const cursor = cm.getCursor();
if (cursor.line !== 0 || cursor.ch !== 0) {
cm.setCursor({ line: 0, ch: 0 });
this._commands.execute('notebook:move-cursor-up');
}
}
// key = 'k';
}
return;
Expand Down Expand Up @@ -188,6 +218,20 @@ export class VimCellManager {
};
lvim.defineMotion('moveByLinesOrCell', moveByLinesOrCell);

lvim.mapCommand(
'<Up>',
'motion',
'moveByLinesOrCell',
{ forward: false, linewise: true, handleArrow: true },
{ context: 'normal' }
);
lvim.mapCommand(
'<Down>',
'motion',
'moveByLinesOrCell',
{ forward: true, linewise: true, handleArrow: true },
{ context: 'normal' }
);
lvim.mapCommand(
'k',
'motion',
Expand Down