Skip to content

Commit b6ff7af

Browse files
committed
persistent side-by-side ratio setting
1 parent 6099bcb commit b6ff7af

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

packages/notebook-extension/schema/tracker.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,13 @@
922922
"description": "Side-by-side right margin override.",
923923
"type": "string",
924924
"default": "10px"
925+
},
926+
"sideBySideOutputRatio": {
927+
"title": "Side-by-side output ratio",
928+
"description": "For the side-by-side rendering, the side-by-side output ratio defines the width of the output vs the input. Set 1 for same size, > 1 for larger output, < 1 for smaller output.",
929+
"type": "number",
930+
"default": 1,
931+
"minimum": 0
925932
}
926933
},
927934
"additionalProperties": false,

packages/notebook-extension/src/index.ts

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,12 @@ function activateNotebookHandler(
13811381
return Private.isEnabled(shell, tracker);
13821382
};
13831383

1384+
const setSideBySideOutputRatio = (sideBySideOutputRatio: number) =>
1385+
document.documentElement.style.setProperty(
1386+
'--jp-side-by-side-output-size',
1387+
`${sideBySideOutputRatio}fr`
1388+
);
1389+
13841390
// Fetch settings if possible.
13851391
const fetchSettings = settingRegistry
13861392
? settingRegistry.load(trackerPlugin.id)
@@ -1422,6 +1428,22 @@ function activateNotebookHandler(
14221428
x => (settings.get(x).composite as JSONObject).autoClosingBrackets
14231429
)
14241430
});
1431+
commands.addCommand(CommandIDs.setSideBySideRatio, {
1432+
label: trans.__('Set side-by-side ratio'),
1433+
execute: args => {
1434+
InputDialog.getNumber({
1435+
title: trans.__('Width of the output in side-by-side mode'),
1436+
value: settings.get('sideBySideOutputRatio').composite as number
1437+
})
1438+
.then(result => {
1439+
setSideBySideOutputRatio(result.value!);
1440+
if (result.value) {
1441+
settings.set('sideBySideOutputRatio', result.value);
1442+
}
1443+
})
1444+
.catch(console.error);
1445+
}
1446+
});
14251447
})
14261448
.catch((reason: Error) => {
14271449
console.warn(reason.message);
@@ -1534,8 +1556,11 @@ function activateNotebookHandler(
15341556
.composite as string,
15351557
sideBySideRightMarginOverride: settings.get(
15361558
'sideBySideRightMarginOverride'
1537-
).composite as string
1559+
).composite as string,
1560+
sideBySideOutputRatio: settings.get('sideBySideOutputRatio')
1561+
.composite as number
15381562
};
1563+
setSideBySideOutputRatio(factory.notebookConfig.sideBySideOutputRatio);
15391564
const sideBySideMarginStyle = `.jp-mod-sideBySide.jp-Notebook .jp-Notebook-cell {
15401565
margin-left: ${factory.notebookConfig.sideBySideLeftMarginOverride} !important;
15411566
margin-right: ${factory.notebookConfig.sideBySideRightMarginOverride} !important;`;
@@ -2698,24 +2723,6 @@ function addCommands(
26982723
}
26992724
});
27002725

2701-
commands.addCommand(CommandIDs.setSideBySideRatio, {
2702-
label: trans.__('Set side-by-side ratio'),
2703-
execute: args => {
2704-
InputDialog.getNumber({
2705-
title: trans.__('Width of the output in side-by-side mode'),
2706-
value: 1
2707-
})
2708-
.then(result => {
2709-
if (result.value) {
2710-
document.documentElement.style.setProperty(
2711-
'--jp-side-by-side-output-size',
2712-
`${result.value}fr`
2713-
);
2714-
}
2715-
})
2716-
.catch(console.error);
2717-
}
2718-
});
27192726
commands.addCommand(CommandIDs.showAllOutputs, {
27202727
label: trans.__('Expand All Outputs'),
27212728
execute: args => {

packages/notebook/src/widget.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,11 @@ export namespace StaticNotebook {
11051105
* Override the side-by-side right margin.
11061106
*/
11071107
sideBySideRightMarginOverride: string;
1108+
1109+
/**
1110+
* Side-by-side output ratio.
1111+
*/
1112+
sideBySideOutputRatio: number;
11081113
}
11091114

11101115
/**
@@ -1125,7 +1130,8 @@ export namespace StaticNotebook {
11251130
disableDocumentWideUndoRedo: false,
11261131
renderingLayout: 'default',
11271132
sideBySideLeftMarginOverride: '10px',
1128-
sideBySideRightMarginOverride: '10px'
1133+
sideBySideRightMarginOverride: '10px',
1134+
sideBySideOutputRatio: 1
11291135
};
11301136

11311137
/**

packages/notebook/test/widget.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const notebookConfig = {
4747
disableDocumentWideUndoRedo: true,
4848
renderingLayout: 'default' as 'default' | 'side-by-side',
4949
sideBySideLeftMarginOverride: '10px',
50-
sideBySideRightMarginOverride: '10px'
50+
sideBySideRightMarginOverride: '10px',
51+
sideBySideOutputRatio: 1
5152
};
5253

5354
const options: Notebook.IOptions = {

0 commit comments

Comments
 (0)