Skip to content

Commit c744458

Browse files
andreamahjrieken
authored andcommitted
Flexible-width Find Menu in Notebook (#154550)
Fixes #141516
1 parent c7b7d2b commit c744458

File tree

3 files changed

+82
-7
lines changed

3 files changed

+82
-7
lines changed

src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.css

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
position: absolute;
1010
top: -45px;
1111
right: 18px;
12-
width: 318px;
12+
width: var(--notebook-find-width);
1313
max-width: calc(100% - 28px - 28px - 8px);
14-
pointer-events: none;
14+
padding:0 var(--notebook-find-horizontal-padding);
1515
transition: top 200ms linear;
1616
visibility: hidden;
1717
}
@@ -158,3 +158,6 @@
158158
.monaco-workbench .simple-fr-replace-part .monaco-inputbox > .ibwrapper > .input {
159159
height: 24px;
160160
}
161+
.monaco-workbench .simple-fr-find-part-wrapper .monaco-sash {
162+
left: 0 !important;
163+
}

src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindReplaceWidget.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as nls from 'vs/nls';
1818
import { ContextScopedReplaceInput, registerAndCreateHistoryNavigationContext } from 'vs/platform/history/browser/contextScopedHistoryWidget';
1919
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
2020
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
21-
import { editorWidgetBackground, editorWidgetForeground, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
21+
import { editorWidgetBackground, editorWidgetBorder, editorWidgetForeground, editorWidgetResizeBorder, inputActiveOptionBackground, inputActiveOptionBorder, inputActiveOptionForeground, inputBackground, inputBorder, inputForeground, inputValidationErrorBackground, inputValidationErrorBorder, inputValidationErrorForeground, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationInfoForeground, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationWarningForeground, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
2222
import { registerIcon, widgetClose } from 'vs/platform/theme/common/iconRegistry';
2323
import { attachProgressBarStyler } from 'vs/platform/theme/common/styler';
2424
import { IColorTheme, IThemeService, registerThemingParticipant, ThemeIcon } from 'vs/platform/theme/common/themeService';
@@ -35,6 +35,8 @@ import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
3535
import { filterIcon } from 'vs/workbench/contrib/extensions/browser/extensionsIcons';
3636
import { NotebookFindFilters } from 'vs/workbench/contrib/notebook/browser/contrib/find/findFilters';
3737
import { isSafari } from 'vs/base/common/platform';
38+
import { ISashEvent, Orientation, Sash } from 'vs/base/browser/ui/sash/sash';
39+
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
3840

3941
const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
4042
const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find");
@@ -55,6 +57,8 @@ const NOTEBOOK_FIND_IN_MARKUP_PREVIEW = nls.localize('notebook.find.filter.findI
5557
const NOTEBOOK_FIND_IN_CODE_INPUT = nls.localize('notebook.find.filter.findInCodeInput', "Code Cell Source");
5658
const NOTEBOOK_FIND_IN_CODE_OUTPUT = nls.localize('notebook.find.filter.findInCodeOutput', "Cell Output");
5759

60+
const NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH = 318;
61+
const NOTEBOOK_FIND_WIDGET_INITIAL_HORIZONTAL_PADDING = 4;
5862
class NotebookFindFilterActionViewItem extends DropdownMenuActionViewItem {
5963
constructor(readonly filters: NotebookFindFilters, action: IAction, actionRunner: IActionRunner, @IContextMenuService contextMenuService: IContextMenuService) {
6064
super(action,
@@ -256,6 +260,8 @@ export abstract class SimpleFindReplaceWidget extends Widget {
256260
protected _replaceBtn!: SimpleButton;
257261
protected _replaceAllBtn!: SimpleButton;
258262

263+
private readonly _resizeSash: Sash;
264+
private _resizeOriginalWidth = NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH;
259265

260266
private _isVisible: boolean = false;
261267
private _isReplaceVisible: boolean = false;
@@ -274,7 +280,8 @@ export abstract class SimpleFindReplaceWidget extends Widget {
274280
@IMenuService readonly menuService: IMenuService,
275281
@IContextMenuService readonly contextMenuService: IContextMenuService,
276282
@IInstantiationService readonly instantiationService: IInstantiationService,
277-
protected readonly _state: FindReplaceState<NotebookFindFilters> = new FindReplaceState<NotebookFindFilters>()
283+
protected readonly _state: FindReplaceState<NotebookFindFilters> = new FindReplaceState<NotebookFindFilters>(),
284+
protected readonly _notebookEditor: INotebookEditor,
278285
) {
279286
super();
280287

@@ -339,7 +346,8 @@ export abstract class SimpleFindReplaceWidget extends Widget {
339346
this.updateButtons(this.foundMatch);
340347
return { content: e.message };
341348
}
342-
}
349+
},
350+
flexibleWidth: true,
343351
}
344352
));
345353

@@ -474,6 +482,58 @@ export abstract class SimpleFindReplaceWidget extends Widget {
474482

475483
this._innerReplaceDomNode.appendChild(this._replaceBtn.domNode);
476484
this._innerReplaceDomNode.appendChild(this._replaceAllBtn.domNode);
485+
486+
this._resizeSash = this._register(new Sash(this._domNode, { getVerticalSashLeft: () => 0 }, { orientation: Orientation.VERTICAL, size: 2 }));
487+
488+
this._register(this._resizeSash.onDidStart(() => {
489+
this._resizeOriginalWidth = this._getDomWidth();
490+
}));
491+
492+
this._register(this._resizeSash.onDidChange((evt: ISashEvent) => {
493+
let width = this._resizeOriginalWidth + evt.startX - evt.currentX;
494+
if (width < NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH) {
495+
width = NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH;
496+
}
497+
498+
const maxWidth = this._getMaxWidth();
499+
if (width > maxWidth) {
500+
width = maxWidth;
501+
}
502+
503+
this._domNode.style.width = `${width}px`;
504+
505+
if (this._isReplaceVisible) {
506+
this._replaceInput.width = dom.getTotalWidth(this._findInput.domNode);
507+
}
508+
509+
this._findInput.inputBox.layout();
510+
}));
511+
512+
this._register(this._resizeSash.onDidReset(() => {
513+
// users double click on the sash
514+
// try to emulate what happens with editor findWidget
515+
const currentWidth = this._getDomWidth();
516+
let width = NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH;
517+
518+
if (currentWidth <= NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH) {
519+
width = this._getMaxWidth();
520+
}
521+
522+
this._domNode.style.width = `${width}px`;
523+
if (this._isReplaceVisible) {
524+
this._replaceInput.width = dom.getTotalWidth(this._findInput.domNode);
525+
}
526+
527+
this._findInput.inputBox.layout();
528+
}));
529+
}
530+
531+
private _getMaxWidth() {
532+
return this._notebookEditor.getLayoutInfo().width - 64;
533+
}
534+
535+
private _getDomWidth() {
536+
return dom.getTotalWidth(this._domNode) - (NOTEBOOK_FIND_WIDGET_INITIAL_HORIZONTAL_PADDING * 2);
477537
}
478538

479539
getCellToolbarActions(menu: IMenu): { primary: IAction[]; secondary: IAction[] } {
@@ -727,4 +787,16 @@ registerThemingParticipant((theme, collector) => {
727787
if (inputActiveOptionBackgroundColor) {
728788
collector.addRule(`.simple-fr-find-part .find-filter-button > .monaco-action-bar .action-label.notebook-filters.checked { background-color: ${inputActiveOptionBackgroundColor}; }`);
729789
}
790+
791+
const resizeBorderBackground = theme.getColor(editorWidgetResizeBorder) ?? theme.getColor(editorWidgetBorder);
792+
if (resizeBorderBackground) {
793+
collector.addRule(`.monaco-workbench .simple-fr-find-part-wrapper .monaco-sash { background-color: ${resizeBorderBackground}; }`);
794+
}
795+
796+
collector.addRule(`
797+
:root {
798+
--notebook-find-width: ${NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH}px;
799+
--notebook-find-horizontal-padding: ${NOTEBOOK_FIND_WIDGET_INITIAL_HORIZONTAL_PADDING}px;
800+
}
801+
`);
730802
});

src/vs/workbench/contrib/notebook/browser/contrib/find/notebookFindWidget.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
4848
private _findModel: FindModel;
4949

5050
constructor(
51-
private readonly _notebookEditor: INotebookEditor,
51+
_notebookEditor: INotebookEditor,
5252
@IContextViewService contextViewService: IContextViewService,
5353
@IContextKeyService contextKeyService: IContextKeyService,
5454
@IThemeService themeService: IThemeService,
@@ -57,7 +57,7 @@ export class NotebookFindWidget extends SimpleFindReplaceWidget implements INote
5757
@IMenuService menuService: IMenuService,
5858
@IInstantiationService instantiationService: IInstantiationService,
5959
) {
60-
super(contextViewService, contextKeyService, themeService, configurationService, menuService, contextMenuService, instantiationService, new FindReplaceState<NotebookFindFilters>());
60+
super(contextViewService, contextKeyService, themeService, configurationService, menuService, contextMenuService, instantiationService, new FindReplaceState<NotebookFindFilters>(), _notebookEditor);
6161
this._findModel = new FindModel(this._notebookEditor, this._state, this._configurationService);
6262

6363
DOM.append(this._notebookEditor.getDomNode(), this.getDomNode());

0 commit comments

Comments
 (0)