Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect inputOption.activeBackground in preserve case checkbox #81283

Merged
merged 2 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/vs/base/browser/ui/findinput/replaceInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IReplaceInputOptions extends IReplaceInputStyles {

export interface IReplaceInputStyles extends IInputBoxStyles {
inputActiveOptionBorder?: Color;
inputActiveOptionBackground?: Color;
}

const NLS_DEFAULT_LABEL = nls.localize('defaultLabel', "input");
Expand All @@ -44,7 +45,8 @@ export class PreserveCaseCheckbox extends Checkbox {
actionClassName: 'codicon-preserve-case',
title: NLS_PRESERVE_CASE_LABEL + opts.appendTitle,
isChecked: opts.isChecked,
inputActiveOptionBorder: opts.inputActiveOptionBorder
inputActiveOptionBorder: opts.inputActiveOptionBorder,
inputActiveOptionBackground: opts.inputActiveOptionBackground
});
}
}
Expand All @@ -60,6 +62,7 @@ export class ReplaceInput extends Widget {
private fixFocusOnOptionClickEnabled = true;

private inputActiveOptionBorder?: Color;
private inputActiveOptionBackground?: Color;
private inputBackground?: Color;
private inputForeground?: Color;
private inputBorder?: Color;
Expand Down Expand Up @@ -105,6 +108,7 @@ export class ReplaceInput extends Widget {
this.label = options.label || NLS_DEFAULT_LABEL;

this.inputActiveOptionBorder = options.inputActiveOptionBorder;
this.inputActiveOptionBackground = options.inputActiveOptionBackground;
this.inputBackground = options.inputBackground;
this.inputForeground = options.inputForeground;
this.inputBorder = options.inputBorder;
Expand Down Expand Up @@ -181,6 +185,7 @@ export class ReplaceInput extends Widget {

public style(styles: IReplaceInputStyles): void {
this.inputActiveOptionBorder = styles.inputActiveOptionBorder;
this.inputActiveOptionBackground = styles.inputActiveOptionBackground;
this.inputBackground = styles.inputBackground;
this.inputForeground = styles.inputForeground;
this.inputBorder = styles.inputBorder;
Expand All @@ -202,6 +207,7 @@ export class ReplaceInput extends Widget {
if (this.domNode) {
const checkBoxStyles: ICheckboxStyles = {
inputActiveOptionBorder: this.inputActiveOptionBorder,
inputActiveOptionBackground: this.inputActiveOptionBackground,
};
this.preserveCase.style(checkBoxStyles);

Expand Down Expand Up @@ -281,7 +287,8 @@ export class ReplaceInput extends Widget {
this.preserveCase = this._register(new PreserveCaseCheckbox({
appendTitle: '',
isChecked: false,
inputActiveOptionBorder: this.inputActiveOptionBorder
inputActiveOptionBorder: this.inputActiveOptionBorder,
inputActiveOptionBackground: this.inputActiveOptionBackground,
}));
this._register(this.preserveCase.onChange(viaKeyboard => {
this._onDidOptionChange.fire(viaKeyboard);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/theme/common/styler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function attachSelectBoxStyler(widget: IThemable, themeService: IThemeSer
} as ISelectBoxStyleOverrides, widget);
}

export function attachFindInputBoxStyler(widget: IThemable, themeService: IThemeService, style?: IInputBoxStyleOverrides): IDisposable {
export function attachFindReplaceInputBoxStyler(widget: IThemable, themeService: IThemeService, style?: IInputBoxStyleOverrides): IDisposable {
return attachStyler(themeService, {
inputBackground: (style && style.inputBackground) || inputBackground,
inputForeground: (style && style.inputForeground) || inputForeground,
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/contrib/search/browser/searchView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ export class SearchView extends ViewletPanel {
this._register(this.viewModel.searchResult.onChange((event) => this.onSearchResultsChanged(event)));

this._register(this.searchWidget.searchInput.onInput(() => this.updateActions()));
this._register(this.searchWidget.replaceInput.onDidChange(() => this.updateActions()));
this._register(this.searchWidget.replaceInput.onInput(() => this.updateActions()));

this._register(this.onDidFocus(() => this.viewletFocused.set(true)));
this._register(this.onDidBlur(() => this.viewletFocused.set(false)));
Expand Down Expand Up @@ -1048,10 +1048,10 @@ export class SearchView extends ViewletPanel {
this.searchWidget.searchInput.setValue(args.query);
}
if (typeof args.replace === 'string') {
this.searchWidget.replaceInput.value = args.replace;
this.searchWidget.replaceInput.setValue(args.replace);
} else {
if (this.searchWidget.replaceInput.value !== '') {
this.searchWidget.replaceInput.value = '';
if (this.searchWidget.replaceInput.getValue() !== '') {
this.searchWidget.replaceInput.setValue('');
}
}
if (typeof args.triggerSearch === 'boolean' && args.triggerSearch) {
Expand Down
113 changes: 50 additions & 63 deletions src/vs/workbench/contrib/search/browser/searchWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar';
import { Button, IButtonOptions } from 'vs/base/browser/ui/button/button';
import { FindInput, IFindInputOptions } from 'vs/base/browser/ui/findinput/findInput';
import { HistoryInputBox, IMessage } from 'vs/base/browser/ui/inputbox/inputBox';
import { ReplaceInput } from 'vs/base/browser/ui/findinput/replaceInput';
import { IMessage } from 'vs/base/browser/ui/inputbox/inputBox';
import { Widget } from 'vs/base/browser/ui/widget';
import { Action } from 'vs/base/common/actions';
import { Delayer } from 'vs/base/common/async';
Expand All @@ -24,16 +25,15 @@ import { IContextViewService } from 'vs/platform/contextview/browser/contextView
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ISearchConfigurationProperties } from 'vs/workbench/services/search/common/search';
import { attachFindInputBoxStyler, attachInputBoxStyler } from 'vs/platform/theme/common/styler';
import { attachFindReplaceInputBoxStyler } from 'vs/platform/theme/common/styler';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/browser/contextScopedHistoryWidget';
import { ContextScopedFindInput, ContextScopedReplaceInput } from 'vs/platform/browser/contextScopedHistoryWidget';
import { appendKeyBindingLabel, isSearchViewFocused } from 'vs/workbench/contrib/search/browser/searchActions';
import * as Constants from 'vs/workbench/contrib/search/common/constants';
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { IEditorOptions } from 'vs/editor/common/config/editorOptions';
import { IAccessibilityService, AccessibilitySupport } from 'vs/platform/accessibility/common/accessibility';
import { Checkbox } from 'vs/base/browser/ui/checkbox/checkbox';
import { isMacintosh } from 'vs/base/common/platform';

export interface ISearchWidgetOptions {
Expand Down Expand Up @@ -79,6 +79,22 @@ class ReplaceAllAction extends Action {

const ctrlKeyMod = (isMacintosh ? KeyMod.WinCtrl : KeyMod.CtrlCmd);

function stopPropagationForMultiLineUpwards(event: IKeyboardEvent, value: string, textarea: HTMLTextAreaElement | null) {
const isMultiline = !!value.match(/\n/);
if (textarea && isMultiline && textarea.selectionStart > 0) {
event.stopPropagation();
return;
}
}

function stopPropagationForMultiLineDownwards(event: IKeyboardEvent, value: string, textarea: HTMLTextAreaElement | null) {
const isMultiline = !!value.match(/\n/);
if (textarea && isMultiline && textarea.selectionEnd < textarea.value.length) {
event.stopPropagation();
return;
}
}

export class SearchWidget extends Widget {

private static readonly REPLACE_ALL_DISABLED_LABEL = nls.localize('search.action.replaceAll.disabled.label', "Replace All (Submit Search to Enable)");
Expand All @@ -94,15 +110,14 @@ export class SearchWidget extends Widget {
private searchInputBoxFocused: IContextKey<boolean>;

private replaceContainer!: HTMLElement;
replaceInput!: HistoryInputBox;
replaceInput!: ReplaceInput;
replaceInputFocusTracker!: dom.IFocusTracker;
private replaceInputBoxFocused: IContextKey<boolean>;
private toggleReplaceButton!: Button;
private replaceAllAction!: ReplaceAllAction;
private replaceActive: IContextKey<boolean>;
private replaceActionBar!: ActionBar;
replaceInputFocusTracker!: dom.IFocusTracker;
private replaceInputBoxFocused: IContextKey<boolean>;
private _replaceHistoryDelayer: Delayer<void>;
private _preserveCase!: Checkbox;

private ignoreGlobalFindBufferOnNextFocus = false;
private previousGlobalFindBufferValue: string | null = null;
Expand Down Expand Up @@ -180,12 +195,12 @@ export class SearchWidget extends Widget {
setWidth(width: number) {
this.searchInput.inputBox.layout();
this.replaceInput.width = width - 28;
this.replaceInput.layout();
this.replaceInput.inputBox.layout();
}

clear() {
this.searchInput.clear();
this.replaceInput.value = '';
this.replaceInput.setValue('');
this.setReplaceAllActionState(false);
}

Expand All @@ -198,7 +213,7 @@ export class SearchWidget extends Widget {
}

getReplaceValue(): string {
return this.replaceInput.value;
return this.replaceInput.getValue();
}

toggleReplace(show?: boolean): void {
Expand All @@ -212,7 +227,7 @@ export class SearchWidget extends Widget {
}

getReplaceHistory(): string[] {
return this.replaceInput.getHistory();
return this.replaceInput.inputBox.getHistory();
}

clearHistory(): void {
Expand All @@ -228,19 +243,19 @@ export class SearchWidget extends Widget {
}

showNextReplaceTerm() {
this.replaceInput.showNextValue();
this.replaceInput.inputBox.showNextValue();
}

showPreviousReplaceTerm() {
this.replaceInput.showPreviousValue();
this.replaceInput.inputBox.showPreviousValue();
}

searchInputHasFocus(): boolean {
return !!this.searchInputBoxFocused.get();
}

replaceInputHasFocus(): boolean {
return this.replaceInput.hasFocus();
return this.replaceInput.inputBox.hasFocus();
}

focusReplaceAllAction(): void {
Expand Down Expand Up @@ -302,7 +317,7 @@ export class SearchWidget extends Widget {

const searchInputContainer = dom.append(parent, dom.$('.search-container.input-box'));
this.searchInput = this._register(new ContextScopedFindInput(searchInputContainer, this.contextViewService, inputOptions, this.contextKeyService, true));
this._register(attachFindInputBoxStyler(this.searchInput, this.themeService));
this._register(attachFindReplaceInputBoxStyler(this.searchInput, this.themeService));
this.searchInput.onKeyDown((keyboardEvent: IKeyboardEvent) => this.onSearchInputKeyDown(keyboardEvent));
this.searchInput.setValue(options.value || '');
this.searchInput.setRegex(!!options.isRegex);
Expand All @@ -317,7 +332,7 @@ export class SearchWidget extends Widget {
this._register(this.searchInput.inputBox.onDidHeightChange(() => this._onDidHeightChange.fire()));

this._register(this.onReplaceValueChanged(() => {
this._replaceHistoryDelayer.trigger(() => this.replaceInput.addToHistory());
this._replaceHistoryDelayer.trigger(() => this.replaceInput.inputBox.addToHistory());
}));

this.searchInputFocusTracker = this._register(dom.trackFocus(this.searchInput.inputBox.inputElement));
Expand Down Expand Up @@ -345,38 +360,24 @@ export class SearchWidget extends Widget {
this.replaceContainer = dom.append(parent, dom.$('.replace-container.disabled'));
const replaceBox = dom.append(this.replaceContainer, dom.$('.replace-input'));

this.replaceInput = this._register(new ContextScopedHistoryInputBox(replaceBox, this.contextViewService, {
ariaLabel: nls.localize('label.Replace', 'Replace: Type replace term and press Enter to preview or Escape to cancel'),
this.replaceInput = this._register(new ContextScopedReplaceInput(replaceBox, this.contextViewService, {
label: nls.localize('label.Replace', 'Replace: Type replace term and press Enter to preview or Escape to cancel'),
placeholder: nls.localize('search.replace.placeHolder', "Replace"),
history: options.replaceHistory || [],
history: options.replaceHistory,
flexibleHeight: true
}, this.contextKeyService));
}, this.contextKeyService, true));

this._preserveCase = this._register(new Checkbox({
actionClassName: 'codicon-preserve-case',
title: nls.localize('label.preserveCaseCheckbox', "Preserve Case"),
isChecked: !!options.preserveCase,
}));

this._register(this._preserveCase.onChange(viaKeyboard => {
this._register(this.replaceInput.onDidOptionChange(viaKeyboard => {
if (!viaKeyboard) {
this.replaceInput.focus();
this._onPreserveCaseChange.fire(this._preserveCase.checked);
this._onPreserveCaseChange.fire(this.replaceInput.getPreserveCase());
}
}));

const controls = document.createElement('div');
controls.className = 'controls';
controls.style.display = 'block';
controls.appendChild(this._preserveCase.domNode);
replaceBox.appendChild(controls);
this.replaceInput.paddingRight = this._preserveCase.width();

this._register(attachInputBoxStyler(this.replaceInput, this.themeService));
this.onkeydown(this.replaceInput.inputElement, (keyboardEvent) => this.onReplaceInputKeyDown(keyboardEvent));
this.replaceInput.value = options.replaceValue || '';
this._register(this.replaceInput.onDidChange(() => this._onReplaceValueChanged.fire()));
this._register(this.replaceInput.onDidHeightChange(() => this._onDidHeightChange.fire()));
this._register(attachFindReplaceInputBoxStyler(this.replaceInput, this.themeService));
this.replaceInput.onKeyDown((keyboardEvent) => this.onReplaceInputKeyDown(keyboardEvent));
this.replaceInput.setValue(options.replaceValue || '');
this._register(this.replaceInput.inputBox.onDidChange(() => this._onReplaceValueChanged.fire()));
this._register(this.replaceInput.inputBox.onDidHeightChange(() => this._onDidHeightChange.fire()));

this.replaceAllAction = ReplaceAllAction.INSTANCE;
this.replaceAllAction.searchWidget = this;
Expand All @@ -385,7 +386,7 @@ export class SearchWidget extends Widget {
this.replaceActionBar.push([this.replaceAllAction], { icon: true, label: false });
this.onkeydown(this.replaceActionBar.domNode, (keyboardEvent) => this.onReplaceActionbarKeyDown(keyboardEvent));

this.replaceInputFocusTracker = this._register(dom.trackFocus(this.replaceInput.inputElement));
this.replaceInputFocusTracker = this._register(dom.trackFocus(this.replaceInput.inputBox.inputElement));
this._register(this.replaceInputFocusTracker.onDidFocus(() => this.replaceInputBoxFocused.set(true)));
this._register(this.replaceInputFocusTracker.onDidBlur(() => this.replaceInputBoxFocused.set(false)));
}
Expand Down Expand Up @@ -418,7 +419,7 @@ export class SearchWidget extends Widget {
if (currentState !== newState) {
this.replaceActive.set(newState);
this._onReplaceStateChange.fire(newState);
this.replaceInput.layout();
this.replaceInput.inputBox.layout();
}
}

Expand Down Expand Up @@ -476,19 +477,11 @@ export class SearchWidget extends Widget {
}

else if (keyboardEvent.equals(KeyCode.UpArrow)) {
const ta = this.searchInput.domNode.querySelector('textarea');
const isMultiline = !!this.searchInput.getValue().match(/\n/);
if (ta && isMultiline && ta.selectionStart > 0) {
keyboardEvent.stopPropagation();
}
stopPropagationForMultiLineUpwards(keyboardEvent, this.searchInput.getValue(), this.searchInput.domNode.querySelector('textarea'));
}

else if (keyboardEvent.equals(KeyCode.DownArrow)) {
const ta = this.searchInput.domNode.querySelector('textarea');
const isMultiline = !!this.searchInput.getValue().match(/\n/);
if (ta && isMultiline && ta.selectionEnd < ta.value.length) {
keyboardEvent.stopPropagation();
}
stopPropagationForMultiLineDownwards(keyboardEvent, this.searchInput.getValue(), this.searchInput.domNode.querySelector('textarea'));
}
}

Expand All @@ -514,7 +507,7 @@ export class SearchWidget extends Widget {

private onReplaceInputKeyDown(keyboardEvent: IKeyboardEvent) {
if (keyboardEvent.equals(ctrlKeyMod | KeyCode.Enter)) {
this.searchInput.inputBox.insertAtCursor('\n');
this.replaceInput.inputBox.insertAtCursor('\n');
keyboardEvent.preventDefault();
}

Expand All @@ -534,17 +527,11 @@ export class SearchWidget extends Widget {
}

else if (keyboardEvent.equals(KeyCode.UpArrow)) {
const ta = this.searchInput.domNode.querySelector('textarea');
if (ta && ta.selectionStart > 0) {
keyboardEvent.stopPropagation();
}
stopPropagationForMultiLineUpwards(keyboardEvent, this.replaceInput.getValue(), this.replaceInput.domNode.querySelector('textarea'));
}

else if (keyboardEvent.equals(KeyCode.DownArrow)) {
const ta = this.searchInput.domNode.querySelector('textarea');
if (ta && ta.selectionEnd < ta.value.length) {
keyboardEvent.stopPropagation();
}
stopPropagationForMultiLineDownwards(keyboardEvent, this.replaceInput.getValue(), this.replaceInput.domNode.querySelector('textarea'));
}
}

Expand Down