提交 7162bd57 编写于 作者: U Urange

Fixed terminal search widget bug were actions buttons were not being disabled with invalid input.

上级 b8a7c7f4
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
background-image: url('images/close-dark.svg'); background-image: url('images/close-dark.svg');
} }
monaco-workbench .simple-find-part .button.disabled { .monaco-workbench .simple-find-part .button.disabled {
opacity: 0.3; opacity: 0.3;
cursor: default; cursor: default;
} }
\ No newline at end of file
...@@ -33,6 +33,9 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -33,6 +33,9 @@ export abstract class SimpleFindWidget extends Widget {
private readonly _focusTracker: dom.IFocusTracker; private readonly _focusTracker: dom.IFocusTracker;
private readonly _findInputFocusTracker: dom.IFocusTracker; private readonly _findInputFocusTracker: dom.IFocusTracker;
private readonly _updateHistoryDelayer: Delayer<void>; private readonly _updateHistoryDelayer: Delayer<void>;
private prevBtn: SimpleButton;
private nextBtn: SimpleButton;
private foundMatch: boolean;
constructor( constructor(
@IContextViewService private readonly _contextViewService: IContextViewService, @IContextViewService private readonly _contextViewService: IContextViewService,
...@@ -54,6 +57,8 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -54,6 +57,8 @@ export abstract class SimpleFindWidget extends Widget {
new RegExp(value); new RegExp(value);
return null; return null;
} catch (e) { } catch (e) {
this.foundMatch = false;
this.updateBtns();
return { content: e.message }; return { content: e.message };
} }
} }
...@@ -63,7 +68,8 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -63,7 +68,8 @@ export abstract class SimpleFindWidget extends Widget {
this._updateHistoryDelayer = new Delayer<void>(500); this._updateHistoryDelayer = new Delayer<void>(500);
this.oninput(this._findInput.domNode, (e) => { this.oninput(this._findInput.domNode, (e) => {
this.onInputChanged(); this.foundMatch = this.onInputChanged();
this.updateBtns();
this._delayedUpdateHistory(); this._delayedUpdateHistory();
}); });
...@@ -99,7 +105,7 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -99,7 +105,7 @@ export abstract class SimpleFindWidget extends Widget {
} }
})); }));
const prevBtn = new SimpleButton({ this.prevBtn = new SimpleButton({
label: NLS_PREVIOUS_MATCH_BTN_LABEL, label: NLS_PREVIOUS_MATCH_BTN_LABEL,
className: 'previous', className: 'previous',
onTrigger: () => { onTrigger: () => {
...@@ -107,7 +113,7 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -107,7 +113,7 @@ export abstract class SimpleFindWidget extends Widget {
} }
}); });
const nextBtn = new SimpleButton({ this.nextBtn = new SimpleButton({
label: NLS_NEXT_MATCH_BTN_LABEL, label: NLS_NEXT_MATCH_BTN_LABEL,
className: 'next', className: 'next',
onTrigger: () => { onTrigger: () => {
...@@ -126,8 +132,8 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -126,8 +132,8 @@ export abstract class SimpleFindWidget extends Widget {
this._innerDomNode = document.createElement('div'); this._innerDomNode = document.createElement('div');
this._innerDomNode.classList.add('simple-find-part'); this._innerDomNode.classList.add('simple-find-part');
this._innerDomNode.appendChild(this._findInput.domNode); this._innerDomNode.appendChild(this._findInput.domNode);
this._innerDomNode.appendChild(prevBtn.domNode); this._innerDomNode.appendChild(this.prevBtn.domNode);
this._innerDomNode.appendChild(nextBtn.domNode); this._innerDomNode.appendChild(this.nextBtn.domNode);
this._innerDomNode.appendChild(closeBtn.domNode); this._innerDomNode.appendChild(closeBtn.domNode);
// _domNode wraps _innerDomNode, ensuring that // _domNode wraps _innerDomNode, ensuring that
...@@ -156,7 +162,7 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -156,7 +162,7 @@ export abstract class SimpleFindWidget extends Widget {
})); }));
} }
protected abstract onInputChanged(): void; protected abstract onInputChanged(): boolean;
protected abstract find(previous: boolean): void; protected abstract find(previous: boolean): void;
protected abstract onFocusTrackerFocus(): void; protected abstract onFocusTrackerFocus(): void;
protected abstract onFocusTrackerBlur(): void; protected abstract onFocusTrackerBlur(): void;
...@@ -213,6 +219,7 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -213,6 +219,7 @@ export abstract class SimpleFindWidget extends Widget {
} }
this._isVisible = true; this._isVisible = true;
this.updateBtns();
setTimeout(() => { setTimeout(() => {
dom.addClass(this._innerDomNode, 'visible'); dom.addClass(this._innerDomNode, 'visible');
...@@ -243,6 +250,7 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -243,6 +250,7 @@ export abstract class SimpleFindWidget extends Widget {
// Need to delay toggling visibility until after Transition, then visibility hidden - removes from tabIndex list // Need to delay toggling visibility until after Transition, then visibility hidden - removes from tabIndex list
setTimeout(() => { setTimeout(() => {
this._isVisible = false; this._isVisible = false;
this.updateBtns();
dom.removeClass(this._innerDomNode, 'visible'); dom.removeClass(this._innerDomNode, 'visible');
}, 200); }, 200);
} }
...@@ -267,6 +275,12 @@ export abstract class SimpleFindWidget extends Widget { ...@@ -267,6 +275,12 @@ export abstract class SimpleFindWidget extends Widget {
protected _getCaseSensitiveValue(): boolean { protected _getCaseSensitiveValue(): boolean {
return this._findInput.getCaseSensitive(); return this._findInput.getCaseSensitive();
} }
private updateBtns() {
let hasInput = this.inputValue.length > 0;
this.prevBtn.setEnabled(this._isVisible && hasInput && this.foundMatch);
this.nextBtn.setEnabled(this._isVisible && hasInput && this.foundMatch);
}
} }
// theming // theming
......
...@@ -50,8 +50,9 @@ export class TerminalFindWidget extends SimpleFindWidget { ...@@ -50,8 +50,9 @@ export class TerminalFindWidget extends SimpleFindWidget {
// Ignore input changes for now // Ignore input changes for now
const instance = this._terminalService.getActiveInstance(); const instance = this._terminalService.getActiveInstance();
if (instance !== null) { if (instance !== null) {
instance.findNext(this.inputValue, { regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue(), incremental: true }); return instance.findNext(this.inputValue, { regex: this._getRegexValue(), wholeWord: this._getWholeWordValue(), caseSensitive: this._getCaseSensitiveValue(), incremental: true });
} }
return false;
} }
protected onFocusTrackerFocus() { protected onFocusTrackerFocus() {
......
...@@ -44,6 +44,7 @@ export class WebviewFindWidget extends SimpleFindWidget { ...@@ -44,6 +44,7 @@ export class WebviewFindWidget extends SimpleFindWidget {
} else { } else {
this._delegate.stopFind(false); this._delegate.stopFind(false);
} }
return false;
} }
protected onFocusTrackerFocus() { } protected onFocusTrackerFocus() { }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册