Skip to content

Commit 8b008df

Browse files
committed
more progress
1 parent 6183e69 commit 8b008df

File tree

3 files changed

+38
-54
lines changed

3 files changed

+38
-54
lines changed

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

Lines changed: 2 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 4px;
1515
transition: top 200ms linear;
1616
visibility: hidden;
1717
}

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

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { Delayer } from 'vs/base/common/async';
1313
import { KeyCode } from 'vs/base/common/keyCodes';
1414
import 'vs/css!./notebookFindReplaceWidget';
1515
import { FindReplaceState, FindReplaceStateChangedEvent } from 'vs/editor/contrib/find/browser/findState';
16-
import { findNextMatchIcon, findPreviousMatchIcon, findReplaceAllIcon, findReplaceIcon, FIND_WIDGET_INITIAL_WIDTH, SimpleButton } from 'vs/editor/contrib/find/browser/findWidget';
16+
import { findNextMatchIcon, findPreviousMatchIcon, findReplaceAllIcon, findReplaceIcon, SimpleButton } from 'vs/editor/contrib/find/browser/findWidget';
1717
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';
@@ -35,8 +35,9 @@ 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, SashState } from 'vs/base/browser/ui/sash/sash';
38+
import { ISashEvent, Orientation, Sash } from 'vs/base/browser/ui/sash/sash';
3939
import { DisposableStore } from 'vs/base/common/lifecycle';
40+
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
4041

