Skip to content

Commit b6e3fad

Browse files
committed
Moving buttons notebook toolbar to floating state.
1 parent 9b1e3c6 commit b6e3fad

File tree

2 files changed

+80
-59
lines changed

2 files changed

+80
-59
lines changed

src/plugin.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
UnifiedFileDiffManager
2020
} from './diff/unified-file';
2121
import { CodeMirrorEditor } from '@jupyterlab/codemirror';
22-
import { ToolbarButton } from '@jupyterlab/ui-components';
2322

2423
/**
2524
* The translation namespace for the plugin.
@@ -314,54 +313,62 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
314313
notebookTracker.widgetAdded.connect((sender, notebookPanel) => {
315314
const notebookId = notebookPanel.id;
316315

317-
let acceptAllButton: ToolbarButton | null = null;
318-
let rejectAllButton: ToolbarButton | null = null;
316+
let floatingPanel: HTMLElement | null = null;
319317

320-
function updateToolbar() {
321-
const managers = getNotebookManagers(notebookId);
318+
function createFloatingPanel(): HTMLElement {
319+
const panel = document.createElement('div');
320+
panel.classList.add('jp-unified-diff-floating-panel');
321+
322+
const acceptButton = document.createElement('button');
323+
acceptButton.classList.add('jp-merge-accept-button');
324+
acceptButton.textContent = 'Accept All';
325+
acceptButton.title = trans.__('Accept all changes in this notebook');
326+
acceptButton.onclick = () => {
327+
getNotebookManagers(notebookId).forEach(m => m.acceptAll());
328+
updateFloatingPanel();
329+
};
330+
331+
const rejectButton = document.createElement('button');
332+
rejectButton.classList.add('jp-merge-reject-button');
333+
rejectButton.textContent = 'Reject All';
334+
rejectButton.title = trans.__('Reject all changes in this notebook');
335+
rejectButton.onclick = () => {
336+
getNotebookManagers(notebookId).forEach(m => m.rejectAll());
337+
updateFloatingPanel();
338+
};
339+
340+
panel.appendChild(acceptButton);
341+
panel.appendChild(rejectButton);
342+
return panel;
343+
}
322344

345+
function updateFloatingPanel(): void {
346+
const managers = getNotebookManagers(notebookId);
323347
const anyPending = managers.some(m => m.hasPendingChanges());
348+
324349
if (!anyPending) {
325-
if (acceptAllButton) {
326-
acceptAllButton.dispose();
327-
}
328-
if (rejectAllButton) {
329-
rejectAllButton.dispose();
350+
if (floatingPanel && floatingPanel.parentElement) {
351+
floatingPanel.parentElement.removeChild(floatingPanel);
330352
}
331-
acceptAllButton = null;
332-
rejectAllButton = null;
353+
floatingPanel = null;
333354
return;
334355
}
335356

336-
if (!acceptAllButton) {
337-
acceptAllButton = new ToolbarButton({
338-
label: trans.__('Accept All'),
339-
className: 'accept-all-changes',
340-
tooltip: trans.__('Accept all changes in this notebook'),
341-
onClick: () => {
342-
getNotebookManagers(notebookId).forEach(m => m.acceptAll());
343-
updateToolbar();
344-
}
345-
});
346-
notebookPanel.toolbar.addItem('accept-all-changes', acceptAllButton);
357+
if (!floatingPanel) {
358+
floatingPanel = createFloatingPanel();
359+
notebookPanel.node.appendChild(floatingPanel);
347360
}
361+
}
348362

349-
if (!rejectAllButton) {
350-
rejectAllButton = new ToolbarButton({
351-
label: trans.__('Reject All'),
352-
className: 'reject-all-changes',
353-
tooltip: trans.__('Reject all changes in this notebook'),
354-
onClick: () => {
355-
getNotebookManagers(notebookId).forEach(m => m.rejectAll());
356-
updateToolbar();
357-
}
358-
});
359-
notebookPanel.toolbar.addItem('reject-all-changes', rejectAllButton);
363+
notebookPanel.disposed.connect(() => {
364+
clearNotebookManagers(notebookId);
365+
if (floatingPanel && floatingPanel.parentElement) {
366+
floatingPanel.parentElement.removeChild(floatingPanel);
360367
}
361-
}
368+
floatingPanel = null;
369+
});
362370

363-
notebookPanel.disposed.connect(() => clearNotebookManagers(notebookId));
364-
notebookPanel.node.addEventListener('diff-updated', updateToolbar);
371+
notebookPanel.node.addEventListener('diff-updated', updateFloatingPanel);
365372

366373
const originalRegister = registerCellManager;
367374
registerCellManager = (nid: string, manager: UnifiedCellDiffManager) => {

style/base.css

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,47 @@
7878
border-color: var(--jp-border-color1);
7979
}
8080

81-
.jp-ToolbarButtonComponent.accept-all-changes {
82-
background-color: #28a745;
83-
cursor: pointer;
84-
padding: 2px 8px;
81+
/* Floating unified-cell-diff control panel */
82+
.jp-unified-diff-floating-panel {
83+
position: absolute;
84+
bottom: 16px;
85+
right: 16px;
86+
display: flex;
87+
gap: 12px;
88+
background: var(--jp-layout-color1);
89+
border: 1px solid var(--jp-border-color2);
90+
border-radius: 8px;
91+
padding: 8px 12px;
92+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
93+
z-index: 200;
94+
opacity: 0.95;
95+
transition: opacity 0.2s ease-in-out;
96+
}
97+
98+
.jp-unified-diff-floating-panel .jp-merge-accept-button,
99+
.jp-unified-diff-floating-panel .jp-merge-reject-button {
100+
padding: 12px 10px;
101+
font-size: 13px;
85102
border-radius: 4px;
86-
font-size: 12px;
87-
transition:
88-
background-color 0.2s,
89-
border-color 0.2s;
103+
cursor: pointer;
104+
color: white;
105+
font-weight: inherit;
106+
border: none;
107+
transition: background-color 0.2s ease-in-out;
90108
}
91109

92-
.jp-ToolbarButtonComponent.accept-all-changes:hover {
93-
background-color: #058522;
110+
.jp-unified-diff-floating-panel .jp-merge-accept-button {
111+
background-color: #089e03;
94112
}
95113

96-
.jp-ToolbarButtonComponent.reject-all-changes {
97-
background-color: #dc3545;
98-
cursor: pointer;
99-
padding: 2px 8px;
100-
border-radius: 4px;
101-
font-size: 12px;
102-
font-weight: bold;
103-
transition:
104-
background-color 0.2s,
105-
border-color 0.2s;
114+
.jp-unified-diff-floating-panel .jp-merge-accept-button:hover {
115+
background-color: #027e1d;
116+
}
117+
118+
.jp-unified-diff-floating-panel .jp-merge-reject-button {
119+
background-color: #b80606;
106120
}
107121

108-
.jp-ToolbarButtonComponent.reject-all-changes:hover {
109-
background-color: #c82333;
122+
.jp-unified-diff-floating-panel .jp-merge-reject-button:hover {
123+
background-color: #8f0505;
110124
}

0 commit comments

Comments
 (0)