Skip to content

Commit

Permalink
Backport PR jupyterlab#12218: Fix state restoration in the notebook e…
Browse files Browse the repository at this point in the history
…xtension
  • Loading branch information
jtpio authored and meeseeksmachine committed Mar 17, 2022
1 parent 076ba0f commit fd485c6
Showing 1 changed file with 46 additions and 45 deletions.
91 changes: 46 additions & 45 deletions packages/notebook-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,53 +1223,54 @@ function activateNotebookHandler(
? settingRegistry.load(trackerPlugin.id)
: Promise.reject(new Error(`No setting registry for ${trackerPlugin.id}`));

// Handle state restoration.
if (restorer) {
fetchSettings
.then(settings => {
fetchSettings
.then(settings => {
updateConfig(settings);
settings.changed.connect(() => {
updateConfig(settings);
settings.changed.connect(() => {
updateConfig(settings);
});
commands.addCommand(CommandIDs.autoClosingBrackets, {
execute: args => {
const codeConfig = settings.get('codeCellConfig')
.composite as JSONObject;
const markdownConfig = settings.get('markdownCellConfig')
.composite as JSONObject;
const rawConfig = settings.get('rawCellConfig')
.composite as JSONObject;

const anyToggled =
codeConfig.autoClosingBrackets ||
markdownConfig.autoClosingBrackets ||
rawConfig.autoClosingBrackets;
const toggled = !!(args['force'] ?? !anyToggled);
[
codeConfig.autoClosingBrackets,
markdownConfig.autoClosingBrackets,
rawConfig.autoClosingBrackets
] = [toggled, toggled, toggled];

void settings.set('codeCellConfig', codeConfig);
void settings.set('markdownCellConfig', markdownConfig);
void settings.set('rawCellConfig', rawConfig);
},
label: trans.__('Auto Close Brackets for All Notebook Cell Types'),
isToggled: () =>
['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(
x => (settings.get(x).composite as JSONObject).autoClosingBrackets
)
});
})
.catch((reason: Error) => {
console.warn(reason.message);
updateTracker({
editorConfig: factory.editorConfig,
notebookConfig: factory.notebookConfig,
kernelShutdown: factory.shutdownOnClose
});
});
commands.addCommand(CommandIDs.autoClosingBrackets, {
execute: args => {
const codeConfig = settings.get('codeCellConfig')
.composite as JSONObject;
const markdownConfig = settings.get('markdownCellConfig')
.composite as JSONObject;
const rawConfig = settings.get('rawCellConfig')
.composite as JSONObject;

const anyToggled =
codeConfig.autoClosingBrackets ||
markdownConfig.autoClosingBrackets ||
rawConfig.autoClosingBrackets;
const toggled = !!(args['force'] ?? !anyToggled);
[
codeConfig.autoClosingBrackets,
markdownConfig.autoClosingBrackets,
rawConfig.autoClosingBrackets
] = [toggled, toggled, toggled];

void settings.set('codeCellConfig', codeConfig);
void settings.set('markdownCellConfig', markdownConfig);
void settings.set('rawCellConfig', rawConfig);
},
label: trans.__('Auto Close Brackets for All Notebook Cell Types'),
isToggled: () =>
['codeCellConfig', 'markdownCellConfig', 'rawCellConfig'].some(
x => (settings.get(x).composite as JSONObject).autoClosingBrackets
)
});
})
.catch((reason: Error) => {
console.warn(reason.message);
updateTracker({
editorConfig: factory.editorConfig,
notebookConfig: factory.notebookConfig,
kernelShutdown: factory.shutdownOnClose
});
});

// Handle state restoration.
if (restorer) {
void restorer.restore(tracker, {
command: 'docmanager:open',
args: panel => ({ path: panel.context.path, factory: FACTORY }),
Expand Down

0 comments on commit fd485c6

Please sign in to comment.