Kaynağa Gözat

add arrow key navigation to notebook cells

Jason Grout 9 yıl önce
ebeveyn
işleme
d641c711a2
1 değiştirilmiş dosya ile 40 ekleme ve 2 silme
  1. 40 2
      src/notebook/plugin.ts

+ 40 - 2
src/notebook/plugin.ts

@@ -71,6 +71,27 @@ let renderCommand = new SimpleCommand({
 })
 
 
+let selectNextCellCommandId = 'notebook:select-next-cell';
+let selectNextCell = new SimpleCommand({
+  category: 'Notebook Operations',
+  text: 'Select next cell',
+  caption: 'Select next cell',
+  handler: (args) => {
+    args.model.selectNextCell();
+  }
+})
+
+let selectPreviousCellCommandId = 'notebook:select-previous-cell';
+let selectPreviousCell = new SimpleCommand({
+  category: 'Notebook Operations',
+  text: 'Select previous cell',
+  caption: 'Select previous cell',
+  handler: (args) => {
+    args.model.selectPreviousCell();
+  }
+})
+
+
 let notebookContainerClass = 'jp-NotebookContainer';
 
 /**
@@ -95,6 +116,12 @@ function resolve(container: Container): Promise<IFileHandler> {
       }, {
         id: renderCellCommandId,
         command: renderCommand
+      }, {
+        id: selectNextCellCommandId,
+        command: selectNextCell
+      }, {
+        id: selectPreviousCellCommandId,
+        command: selectPreviousCell
       }])
       return handler;
     }
@@ -206,16 +233,27 @@ class NotebookFileHandler extends AbstractFileHandler {
       // specific `.jp-active-document` class, for example. Then the keyboard shortcut
       // selects on that. The application state would also have a handle on this active
       // document (model or widget), and so we could execute the current active cell.
+      let prefix = `.${notebookContainerClass}.notebook-id-${n22otebookId}`
       this.shortcuts.add([{
         sequence: ['Shift Enter'],
-        selector: `.${notebookContainerClass}.notebook-id-${notebookId} .jp-CodeCell`,
+        selector: `${prefix} .jp-CodeCell`,
         command: executeCellCommandId,
         args: {model: model, session: s}
       }, {
         sequence: ['Shift Enter'],
-        selector: `.${notebookContainerClass}.notebook-id-${notebookId} .jp-MarkdownCell`,
+        selector: `${prefix} .jp-MarkdownCell`,
         command: renderCellCommandId,
         args: {model: model}
+      }, {
+        sequence: ['ArrowDown'],
+        selector: `${prefix} .jp-Cell`,
+        command: selectNextCellCommandId,
+        args: {model: model}
+      }, {
+        sequence: ['ArrowUp'],
+        selector: `${prefix} .jp-Cell`,
+        command: selectPreviousCellCommandId,
+        args: {model: model}
       }])
 
       s.kernel.commOpened.connect((kernel, msg) => {