Skip to content

Commit 0fcf901

Browse files
authored
Merge pull request #219 from osscar-org/disable-cell-edits
Disable editing keyboard shortcuts when activating the hide-code button
2 parents 2451500 + 1a81cb4 commit 0fcf901

6 files changed

Lines changed: 13098 additions & 12 deletions

File tree

.github/workflows/build.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v6
1616

1717
- name: Base Setup
1818
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
@@ -49,7 +49,7 @@ jobs:
4949
pip uninstall -y "jupyterlab_hide_code" jupyterlab
5050
5151
- name: Upload extension packages
52-
uses: actions/upload-artifact@v3
52+
uses: actions/upload-artifact@v7
5353
with:
5454
name: extension-artifacts
5555
path: dist/jupyterlab_hide_code*
@@ -61,11 +61,11 @@ jobs:
6161

6262
steps:
6363
- name: Install Python
64-
uses: actions/setup-python@v4
64+
uses: actions/setup-python@v6
6565
with:
6666
python-version: '3.9'
6767
architecture: 'x64'
68-
- uses: actions/download-artifact@v3
68+
- uses: actions/download-artifact@v8
6969
with:
7070
name: extension-artifacts
7171
- name: Install and Test
@@ -92,13 +92,13 @@ jobs:
9292

9393
steps:
9494
- name: Checkout
95-
uses: actions/checkout@v3
95+
uses: actions/checkout@v6
9696

9797
- name: Base Setup
9898
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
9999

100100
- name: Download extension package
101-
uses: actions/download-artifact@v3
101+
uses: actions/download-artifact@v8
102102
with:
103103
name: extension-artifacts
104104

@@ -114,7 +114,7 @@ jobs:
114114
run: jlpm install
115115

116116
- name: Set up browser cache
117-
uses: actions/cache@v3
117+
uses: actions/cache@v5
118118
with:
119119
path: |
120120
${{ github.workspace }}/pw-browsers
@@ -131,7 +131,7 @@ jobs:
131131
132132
- name: Upload Playwright Test report
133133
if: always()
134-
uses: actions/upload-artifact@v3
134+
uses: actions/upload-artifact@v7
135135
with:
136136
name: jupyterlab_hide_code-playwright-tests
137137
path: |
@@ -143,6 +143,6 @@ jobs:
143143
runs-on: ubuntu-latest
144144
timeout-minutes: 15
145145
steps:
146-
- uses: actions/checkout@v3
146+
- uses: actions/checkout@v6
147147
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
148148
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1

.github/workflows/check-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v3
13+
uses: actions/checkout@v6
1414
- name: Base Setup
1515
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
1616
- name: Install Dependencies
@@ -23,7 +23,7 @@ jobs:
2323
token: ${{ secrets.GITHUB_TOKEN }}
2424

2525
- name: Upload Distributions
26-
uses: actions/upload-artifact@v3
26+
uses: actions/upload-artifact@v7
2727
with:
2828
name: jupyterlab_hide_code-releaser-dist-${{ github.run_number }}
2929
path: .jupyter_releaser_checkout/dist

.github/workflows/update-integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
steps:
1717
- name: Checkout
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v6
1919
with:
2020
token: ${{ secrets.GITHUB_TOKEN }}
2121

src/index.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,48 @@ export class ButtonExtension
4040
panel: NotebookPanel,
4141
context: DocumentRegistry.IContext<INotebookModel>
4242
): IDisposable {
43+
let hidden = false;
44+
45+
// Block keyboard shortcuts that change cell type in command mode
46+
const blockCellTypeShortcuts = (event: KeyboardEvent) => {
47+
if (!hidden) {
48+
return;
49+
}
50+
// Cell type: m, y, r, 1-6
51+
// Add/remove/reorder: a, b, d (dd), x, v, z, Shift+M
52+
const blockedKeys = [
53+
'm',
54+
'y',
55+
'r',
56+
'1',
57+
'2',
58+
'3',
59+
'4',
60+
'5',
61+
'6',
62+
'a',
63+
'b',
64+
'd',
65+
'x',
66+
'v',
67+
'z'
68+
];
69+
const isBlocked =
70+
(blockedKeys.includes(event.key) &&
71+
!event.ctrlKey &&
72+
!event.altKey &&
73+
!event.metaKey) ||
74+
(event.key === 'M' &&
75+
event.shiftKey &&
76+
!event.ctrlKey &&
77+
!event.altKey &&
78+
!event.metaKey);
79+
if (isBlocked) {
80+
event.stopPropagation();
81+
event.preventDefault();
82+
}
83+
};
84+
4385
const hideInputCode = () => {
4486
NotebookActions.runAll(panel.content, context.sessionContext);
4587

@@ -48,7 +90,18 @@ export class ButtonExtension
4890
const layout = cell.layout as PanelLayout;
4991
layout.widgets[1].hide();
5092
}
93+
if (cell.editor) {
94+
cell.editor.setOption('readOnly', true);
95+
}
5196
});
97+
98+
hidden = true;
99+
panel.content.node.addEventListener(
100+
'keydown',
101+
blockCellTypeShortcuts,
102+
true
103+
);
104+
52105
buttonHideInput.hide();
53106
buttonShowInput.show();
54107
};
@@ -58,8 +111,18 @@ export class ButtonExtension
58111
const layout = cell.layout as PanelLayout;
59112
layout.widgets[1].show();
60113
}
114+
if (cell.editor) {
115+
cell.editor.setOption('readOnly', false);
116+
}
61117
});
62118

119+
hidden = false;
120+
panel.content.node.removeEventListener(
121+
'keydown',
122+
blockCellTypeShortcuts,
123+
true
124+
);
125+
63126
buttonHideInput.show();
64127
buttonShowInput.hide();
65128
};

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"resolveJsonModule": true,
1616
"outDir": "lib",
1717
"rootDir": "src",
18+
"skipLibCheck": true,
1819
"strict": true,
1920
"strictNullChecks": true,
2021
"target": "ES2018",

0 commit comments

Comments
 (0)