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

[WIP] Adding classic shortcuts extension #7075

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@codemirror/view": "~6.15.3",
"@jupyter-notebook/application": "~7.0.4",
"@jupyter-notebook/application-extension": "~7.0.4",
"@jupyter-notebook/classic-shortcuts-extension": "~7.0.4",
"@jupyter-notebook/console-extension": "~7.0.4",
"@jupyter-notebook/docmanager-extension": "~7.0.4",
"@jupyter-notebook/documentsearch-extension": "~7.0.4",
Expand Down Expand Up @@ -118,6 +119,7 @@
"dependencies": {
"@jupyter-notebook/application": "^7.0.4",
"@jupyter-notebook/application-extension": "^7.0.4",
"@jupyter-notebook/classic-shortcuts-extension": "7.0.4",
"@jupyter-notebook/console-extension": "^7.0.4",
"@jupyter-notebook/docmanager-extension": "^7.0.4",
"@jupyter-notebook/documentsearch-extension": "^7.0.4",
Expand Down Expand Up @@ -205,6 +207,7 @@
"plugins": {
"/": {
"@jupyter-notebook/application-extension": true,
"@jupyter-notebook/classic-shortcuts-extension": true,
"@jupyter-notebook/console-extension": true,
"@jupyter-notebook/docmanager-extension": true,
"@jupyter-notebook/documentsearch-extension": true,
Expand Down
1 change: 1 addition & 0 deletions packages/_metapackage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@jupyter-notebook/application": "^7.0.4",
"@jupyter-notebook/application-extension": "^7.0.4",
"@jupyter-notebook/classic-shortcuts-extension": "^7.0.4",
"@jupyter-notebook/console-extension": "^7.0.4",
"@jupyter-notebook/docmanager-extension": "^7.0.4",
"@jupyter-notebook/documentsearch-extension": "^7.0.4",
Expand Down
1 change: 1 addition & 0 deletions packages/_metapackage/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import '@jupyter-notebook/application';
import '@jupyter-notebook/application-extension';
import '@jupyter-notebook/classic-shortcuts-extension';
import '@jupyter-notebook/console-extension';
import '@jupyter-notebook/docmanager-extension';
import '@jupyter-notebook/documentsearch-extension';
Expand Down
1 change: 1 addition & 0 deletions packages/_metapackage/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"references": [
{ "path": "../application" },
{ "path": "../application-extension" },
{ "path": "../classic-shortcuts-extension" },
{ "path": "../console-extension" },
{ "path": "../docmanager-extension" },
{ "path": "../documentsearch-extension" },
Expand Down
57 changes: 57 additions & 0 deletions packages/classic-shortcuts-extension/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@jupyter-notebook/classic-shortcuts-extension",
"version": "7.0.4",
"description": "Jupyter Notebook - Classic Shortcuts Extension",
"homepage": "https://github.com/jupyter/notebook",
"bugs": {
"url": "https://github.com/jupyter/notebook/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/jupyter/notebook.git"
},
"license": "BSD-3-Clause",
"author": "Project Jupyter",
"sideEffects": [
"style/**/*.css",
"style/index.js"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"style": "style/index.css",
"directories": {
"lib": "lib/"
},
"files": [
"lib/*.d.ts",
"lib/*.js.map",
"lib/*.js",
"schema/*.json",
"style/**/*.css",
"style/index.js"
],
"scripts": {
"build": "tsc -b",
"build:prod": "tsc -b",
"clean": "rimraf lib && rimraf tsconfig.tsbuildinfo",
"docs": "typedoc src",
"watch": "tsc -b --watch"
},
"dependencies": {
"@jupyter-notebook/application": "^7.0.4",
"@jupyterlab/application": "^4.0.6",
"@jupyterlab/apputils": "^4.1.6"
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "~5.0.2"
},
"publishConfig": {
"access": "public"
},
"jupyterlab": {
"extension": true,
"schemaDir": "schema"
},
"styleModule": "style/index.js"
}
44 changes: 44 additions & 0 deletions packages/classic-shortcuts-extension/schema/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"jupyter.lab.shortcuts": [
{
"command": "documentsearch:startWithReplace",
"keys": ["F"],
"selector": ".jp-mod-searchable :focus:not(:read-write)"
},
{
"command": "apputils:display-shortcuts",
"keys": ["H"],
"selector": "body :focus:not(:read-write)"
},
{
"command": "apputils:activate-command-palette",
"keys": ["P"],
"selector": "body :focus:not(:read-write)"
},
{
"command": "classic:toggle-output-scrolling",
"keys": ["Shift O"],
"selector": "body :focus:not(:read-write)"
},
{
"command": "classic:toggle-collapse-output",
"keys": ["O"],
"selector": "body :focus:not(:read-write)"
},
{
"command": "notebook:toggle-all-cell-line-numbers",
"keys": ["L"],
"selector": "body :focus:not(:read-write)"
},
{
"command": "filebrowser:paste",
"keys": ["Shift V"],
"selector": ".jp-DirListing-content .jp-DirListing-itemText"
}
],
"title": "Jupyter Notebook Classic Shortcuts Extension Entries",
"description": "Jupyter Notebook Classic Shortcuts Extension Entries",
"type": "object",
"properties": {},
"additionalProperties": false
}
106 changes: 106 additions & 0 deletions packages/classic-shortcuts-extension/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';

import { ICommandPalette } from '@jupyterlab/apputils';

/**
* Initialization the functionality for the Classic Shortcuts extension.
*/
const classicShortcutsPlugin: JupyterFrontEndPlugin<void> = {
id: 'classic-shortcuts:plugin',
description: 'A JupyterLab extension.',
autoStart: false,
requires: [ICommandPalette],
activate: (app: JupyterFrontEnd, palette: ICommandPalette) => {
const { commands } = app;

const toggle_collapse_output_command = 'classic:toggle-collapse-output';
const toggle_autoscroll_output_command = 'classic:toggle-output-scrolling';
const toggle_line_numbers_command = 'classic:toggle-line-numbers';

// Add a command to enable/disable collapse output
commands.addCommand(toggle_collapse_output_command, {
label: 'Execute classic:toggle-collapse-output Command',
caption: 'Execute classic:toggle-collapse-output Command',
execute: (args: any) => {
console.log('classic:toggle-collapse-output has been called');

const searchActive = document.querySelector(
'.jp-mod-active.jp-mod-selected'
);
if (searchActive?.children) {
for (let i = 0; i < searchActive?.children.length; i++) {
const outputArea = searchActive.children[i].querySelector(
'.jp-Cell-outputArea'
);
const placeholderArea = searchActive.children[i].querySelector(
'.jp-OutputPlaceholder'
);

if (outputArea) {
commands.execute('notebook:hide-cell-outputs');
}

if (placeholderArea) {
commands.execute('notebook:show-cell-outputs');
}
}
}
},
});

// Add a command to enable/disable autscroll output
commands.addCommand(toggle_autoscroll_output_command, {
label: 'Execute classic:toggle-output-scrolling Command',
caption: 'Execute classic:toggle-output-scrolling Command',
execute: (args: any) => {
console.log('classic:toggle-output-scrolling has been called.');
// if the output has auto-scroll enabled, disable it and vice-versa
const searchActive = document.querySelector(
'.jp-mod-active.jp-mod-selected.jp-mod-outputsScrolled'
);
if (searchActive) {
commands.execute('notebook:disable-output-scrolling');
} else {
commands.execute('notebook:enable-output-scrolling');
}
},
});

// Add a command to enable/disable line numbers
commands.addCommand(toggle_line_numbers_command, {
label: 'Execute classic:toggle-line-numbers Command',
caption: 'Execute classic:toggle-line-numbers Command',
execute: (args: any) => {
console.log('classic:toggle-line-numbers has been called.');
// if the output has auto-scroll enabled, disable it and vice-versa
const searchActive = document.querySelector(
'.jp-mod-active.jp-mod-selected'
);
if (searchActive) {
commands.execute('notebook:disable-output-scrolling');
}
},
});

// Add the commands to the command palette
const category = 'Classic Notebook Shortcuts';
palette.addItem({
command: toggle_collapse_output_command,
category,
args: { origin: 'from palette ' },
});

palette.addItem({
command: toggle_autoscroll_output_command,
category,
args: { origin: 'from palette ' },
});

console.log('Classic Shortcuts extension is activated!');
},
};

export default classicShortcutsPlugin;
Empty file.
1 change: 1 addition & 0 deletions packages/classic-shortcuts-extension/style/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import url('./base.css');
1 change: 1 addition & 0 deletions packages/classic-shortcuts-extension/style/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './base.css';
8 changes: 8 additions & 0 deletions packages/classic-shortcuts-extension/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfigbase",
"compilerOptions": {
"outDir": "lib",
"rootDir": "src"
},
"include": ["src/**/*"]
}