4142
const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
4243
const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find");
@@ -57,6 +58,7 @@ const NOTEBOOK_FIND_IN_MARKUP_PREVIEW = nls.localize('notebook.find.filter.findI
5758
const NOTEBOOK_FIND_IN_CODE_INPUT = nls.localize('notebook.find.filter.findInCodeInput', "Code Cell Source");
5859
const NOTEBOOK_FIND_IN_CODE_OUTPUT = nls.localize('notebook.find.filter.findInCodeOutput', "Cell Output");
5960

61+
const NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH = 318;
6062
class NotebookFindFilterActionViewItem extends DropdownMenuActionViewItem {
6163
constructor(readonly filters: NotebookFindFilters, action: IAction, actionRunner: IActionRunner, @IContextMenuService contextMenuService: IContextMenuService) {
6264
super(action,
@@ -257,11 +259,12 @@ export abstract class SimpleFindReplaceWidget extends Widget {
257259
private readonly _replaceInputFocusTracker!: dom.IFocusTracker;
258260
protected _replaceBtn!: SimpleButton;
259261
protected _replaceAllBtn!: SimpleButton;
262+
260263
private readonly _westSash: Sash;
264+
private _resized: boolean = false;
261265
private readonly _sashListener = new DisposableStore();
262266

263267

264-
265268
private _isVisible: boolean = false;
266269
private _isReplaceVisible: boolean = false;
267270
private foundMatch: boolean = false;
@@ -279,7 +282,8 @@ export abstract class SimpleFindReplaceWidget extends Widget {
279282
@IMenuService readonly menuService: IMenuService,
280283
@IContextMenuService readonly contextMenuService: IContextMenuService,
281284
@IInstantiationService readonly instantiationService: IInstantiationService,
282-
protected readonly _state: FindReplaceState<NotebookFindFilters> = new FindReplaceState<NotebookFindFilters>()
285+
protected readonly _state: FindReplaceState<NotebookFindFilters> = new FindReplaceState<NotebookFindFilters>(),
286+
protected readonly _notebookEditor: INotebookEditor,
283287
) {
284288
super();
285289

@@ -291,7 +295,6 @@ export abstract class SimpleFindReplaceWidget extends Widget {
291295
});
292296

293297
this._domNode = document.createElement('div');
294-
295298
this._domNode.classList.add('simple-fr-find-part-wrapper');
296299
this._register(this._state.onFindReplaceStateChange((e) => this._onStateChanged(e)));
297300
this._scopedContextKeyService = contextKeyService.createScoped(this._domNode);
@@ -347,8 +350,6 @@ export abstract class SimpleFindReplaceWidget extends Widget {
347350
}
348351
},
349352
flexibleWidth: true,
350-
flexibleHeight: true,
351-
flexibleMaxHeight: 118,
352353
}
353354
));
354355

@@ -483,19 +484,25 @@ export abstract class SimpleFindReplaceWidget extends Widget {
483484

484485
this._innerReplaceDomNode.appendChild(this._replaceBtn.domNode);
485486
this._innerReplaceDomNode.appendChild(this._replaceAllBtn.domNode);
486-
this.handleFlexWidth();
487487

488488
this._westSash = new Sash(this._domNode, { getVerticalSashLeft: () => 0 }, { orientation: Orientation.VERTICAL, size: 2 });
489489

490-
let originalWidth = FIND_WIDGET_INITIAL_WIDTH;
490+
let originalWidth = NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH;
491+
491492
this._sashListener.add(this._westSash.onDidStart(() => {
492493
originalWidth = dom.getTotalWidth(this._domNode);
493494
}));
494-
this._sashListener.add(this._westSash.onDidEnd(() => {
495-
console.log('end');
496-
}));
497495
this._sashListener.add(this._westSash.onDidChange((evt: ISashEvent) => {
496+
this._resized = true;
498497
const width = originalWidth + evt.startX - evt.currentX;
498+
if (width < NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH) {
499+
return;
500+
}
501+
502+
const maxWidth = this._getMaxWidth();
503+
if (width > maxWidth) {
504+
return;
505+
}
499506

500507
this._domNode.style.width = `${width}px`;
501508
if (this._isReplaceVisible) {
@@ -504,15 +511,18 @@ export abstract class SimpleFindReplaceWidget extends Widget {
504511
this._findInput.inputBox.layout();
505512
}));
506513
this._sashListener.add(this._westSash.onDidReset(() => {
507-
console.log('reset');
514+
// this._domNode.style.width = `${NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH}px`;
515+
const layoutInfo = this._notebookEditor.getLayoutInfo();
516+
console.log(layoutInfo);
517+
console.log(this._domNode.style.width);
518+
// const layoutInfo = notebookEditor
519+
// width = layoutInfo.width - 28 - layoutInfo.minimap.minimapWidth - 15;
508520
}));
509-
this._westSash.state = SashState.Enabled;
510521
}
511522

512-
// getVerticalSashLeft(sash: Sash): number {
513-
// return 4;
514-
// }
515-
523+
private _getMaxWidth() {
524+
return this._notebookEditor.getLayoutInfo().width - 64;
525+
}
516526
getCellToolbarActions(menu: IMenu): { primary: IAction[]; secondary: IAction[] } {
517527
const primary: IAction[] = [];
518528
const secondary: IAction[] = [];
@@ -612,38 +622,6 @@ export abstract class SimpleFindReplaceWidget extends Widget {
612622
this.updateButtons(this.foundMatch);
613623
}
614624

615-
private handleFlexWidth() {
616-
617-
// this._resizeSash = new Sash(this._domNode, this, { orientation: Orientation.VERTICAL, size: 2 });
618-
// let originalWidth = FIND_WIDGET_INITIAL_WIDTH;
619-
620-
// this._register(this._resizeSash.onDidStart(() => {
621-
// originalWidth = dom.getTotalWidth(this._domNode);
622-
// }));
623-
624-
// this._register(this._resizeSash.onDidChange((evt: ISashEvent) => {
625-
// const width = originalWidth + evt.startX - evt.currentX;
626-
627-
// if (width < FIND_WIDGET_INITIAL_WIDTH) {
628-
// // narrow down the find widget should be handled by CSS.
629-
// return;
630-
// }
631-
632-
// const maxWidth = parseFloat(dom.getComputedStyle(this._domNode).maxWidth!) || 0;
633-
// if (width > maxWidth) {
634-
// return;
635-
// }
636-
// this._domNode.style.width = `${width}px`;
637-
// if (this._isReplaceVisible) {
638-
// this._replaceInput.width = dom.getTotalWidth(this._findInput.domNode);
639-
// }
640-
641-
// this._findInput.inputBox.layout();
642-
// }));
643-
// look more into findController
644-
// why does the other findWidget trigger constructor every time you open find menu
645-
// how to get sash div element
646-
}
647625
protected _updateMatchesCount(): void {
648626
}
649627

@@ -806,4 +784,10 @@ registerThemingParticipant((theme, collector) => {
806784
collector.addRule(`.monaco-workbench .simple-fr-find-part-wrapper .monaco-sash { background-color: ${border}; }`);
807785
}
808786
}
787+
788+
collector.addRule(`
789+
:root {
790+
--notebook-find-width: ${NOTEBOOK_FIND_WIDGET_INITIAL_WIDTH}px;
791+
}
792+
`);
809793
});

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)