mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-20 20:10:11 -04:00
* Squash merge commits for 1.26 (#1) (#2323) * Polish tag search as per feedback (#55269) * Polish tag search as per feedback * Updated regex * Allow users to opt-out of features that send online requests in the background (#55097) * settings sweep #54690 * Minor css tweaks to enable eoverflow elipsis in more places (#55277) * fix an issue with titlebarheight when not scaling with zoom * Settings descriptions update #54690 * fixes #55209 * Settings editor - many padding fixes * More space above level 2 label * Fixing Cannot debug npm script using Yarn #55103 * Settings editor - show ellipsis when description overflows * Settings editor - ... fix measuring around links, relayout * Setting descriptions * Settings editor - fix ... for some short lines, fix select container width * Settings editor - overlay trees so scrollable shadow is full width * Fix #54133 - missing extension settings after reload * Settings color token description tweak * Settings editor - disable overflow indicator temporarily, needs to be faster * Added command to Run the selected npm script * fixes #54452 * fixes #54929 * fixes #55248 * prefix command with extension name * Contribute run selected to the context menu * node-debug@1.26.6 * Allow terminal rendererType to be swapped out at runtime Part of #53274 Fixes #55344 * Settings editor - fix not focusing search when restoring editor setInput must be actually async. Will be fixed naturally when we aren't using winJS promises... * Settings editor - TOC should only expand the section with a selected item * Bump node-debug2 * Settings editor - Tree focus outlines * Settings editor - don't blink the scrollbar when toc selection changes And hide TOC correctly when the editor is narrow * Settings editor - header rows should not be selectable * fixes #54877 * change debug assignee to isi * Settings sweep (#54690) * workaround for #55051 * Settings sweep (#54690) * settings sweep #54690 * Don't try closing tags when you type > after another > * Describe what implementation code lens does Fixes #55370 * fix javadoc formatter setting description * fixes #55325 * update to officical TS version * Settings editor - Even more padding, use semibold instead of bold * Fix #55357 - fix TOC twistie * fixes #55288 * explorer: refresh on di change file system provider registration fixes #53256 * Disable push to Linux repo to test standalone publisher * New env var to notify log level to extensions #54001 * Disable snippets in extension search (when not in suggest dropdown) (#55281) * Disable snippits in extension search (when not in suggest dropdown) * Add monaco input contributions * Fix bug preventing snippetSuggestions from taking effect in sub-editors * Latest emmet helper to fix #52366 * Fix comment updates for threads within same file * Allow extensions to log telemetry to log files #54001 * Pull latest css grammar * files.exclude control - use same style for "add" vs "edit" * files.exclude control - focus/keyboard behavior * don't show menubar too early * files.exclude - better styling * Place cursor at end of extensions search box on autofill (#55254) * Place cursor at end of extensions search box on autofill * Use position instead of selection * fix linux build issue (empty if block) * Settings editor - fix extension category prefixes * Settings editor - add simple ellipsis for first line that overflows, doesn't cover case when first line does not overflow but there is more text, TODO * File/Text search provider docs * Fixes #52655 * Include epoch (#55008) * Fixes #53385 * Fixes #49480 * VS Code Insiders (Users) not opening Fixes #55353 * Better handling of the case when the extension host fails to start * Fixes #53966 * Remove confusing Start from wordPartLeft commands ID * vscode-xterm@3.6.0-beta12 Fixes #55488 * Initial size is set to infinity!! Fixes #55461 * Polish embeddedEditorBackground * configuration service misses event * Fix #55224 - fix duplicate results in multiroot workspace from splitting the diskseach query * Select all not working in issue reporter on mac, fixes #55424 * Disable fuzzy matching for extensions autosuggest (#55498) * Fix clipping of extensions search border in some third party themes (#55504) * fixes #55538 * Fix bug causing an aria alert to not be shown the third time (and odd numbers thereafter) * Settings editor - work around rendering glitch with webkit-line-clamp * Settings editor - revert earlier '...' changes * Settings editor - move enumDescription to its own div, because it disturbs -webkit-line-clamp for some reason * Settings editor - better overflow indicator * Don't show existing filters in autocomplete (#55495) * Dont show existing filters in autocomplete * Simplify * Settings Editor: Add aria labels for input elements Fixes: #54836 (#55543) * fixes #55223 * Update vscode-css-languageservice to 3.0.10-next.1 * Fix #55509 - settings navigation * Fix #55519 * Fix #55520 * FIx #55524 * Fix #55556 - include wordSeparators in all search queries, so findTextInFiles can respect isWordMatch correctly * oss updates for endgame * Fix unit tests * fixes #55522 * Avoid missing manifest error from bubbling up #54757 * Settings format crawl * Search provider - Fix FileSearchProvider to return array, not progress * Fix #55598 * Settings editor - fix NPE rendering settings with no description * dont render inden guides in search box (#55600) * fixes #55454 * More settings crawl * Another change for #55598 - maxResults applies to FileSearch and TextSearch but not FileIndex * Fix FileSearchProvider unit tests for progress change * fixes #55561 * Settings description update for #54690 * Update setting descriptions for online services * Minor edits * fixes #55513 * fixes #55451 * Fix #55612 - fix findTextInFiles cancellation * fixes #55539 * More setting description tweaks * Setting to disable online experiments #54354 * fixes #55507 * fixes #55515 * Show online services action only in Insiders for now * Settings editor - change toc behavior default to 'filter' * Settings editor - nicer filter count style during search * Fix #55617 - search viewlet icons * Settings editor - better styling for element count indicator * SearchProvider - fix NPE when searching extraFileResources * Allow extends to work without json suffix Fixes #16905 * Remove accessability options logic entirely Follow up on #55451 * use latest version of DAP * fixes #55490 * fixes #55122 * fixes #52332 * Avoid assumptions about git: URIs (fixes #36236) * relative path for descriptions * resourece: get rid of isFile context key fixes #48275 * Register previous ids for compatibility (#53497) * more tuning for #48275 * no need to always re-read "files explorer" fixes #52003 * read out active composites properly fixes #51967 * Update link colors for hc theme to meet color contrast ratio, fixes #55651 Also updated link color for `textLinkActiveForeground` to be the same as `textLinkForeground` as it wasn't properly updated * detect 'winpty-agent.exe'; fixes #55672 * node-debug@1.26.7 * reset counter on new label * Settings editor - fix multiple setting links in one description * Settings editor - color code blocks in setting descriptions, fix #55532 * Settings editor - hover color in TOC * Settings editor - fix navigation NPE * Settings editor - fix text control width * Settings editor - maybe fix #55684 * Fix bug causing cursor to not move on paste * fixes #53582 * Use ctrlCmd instead of ctrl for go down from search box * fixes #55264 * fixes #55456 * filter for spcaes before triggering search (#55611) * Fix #55698 - don't lose filtered TOC counts when refreshing TOC * fixes #55421 * fixes #28979 * fixes #55576 * only add check for updates to windows/linux help * readonly files: append decoration to label fixes #53022 * debug: do not show toolbar while initialising fixes #55026 * Opening launch.json should not activate debug extensions fixes #55029 * fixes #55435 * fixes #55434 * fixes #55439 * trigger menu only on altkey up * Fix #50555 - fix settings editor memory leak * Fix #55712 - no need to focus 'a' anymore when restoring control focus after tree render * fixes #55335 * proper fix for readonly model fixes #53022 * improve FoldingRangeKind spec (for #55686) * Use class with static fields (fixes #55494) * Fixes #53671 * fixes #54630 * [html] should disable ionic suggestions by default. Currently forces deprecated Ionic v1 suggestions in .html files while typing. Fixes #53324 * cleanup deps * debug issues back to andre * update electron for smoketest * Fix #55757 - prevent settings tabs from overflowing * Fix #53897 - revert setting menu defaults to old editor * Add enum descriptions to `typescript.preferences.importModuleSpecifier` * Fix #55767 - leaking style elements from settings editor * Fix #55521 - prevent flashing when clicking in exclude control * Update Git modified color for contrast ratio, fixes #53140 * Revert "Merge branch 'master' of github.com:Microsoft/vscode" This reverts commit bf46b6bfbae0cab99c2863e1244a916181fa9fbc, reversing changes made to e275a424483dfb4ed33b428c97d5e2c441d6b917. * Revert "Revert "Merge branch 'master' of github.com:Microsoft/vscode"" This reverts commit 53949d963f39e40757557c6526332354a31d9154. * don't ask to install an incomplete menu * Fix NPE in terminal AccessibilityManager Fixes #55744 * don't display fallback menu unless we've closed the last window * fixes #55547 * Fix smoke tests for extension search box * Update OSSREADME.json for Electron 2.0.5 * Update distro Includes Chromium license changes * fix #55455 * fix #55865 * fixes #55893 * Fix bug causing workspace recommendations to go away upon ignoring a recommendation (#55805) * Fix bug causing workspace recommendations to go away upon ignoring a recommendation * ONly show on @recommended or @recommended:workspace * Make more consistant * Fix #55911 * Understand json activity (#55926) * Understand json file activity * Refactoring * adding composer.json * Distro update for experiments * use terminal.processId for auto-attach; fixes #55918 * Reject invalid URI with vscode.openFolder (for #55891) * improve win32 setup system vs user detection fixes #55840 fixes #55840 delay winreg import related to #55840 show notification earlier related to #55840 fix #55840 update inno setup message related to #55840 * Fix #55593 - this code only operates on local paths, so use fsPath and Uri.file instead * Bring back the old menu due to electron 2.0 issues (#55913) * add the old menu back for native menus * make menu labels match * `vscode.openFolder`: treat missing URI schema gracefully (for #55891) * delay EH reattach; fixes #55955 * Mark all json files under appSettingsHome as settings * Use localized strings for telemetry opt-out * Exception when saving file editor opened from remote file provider (fixes #55051) * Remove terminal menu from stable Fixes 56003 * VSCode Insiders crashes on open with TypeError: Cannot read property 'lastIndexOf' of undefined. Fixes #54933 * improve fix for #55891 * fix #55916 * Improve #55891 * increase EH debugging restart delay; fixes #55955 * Revert "Don't include non-resource entries in history quick pick" This reverts commit 37209a838e9f7e9abe6dc53ed73cdf1e03b72060. * Diff editor: horizontal scrollbar height is smaller (fixes #56062) * improve openFolder uri fix (correctly treat backslashes) * fixes #56116 repair ipc for native menubar keybindings * Fix #56240 - Open the JSON settings editor instead of the UI editor * Fix #55536 * uriDisplay: if no formatter is registered fall back to getPathlabel fixes #56104 * VSCode hangs when opening python file. Fixes #56377 * VS Code Hangs When Opening Specific PowerShell File. Fixes #56430 * Fix #56433 - search extraFileResources even when no folders open * Workaround #55649 * Fix in master #56371 * Fix tests #56371 * Fix in master #56317 * increase version to 1.26.1 * Fixes #56387: Handle SIGPIPE in extension host * fixes #56185 * Fix merge issues (part 1) * Fix build breaks (part 1) * Build breaks (part 2) * Build breaks (part 3) * More build breaks (part 4) * Fix build breaks (part 5) * WIP * Fix menus * Render query result and message panels (#2363) * Put back query editor hot exit changes * Fix grid changes that broke profiler (#2365) * Update APIs for saving query editor state * Fix restore view state for profiler and edit data * Updating custom default themes to support 4.5:1 contrast ratio * Test updates * Fix Extension Manager and Windows Setup * Update license headers * Add appveyor and travis files back * Fix hidden modal dropdown issue
1146 lines
38 KiB
TypeScript
1146 lines
38 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
|
*--------------------------------------------------------------------------------------------*/
|
|
|
|
'use strict';
|
|
|
|
import 'vs/css!./findWidget';
|
|
import * as nls from 'vs/nls';
|
|
import { onUnexpectedError } from 'vs/base/common/errors';
|
|
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
|
|
import * as platform from 'vs/base/common/platform';
|
|
import * as strings from 'vs/base/common/strings';
|
|
import { Delayer } from 'vs/base/common/async';
|
|
import * as dom from 'vs/base/browser/dom';
|
|
import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
|
|
import { IMouseEvent } from 'vs/base/browser/mouseEvent';
|
|
import { IContextViewProvider } from 'vs/base/browser/ui/contextview/contextview';
|
|
import { FindInput, IFindInputStyles } from 'vs/base/browser/ui/findinput/findInput';
|
|
import { IMessage as InputBoxMessage, HistoryInputBox } from 'vs/base/browser/ui/inputbox/inputBox';
|
|
import { Widget } from 'vs/base/browser/ui/widget';
|
|
import { Sash, IHorizontalSashLayoutProvider, ISashEvent, Orientation } from 'vs/base/browser/ui/sash/sash';
|
|
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
|
|
import { ICodeEditor, IOverlayWidget, IOverlayWidgetPosition, IViewZone, OverlayWidgetPositionPreference } from 'vs/editor/browser/editorBrowser';
|
|
import { FIND_IDS, MATCHES_LIMIT, CONTEXT_FIND_INPUT_FOCUSED, CONTEXT_REPLACE_INPUT_FOCUSED } from 'vs/editor/contrib/find/findModel';
|
|
import { FindReplaceState, FindReplaceStateChangedEvent } from 'vs/editor/contrib/find/findState';
|
|
import { Range } from 'vs/editor/common/core/range';
|
|
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
|
import { ITheme, registerThemingParticipant, IThemeService } from 'vs/platform/theme/common/themeService';
|
|
import { Color } from 'vs/base/common/color';
|
|
import { IConfigurationChangedEvent } from 'vs/editor/common/config/editorOptions';
|
|
import { editorFindRangeHighlight, editorFindMatch, editorFindMatchHighlight, contrastBorder, inputBackground, editorWidgetBackground, inputActiveOptionBorder, widgetShadow, inputForeground, inputBorder, inputValidationInfoBackground, inputValidationInfoBorder, inputValidationWarningBackground, inputValidationWarningBorder, inputValidationErrorBackground, inputValidationErrorBorder, errorForeground, editorWidgetBorder, editorFindMatchBorder, editorFindMatchHighlightBorder, editorFindRangeHighlightBorder, editorWidgetResizeBorder } from 'vs/platform/theme/common/colorRegistry';
|
|
import { ContextScopedFindInput, ContextScopedHistoryInputBox } from 'vs/platform/widget/browser/contextScopedHistoryWidget';
|
|
|
|
|
|
export interface IFindController {
|
|
replace(): void;
|
|
replaceAll(): void;
|
|
getGlobalBufferTerm(): string;
|
|
}
|
|
|
|
const NLS_FIND_INPUT_LABEL = nls.localize('label.find', "Find");
|
|
const NLS_FIND_INPUT_PLACEHOLDER = nls.localize('placeholder.find', "Find");
|
|
const NLS_PREVIOUS_MATCH_BTN_LABEL = nls.localize('label.previousMatchButton', "Previous match");
|
|
const NLS_NEXT_MATCH_BTN_LABEL = nls.localize('label.nextMatchButton', "Next match");
|
|
const NLS_TOGGLE_SELECTION_FIND_TITLE = nls.localize('label.toggleSelectionFind', "Find in selection");
|
|
const NLS_CLOSE_BTN_LABEL = nls.localize('label.closeButton', "Close");
|
|
const NLS_REPLACE_INPUT_LABEL = nls.localize('label.replace', "Replace");
|
|
const NLS_REPLACE_INPUT_PLACEHOLDER = nls.localize('placeholder.replace', "Replace");
|
|
const NLS_REPLACE_BTN_LABEL = nls.localize('label.replaceButton', "Replace");
|
|
const NLS_REPLACE_ALL_BTN_LABEL = nls.localize('label.replaceAllButton', "Replace All");
|
|
const NLS_TOGGLE_REPLACE_MODE_BTN_LABEL = nls.localize('label.toggleReplaceButton', "Toggle Replace mode");
|
|
const NLS_MATCHES_COUNT_LIMIT_TITLE = nls.localize('title.matchesCountLimit', "Only the first {0} results are highlighted, but all find operations work on the entire text.", MATCHES_LIMIT);
|
|
const NLS_MATCHES_LOCATION = nls.localize('label.matchesLocation', "{0} of {1}");
|
|
const NLS_NO_RESULTS = nls.localize('label.noResults', "No Results");
|
|
|
|
const FIND_WIDGET_INITIAL_WIDTH = 411;
|
|
const PART_WIDTH = 275;
|
|
const FIND_INPUT_AREA_WIDTH = PART_WIDTH - 54;
|
|
const REPLACE_INPUT_AREA_WIDTH = FIND_INPUT_AREA_WIDTH;
|
|
|
|
let MAX_MATCHES_COUNT_WIDTH = 69;
|
|
let FIND_ALL_CONTROLS_WIDTH = 17/** Find Input margin-left */ + (MAX_MATCHES_COUNT_WIDTH + 3 + 1) /** Match Results */ + 23 /** Button */ * 4 + 2/** sash */;
|
|
|
|
const FIND_INPUT_AREA_HEIGHT = 34; // The height of Find Widget when Replace Input is not visible.
|
|
const FIND_REPLACE_AREA_HEIGHT = 64; // The height of Find Widget when Replace Input is visible.
|
|
|
|
|
|
export class FindWidgetViewZone implements IViewZone {
|
|
public readonly afterLineNumber: number;
|
|
public heightInPx: number;
|
|
public readonly suppressMouseDown: boolean;
|
|
public readonly domNode: HTMLElement;
|
|
|
|
constructor(afterLineNumber: number) {
|
|
this.afterLineNumber = afterLineNumber;
|
|
|
|
this.heightInPx = FIND_INPUT_AREA_HEIGHT;
|
|
this.suppressMouseDown = false;
|
|
this.domNode = document.createElement('div');
|
|
this.domNode.className = 'dock-find-viewzone';
|
|
}
|
|
}
|
|
|
|
export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSashLayoutProvider {
|
|
private static readonly ID = 'editor.contrib.findWidget';
|
|
private readonly _codeEditor: ICodeEditor;
|
|
private _state: FindReplaceState;
|
|
private _controller: IFindController;
|
|
private readonly _contextViewProvider: IContextViewProvider;
|
|
private readonly _keybindingService: IKeybindingService;
|
|
private readonly _contextKeyService: IContextKeyService;
|
|
|
|
private _domNode: HTMLElement;
|
|
private _findInput: FindInput;
|
|
private _replaceInputBox: HistoryInputBox;
|
|
|
|
private _toggleReplaceBtn: SimpleButton;
|
|
private _matchesCount: HTMLElement;
|
|
private _prevBtn: SimpleButton;
|
|
private _nextBtn: SimpleButton;
|
|
private _toggleSelectionFind: SimpleCheckbox;
|
|
private _closeBtn: SimpleButton;
|
|
private _replaceBtn: SimpleButton;
|
|
private _replaceAllBtn: SimpleButton;
|
|
|
|
private _isVisible: boolean;
|
|
private _isReplaceVisible: boolean;
|
|
|
|
private _findFocusTracker: dom.IFocusTracker;
|
|
private _findInputFocused: IContextKey<boolean>;
|
|
private _replaceFocusTracker: dom.IFocusTracker;
|
|
private _replaceInputFocused: IContextKey<boolean>;
|
|
private _viewZone: FindWidgetViewZone;
|
|
private _viewZoneId: number;
|
|
|
|
private _resizeSash: Sash;
|
|
private _resized: boolean;
|
|
private _updateHistoryDelayer: Delayer<void>;
|
|
|
|
constructor(
|
|
codeEditor: ICodeEditor,
|
|
controller: IFindController,
|
|
state: FindReplaceState,
|
|
contextViewProvider: IContextViewProvider,
|
|
keybindingService: IKeybindingService,
|
|
contextKeyService: IContextKeyService,
|
|
themeService: IThemeService
|
|
) {
|
|
super();
|
|
this._codeEditor = codeEditor;
|
|
this._controller = controller;
|
|
this._state = state;
|
|
this._contextViewProvider = contextViewProvider;
|
|
this._keybindingService = keybindingService;
|
|
this._contextKeyService = contextKeyService;
|
|
|
|
this._isVisible = false;
|
|
this._isReplaceVisible = false;
|
|
|
|
this._updateHistoryDelayer = new Delayer<void>(500);
|
|
this._register(this._state.onFindReplaceStateChange((e) => this._onStateChanged(e)));
|
|
this._buildDomNode();
|
|
this._updateButtons();
|
|
this._tryUpdateWidgetWidth();
|
|
|
|
this._register(this._codeEditor.onDidChangeConfiguration((e: IConfigurationChangedEvent) => {
|
|
if (e.readOnly) {
|
|
if (this._codeEditor.getConfiguration().readOnly) {
|
|
// Hide replace part if editor becomes read only
|
|
this._state.change({ isReplaceRevealed: false }, false);
|
|
}
|
|
this._updateButtons();
|
|
}
|
|
if (e.layoutInfo) {
|
|
this._tryUpdateWidgetWidth();
|
|
}
|
|
}));
|
|
this._register(this._codeEditor.onDidChangeCursorSelection(() => {
|
|
if (this._isVisible) {
|
|
this._updateToggleSelectionFindButton();
|
|
}
|
|
}));
|
|
this._register(this._codeEditor.onDidFocusEditorWidget(() => {
|
|
if (this._isVisible) {
|
|
let globalBufferTerm = this._controller.getGlobalBufferTerm();
|
|
if (globalBufferTerm && globalBufferTerm !== this._state.searchString) {
|
|
this._state.change({ searchString: globalBufferTerm }, true);
|
|
this._findInput.select();
|
|
}
|
|
}
|
|
}));
|
|
this._findInputFocused = CONTEXT_FIND_INPUT_FOCUSED.bindTo(contextKeyService);
|
|
this._findFocusTracker = this._register(dom.trackFocus(this._findInput.inputBox.inputElement));
|
|
this._register(this._findFocusTracker.onDidFocus(() => {
|
|
this._findInputFocused.set(true);
|
|
this._updateSearchScope();
|
|
}));
|
|
this._register(this._findFocusTracker.onDidBlur(() => {
|
|
this._findInputFocused.set(false);
|
|
}));
|
|
|
|
this._replaceInputFocused = CONTEXT_REPLACE_INPUT_FOCUSED.bindTo(contextKeyService);
|
|
this._replaceFocusTracker = this._register(dom.trackFocus(this._replaceInputBox.inputElement));
|
|
this._register(this._replaceFocusTracker.onDidFocus(() => {
|
|
this._replaceInputFocused.set(true);
|
|
this._updateSearchScope();
|
|
}));
|
|
this._register(this._replaceFocusTracker.onDidBlur(() => {
|
|
this._replaceInputFocused.set(false);
|
|
}));
|
|
|
|
this._codeEditor.addOverlayWidget(this);
|
|
this._viewZone = new FindWidgetViewZone(0); // Put it before the first line then users can scroll beyond the first line.
|
|
|
|
this._applyTheme(themeService.getTheme());
|
|
this._register(themeService.onThemeChange(this._applyTheme.bind(this)));
|
|
|
|
this._register(this._codeEditor.onDidChangeModel((e) => {
|
|
if (!this._isVisible) {
|
|
return;
|
|
}
|
|
|
|
if (this._viewZoneId === undefined) {
|
|
return;
|
|
}
|
|
|
|
this._codeEditor.changeViewZones((accessor) => {
|
|
accessor.removeZone(this._viewZoneId);
|
|
this._viewZoneId = undefined;
|
|
});
|
|
}));
|
|
|
|
|
|
this._register(this._codeEditor.onDidScrollChange((e) => {
|
|
if (e.scrollTopChanged) {
|
|
this._layoutViewZone();
|
|
return;
|
|
}
|
|
|
|
// for other scroll changes, layout the viewzone in next tick to avoid ruining current rendering.
|
|
setTimeout(() => {
|
|
this._layoutViewZone();
|
|
}, 0);
|
|
}));
|
|
}
|
|
|
|
// ----- IOverlayWidget API
|
|
|
|
public getId(): string {
|
|
return FindWidget.ID;
|
|
}
|
|
|
|
public getDomNode(): HTMLElement {
|
|
return this._domNode;
|
|
}
|
|
|
|
public getPosition(): IOverlayWidgetPosition {
|
|
if (this._isVisible) {
|
|
return {
|
|
preference: OverlayWidgetPositionPreference.TOP_RIGHT_CORNER
|
|
};
|
|
}
|
|
return null;
|
|
}
|
|
|
|
// ----- React to state changes
|
|
|
|
private _onStateChanged(e: FindReplaceStateChangedEvent): void {
|
|
if (e.searchString) {
|
|
this._findInput.setValue(this._state.searchString);
|
|
this._updateButtons();
|
|
}
|
|
if (e.replaceString) {
|
|
this._replaceInputBox.value = this._state.replaceString;
|
|
}
|
|
if (e.isRevealed) {
|
|
if (this._state.isRevealed) {
|
|
this._reveal(true);
|
|
} else {
|
|
this._hide(true);
|
|
}
|
|
}
|
|
if (e.isReplaceRevealed) {
|
|
if (this._state.isReplaceRevealed) {
|
|
if (!this._codeEditor.getConfiguration().readOnly && !this._isReplaceVisible) {
|
|
this._isReplaceVisible = true;
|
|
this._replaceInputBox.width = this._findInput.inputBox.width;
|
|
this._updateButtons();
|
|
}
|
|
} else {
|
|
if (this._isReplaceVisible) {
|
|
this._isReplaceVisible = false;
|
|
this._updateButtons();
|
|
}
|
|
}
|
|
}
|
|
if (e.isRegex) {
|
|
this._findInput.setRegex(this._state.isRegex);
|
|
}
|
|
if (e.wholeWord) {
|
|
this._findInput.setWholeWords(this._state.wholeWord);
|
|
}
|
|
if (e.matchCase) {
|
|
this._findInput.setCaseSensitive(this._state.matchCase);
|
|
}
|
|
if (e.searchScope) {
|
|
if (this._state.searchScope) {
|
|
this._toggleSelectionFind.checked = true;
|
|
} else {
|
|
this._toggleSelectionFind.checked = false;
|
|
}
|
|
this._updateToggleSelectionFindButton();
|
|
}
|
|
if (e.searchString || e.matchesCount || e.matchesPosition) {
|
|
let showRedOutline = (this._state.searchString.length > 0 && this._state.matchesCount === 0);
|
|
dom.toggleClass(this._domNode, 'no-results', showRedOutline);
|
|
|
|
this._updateMatchesCount();
|
|
}
|
|
if (e.searchString || e.currentMatch) {
|
|
this._layoutViewZone();
|
|
}
|
|
if (e.updateHistory) {
|
|
this._delayedUpdateHistory();
|
|
}
|
|
}
|
|
|
|
private _delayedUpdateHistory() {
|
|
this._updateHistoryDelayer.trigger(this._updateHistory.bind(this));
|
|
}
|
|
|
|
private _updateHistory() {
|
|
if (this._state.searchString) {
|
|
this._findInput.inputBox.addToHistory();
|
|
}
|
|
if (this._state.replaceString) {
|
|
this._replaceInputBox.addToHistory();
|
|
}
|
|
}
|
|
|
|
private _updateMatchesCount(): void {
|
|
this._matchesCount.style.minWidth = MAX_MATCHES_COUNT_WIDTH + 'px';
|
|
if (this._state.matchesCount >= MATCHES_LIMIT) {
|
|
this._matchesCount.title = NLS_MATCHES_COUNT_LIMIT_TITLE;
|
|
} else {
|
|
this._matchesCount.title = '';
|
|
}
|
|
|
|
// remove previous content
|
|
if (this._matchesCount.firstChild) {
|
|
this._matchesCount.removeChild(this._matchesCount.firstChild);
|
|
}
|
|
|
|
let label: string;
|
|
if (this._state.matchesCount > 0) {
|
|
let matchesCount: string = String(this._state.matchesCount);
|
|
if (this._state.matchesCount >= MATCHES_LIMIT) {
|
|
matchesCount += '+';
|
|
}
|
|
let matchesPosition: string = String(this._state.matchesPosition);
|
|
if (matchesPosition === '0') {
|
|
matchesPosition = '?';
|
|
}
|
|
label = strings.format(NLS_MATCHES_LOCATION, matchesPosition, matchesCount);
|
|
} else {
|
|
label = NLS_NO_RESULTS;
|
|
}
|
|
this._matchesCount.appendChild(document.createTextNode(label));
|
|
|
|
MAX_MATCHES_COUNT_WIDTH = Math.max(MAX_MATCHES_COUNT_WIDTH, this._matchesCount.clientWidth);
|
|
}
|
|
|
|
// ----- actions
|
|
|
|
/**
|
|
* If 'selection find' is ON we should not disable the button (its function is to cancel 'selection find').
|
|
* If 'selection find' is OFF we enable the button only if there is a selection.
|
|
*/
|
|
private _updateToggleSelectionFindButton(): void {
|
|
let selection = this._codeEditor.getSelection();
|
|
let isSelection = selection ? (selection.startLineNumber !== selection.endLineNumber || selection.startColumn !== selection.endColumn) : false;
|
|
let isChecked = this._toggleSelectionFind.checked;
|
|
|
|
this._toggleSelectionFind.setEnabled(this._isVisible && (isChecked || isSelection));
|
|
}
|
|
|
|
private _updateButtons(): void {
|
|
this._findInput.setEnabled(this._isVisible);
|
|
this._replaceInputBox.setEnabled(this._isVisible && this._isReplaceVisible);
|
|
this._updateToggleSelectionFindButton();
|
|
this._closeBtn.setEnabled(this._isVisible);
|
|
|
|
let findInputIsNonEmpty = (this._state.searchString.length > 0);
|
|
this._prevBtn.setEnabled(this._isVisible && findInputIsNonEmpty);
|
|
this._nextBtn.setEnabled(this._isVisible && findInputIsNonEmpty);
|
|
this._replaceBtn.setEnabled(this._isVisible && this._isReplaceVisible && findInputIsNonEmpty);
|
|
this._replaceAllBtn.setEnabled(this._isVisible && this._isReplaceVisible && findInputIsNonEmpty);
|
|
|
|
dom.toggleClass(this._domNode, 'replaceToggled', this._isReplaceVisible);
|
|
this._toggleReplaceBtn.toggleClass('collapse', !this._isReplaceVisible);
|
|
this._toggleReplaceBtn.toggleClass('expand', this._isReplaceVisible);
|
|
this._toggleReplaceBtn.setExpanded(this._isReplaceVisible);
|
|
|
|
let canReplace = !this._codeEditor.getConfiguration().readOnly;
|
|
this._toggleReplaceBtn.setEnabled(this._isVisible && canReplace);
|
|
}
|
|
|
|
private _reveal(animate: boolean): void {
|
|
if (!this._isVisible) {
|
|
this._isVisible = true;
|
|
|
|
let selection = this._codeEditor.getSelection();
|
|
let isSelection = selection ? (selection.startLineNumber !== selection.endLineNumber || selection.startColumn !== selection.endColumn) : false;
|
|
if (isSelection && this._codeEditor.getConfiguration().contribInfo.find.autoFindInSelection) {
|
|
this._toggleSelectionFind.checked = true;
|
|
} else {
|
|
this._toggleSelectionFind.checked = false;
|
|
}
|
|
this._tryUpdateWidgetWidth();
|
|
this._updateButtons();
|
|
|
|
setTimeout(() => {
|
|
dom.addClass(this._domNode, 'visible');
|
|
this._domNode.setAttribute('aria-hidden', 'false');
|
|
}, 0);
|
|
this._codeEditor.layoutOverlayWidget(this);
|
|
|
|
let adjustEditorScrollTop = true;
|
|
if (this._codeEditor.getConfiguration().contribInfo.find.seedSearchStringFromSelection && selection) {
|
|
let editorCoords = dom.getDomNodePagePosition(this._codeEditor.getDomNode());
|
|
let startCoords = this._codeEditor.getScrolledVisiblePosition(selection.getStartPosition());
|
|
let startLeft = editorCoords.left + startCoords.left;
|
|
let startTop = startCoords.top;
|
|
|
|
if (startTop < this._viewZone.heightInPx) {
|
|
if (selection.endLineNumber > selection.startLineNumber) {
|
|
adjustEditorScrollTop = false;
|
|
}
|
|
|
|
let leftOfFindWidget = dom.getTopLeftOffset(this._domNode).left;
|
|
if (startLeft > leftOfFindWidget) {
|
|
adjustEditorScrollTop = false;
|
|
}
|
|
let endCoords = this._codeEditor.getScrolledVisiblePosition(selection.getEndPosition());
|
|
let endLeft = editorCoords.left + endCoords.left;
|
|
if (endLeft > leftOfFindWidget) {
|
|
adjustEditorScrollTop = false;
|
|
}
|
|
}
|
|
}
|
|
this._showViewZone(adjustEditorScrollTop);
|
|
}
|
|
}
|
|
|
|
private _hide(focusTheEditor: boolean): void {
|
|
if (this._isVisible) {
|
|
this._isVisible = false;
|
|
|
|
this._updateButtons();
|
|
|
|
dom.removeClass(this._domNode, 'visible');
|
|
this._domNode.setAttribute('aria-hidden', 'true');
|
|
if (focusTheEditor) {
|
|
this._codeEditor.focus();
|
|
}
|
|
this._codeEditor.layoutOverlayWidget(this);
|
|
this._codeEditor.changeViewZones((accessor) => {
|
|
if (this._viewZoneId !== undefined) {
|
|
accessor.removeZone(this._viewZoneId);
|
|
this._viewZoneId = undefined;
|
|
this._codeEditor.setScrollTop(this._codeEditor.getScrollTop() - this._viewZone.heightInPx);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private _layoutViewZone() {
|
|
if (!this._isVisible) {
|
|
return;
|
|
}
|
|
|
|
if (this._viewZoneId !== undefined) {
|
|
return;
|
|
}
|
|
|
|
this._codeEditor.changeViewZones((accessor) => {
|
|
if (this._state.isReplaceRevealed) {
|
|
this._viewZone.heightInPx = FIND_REPLACE_AREA_HEIGHT;
|
|
} else {
|
|
this._viewZone.heightInPx = FIND_INPUT_AREA_HEIGHT;
|
|
}
|
|
|
|
this._viewZoneId = accessor.addZone(this._viewZone);
|
|
// scroll top adjust to make sure the editor doesn't scroll when adding viewzone at the beginning.
|
|
this._codeEditor.setScrollTop(this._codeEditor.getScrollTop() + this._viewZone.heightInPx);
|
|
});
|
|
}
|
|
|
|
private _showViewZone(adjustScroll: boolean = true) {
|
|
if (!this._isVisible) {
|
|
return;
|
|
}
|
|
|
|
this._codeEditor.changeViewZones((accessor) => {
|
|
let scrollAdjustment = FIND_INPUT_AREA_HEIGHT;
|
|
|
|
if (this._viewZoneId !== undefined) {
|
|
if (this._state.isReplaceRevealed) {
|
|
this._viewZone.heightInPx = FIND_REPLACE_AREA_HEIGHT;
|
|
scrollAdjustment = FIND_REPLACE_AREA_HEIGHT - FIND_INPUT_AREA_HEIGHT;
|
|
} else {
|
|
this._viewZone.heightInPx = FIND_INPUT_AREA_HEIGHT;
|
|
scrollAdjustment = FIND_INPUT_AREA_HEIGHT - FIND_REPLACE_AREA_HEIGHT;
|
|
}
|
|
accessor.removeZone(this._viewZoneId);
|
|
} else {
|
|
this._viewZone.heightInPx = FIND_INPUT_AREA_HEIGHT;
|
|
}
|
|
this._viewZoneId = accessor.addZone(this._viewZone);
|
|
|
|
if (adjustScroll) {
|
|
this._codeEditor.setScrollTop(this._codeEditor.getScrollTop() + scrollAdjustment);
|
|
}
|
|
});
|
|
}
|
|
|
|
private _applyTheme(theme: ITheme) {
|
|
let inputStyles: IFindInputStyles = {
|
|
inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder),
|
|
inputBackground: theme.getColor(inputBackground),
|
|
inputForeground: theme.getColor(inputForeground),
|
|
inputBorder: theme.getColor(inputBorder),
|
|
inputValidationInfoBackground: theme.getColor(inputValidationInfoBackground),
|
|
inputValidationInfoBorder: theme.getColor(inputValidationInfoBorder),
|
|
inputValidationWarningBackground: theme.getColor(inputValidationWarningBackground),
|
|
inputValidationWarningBorder: theme.getColor(inputValidationWarningBorder),
|
|
inputValidationErrorBackground: theme.getColor(inputValidationErrorBackground),
|
|
inputValidationErrorBorder: theme.getColor(inputValidationErrorBorder)
|
|
};
|
|
this._findInput.style(inputStyles);
|
|
this._replaceInputBox.style(inputStyles);
|
|
}
|
|
|
|
private _tryUpdateWidgetWidth() {
|
|
if (!this._isVisible) {
|
|
return;
|
|
}
|
|
let editorWidth = this._codeEditor.getConfiguration().layoutInfo.width;
|
|
let minimapWidth = this._codeEditor.getConfiguration().layoutInfo.minimapWidth;
|
|
let collapsedFindWidget = false;
|
|
let reducedFindWidget = false;
|
|
let narrowFindWidget = false;
|
|
|
|
if (this._resized) {
|
|
let widgetWidth = dom.getTotalWidth(this._domNode);
|
|
|
|
if (widgetWidth > FIND_WIDGET_INITIAL_WIDTH) {
|
|
// as the widget is resized by users, we may need to change the max width of the widget as the editor width changes.
|
|
this._domNode.style.maxWidth = `${editorWidth - 28 - minimapWidth - 15}px`;
|
|
this._replaceInputBox.inputElement.style.width = `${dom.getTotalWidth(this._findInput.inputBox.inputElement)}px`;
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (FIND_WIDGET_INITIAL_WIDTH + 28 + minimapWidth >= editorWidth) {
|
|
reducedFindWidget = true;
|
|
}
|
|
if (FIND_WIDGET_INITIAL_WIDTH + 28 + minimapWidth - MAX_MATCHES_COUNT_WIDTH >= editorWidth) {
|
|
narrowFindWidget = true;
|
|
}
|
|
if (FIND_WIDGET_INITIAL_WIDTH + 28 + minimapWidth - MAX_MATCHES_COUNT_WIDTH >= editorWidth + 50) {
|
|
collapsedFindWidget = true;
|
|
}
|
|
dom.toggleClass(this._domNode, 'collapsed-find-widget', collapsedFindWidget);
|
|
dom.toggleClass(this._domNode, 'narrow-find-widget', narrowFindWidget);
|
|
dom.toggleClass(this._domNode, 'reduced-find-widget', reducedFindWidget);
|
|
|
|
if (!narrowFindWidget && !collapsedFindWidget) {
|
|
// the minimal left offset of findwidget is 15px.
|
|
this._domNode.style.maxWidth = `${editorWidth - 28 - minimapWidth - 15}px`;
|
|
}
|
|
|
|
if (this._resized) {
|
|
let findInputWidth = dom.getTotalWidth(this._findInput.inputBox.inputElement);
|
|
if (findInputWidth > 0) {
|
|
this._replaceInputBox.inputElement.style.width = `${findInputWidth}px`;
|
|
}
|
|
}
|
|
}
|
|
|
|
// ----- Public
|
|
|
|
public focusFindInput(): void {
|
|
this._findInput.select();
|
|
// Edge browser requires focus() in addition to select()
|
|
this._findInput.focus();
|
|
}
|
|
|
|
public focusReplaceInput(): void {
|
|
this._replaceInputBox.select();
|
|
// Edge browser requires focus() in addition to select()
|
|
this._replaceInputBox.focus();
|
|
}
|
|
|
|
public highlightFindOptions(): void {
|
|
this._findInput.highlightFindOptions();
|
|
}
|
|
|
|
private _updateSearchScope(): void {
|
|
if (this._toggleSelectionFind.checked) {
|
|
let selection = this._codeEditor.getSelection();
|
|
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
|
|
selection = selection.setEndPosition(selection.endLineNumber - 1, 1);
|
|
}
|
|
let currentMatch = this._state.currentMatch;
|
|
if (selection.startLineNumber !== selection.endLineNumber) {
|
|
if (!Range.equalsRange(selection, currentMatch)) {
|
|
// Reseed find scope
|
|
this._state.change({ searchScope: selection }, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private _onFindInputMouseDown(e: IMouseEvent): void {
|
|
// on linux, middle key does pasting.
|
|
if (e.middleButton) {
|
|
e.stopPropagation();
|
|
}
|
|
}
|
|
|
|
private _onFindInputKeyDown(e: IKeyboardEvent): void {
|
|
|
|
if (e.equals(KeyCode.Enter)) {
|
|
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().done(null, onUnexpectedError);
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (e.equals(KeyMod.Shift | KeyCode.Enter)) {
|
|
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().done(null, onUnexpectedError);
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (e.equals(KeyCode.Tab)) {
|
|
if (this._isReplaceVisible) {
|
|
this._replaceInputBox.focus();
|
|
} else {
|
|
this._findInput.focusOnCaseSensitive();
|
|
}
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (e.equals(KeyMod.CtrlCmd | KeyCode.DownArrow)) {
|
|
this._codeEditor.focus();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private _onReplaceInputKeyDown(e: IKeyboardEvent): void {
|
|
|
|
if (e.equals(KeyCode.Enter)) {
|
|
this._controller.replace();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (e.equals(KeyMod.CtrlCmd | KeyCode.Enter)) {
|
|
this._controller.replaceAll();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (e.equals(KeyCode.Tab)) {
|
|
this._findInput.focusOnCaseSensitive();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (e.equals(KeyMod.Shift | KeyCode.Tab)) {
|
|
this._findInput.focus();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
|
|
if (e.equals(KeyMod.CtrlCmd | KeyCode.DownArrow)) {
|
|
this._codeEditor.focus();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// ----- sash
|
|
public getHorizontalSashTop(sash: Sash): number {
|
|
return 0;
|
|
}
|
|
public getHorizontalSashLeft?(sash: Sash): number {
|
|
return 0;
|
|
}
|
|
public getHorizontalSashWidth?(sash: Sash): number {
|
|
return 500;
|
|
}
|
|
|
|
// ----- initialization
|
|
|
|
private _keybindingLabelFor(actionId: string): string {
|
|
let kb = this._keybindingService.lookupKeybinding(actionId);
|
|
if (!kb) {
|
|
return '';
|
|
}
|
|
return ` (${kb.getLabel()})`;
|
|
}
|
|
|
|
private _buildFindPart(): HTMLElement {
|
|
// Find input
|
|
this._findInput = this._register(new ContextScopedFindInput(null, this._contextViewProvider, {
|
|
width: FIND_INPUT_AREA_WIDTH,
|
|
label: NLS_FIND_INPUT_LABEL,
|
|
placeholder: NLS_FIND_INPUT_PLACEHOLDER,
|
|
appendCaseSensitiveLabel: this._keybindingLabelFor(FIND_IDS.ToggleCaseSensitiveCommand),
|
|
appendWholeWordsLabel: this._keybindingLabelFor(FIND_IDS.ToggleWholeWordCommand),
|
|
appendRegexLabel: this._keybindingLabelFor(FIND_IDS.ToggleRegexCommand),
|
|
validation: (value: string): InputBoxMessage => {
|
|
if (value.length === 0) {
|
|
return null;
|
|
}
|
|
if (!this._findInput.getRegex()) {
|
|
return null;
|
|
}
|
|
try {
|
|
/* tslint:disable:no-unused-expression */
|
|
new RegExp(value);
|
|
/* tslint:enable:no-unused-expression */
|
|
return null;
|
|
} catch (e) {
|
|
return { content: e.message };
|
|
}
|
|
}
|
|
}, this._contextKeyService));
|
|
this._findInput.setRegex(!!this._state.isRegex);
|
|
this._findInput.setCaseSensitive(!!this._state.matchCase);
|
|
this._findInput.setWholeWords(!!this._state.wholeWord);
|
|
this._register(this._findInput.onKeyDown((e) => this._onFindInputKeyDown(e)));
|
|
this._register(this._findInput.inputBox.onDidChange(() => {
|
|
this._state.change({ searchString: this._findInput.getValue() }, true);
|
|
}));
|
|
this._register(this._findInput.onDidOptionChange(() => {
|
|
this._state.change({
|
|
isRegex: this._findInput.getRegex(),
|
|
wholeWord: this._findInput.getWholeWords(),
|
|
matchCase: this._findInput.getCaseSensitive()
|
|
}, true);
|
|
}));
|
|
this._register(this._findInput.onCaseSensitiveKeyDown((e) => {
|
|
if (e.equals(KeyMod.Shift | KeyCode.Tab)) {
|
|
if (this._isReplaceVisible) {
|
|
this._replaceInputBox.focus();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
}));
|
|
if (platform.isLinux) {
|
|
this._register(this._findInput.onMouseDown((e) => this._onFindInputMouseDown(e)));
|
|
}
|
|
|
|
this._matchesCount = document.createElement('div');
|
|
this._matchesCount.className = 'matchesCount';
|
|
this._updateMatchesCount();
|
|
|
|
// Previous button
|
|
this._prevBtn = this._register(new SimpleButton({
|
|
label: NLS_PREVIOUS_MATCH_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.PreviousMatchFindAction),
|
|
className: 'previous',
|
|
onTrigger: () => {
|
|
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().done(null, onUnexpectedError);
|
|
}
|
|
}));
|
|
|
|
// Next button
|
|
this._nextBtn = this._register(new SimpleButton({
|
|
label: NLS_NEXT_MATCH_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.NextMatchFindAction),
|
|
className: 'next',
|
|
onTrigger: () => {
|
|
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().done(null, onUnexpectedError);
|
|
}
|
|
}));
|
|
|
|
let findPart = document.createElement('div');
|
|
findPart.className = 'find-part';
|
|
findPart.appendChild(this._findInput.domNode);
|
|
findPart.appendChild(this._matchesCount);
|
|
findPart.appendChild(this._prevBtn.domNode);
|
|
findPart.appendChild(this._nextBtn.domNode);
|
|
|
|
// Toggle selection button
|
|
this._toggleSelectionFind = this._register(new SimpleCheckbox({
|
|
parent: findPart,
|
|
title: NLS_TOGGLE_SELECTION_FIND_TITLE + this._keybindingLabelFor(FIND_IDS.ToggleSearchScopeCommand),
|
|
onChange: () => {
|
|
if (this._toggleSelectionFind.checked) {
|
|
let selection = this._codeEditor.getSelection();
|
|
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
|
|
selection = selection.setEndPosition(selection.endLineNumber - 1, 1);
|
|
}
|
|
if (!selection.isEmpty()) {
|
|
this._state.change({ searchScope: selection }, true);
|
|
}
|
|
} else {
|
|
this._state.change({ searchScope: null }, true);
|
|
}
|
|
}
|
|
}));
|
|
|
|
// Close button
|
|
this._closeBtn = this._register(new SimpleButton({
|
|
label: NLS_CLOSE_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.CloseFindWidgetCommand),
|
|
className: 'close-fw',
|
|
onTrigger: () => {
|
|
this._state.change({ isRevealed: false, searchScope: null }, false);
|
|
},
|
|
onKeyDown: (e) => {
|
|
if (e.equals(KeyCode.Tab)) {
|
|
if (this._isReplaceVisible) {
|
|
if (this._replaceBtn.isEnabled()) {
|
|
this._replaceBtn.focus();
|
|
} else {
|
|
this._codeEditor.focus();
|
|
}
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
}
|
|
}));
|
|
|
|
findPart.appendChild(this._closeBtn.domNode);
|
|
|
|
return findPart;
|
|
}
|
|
|
|
private _buildReplacePart(): HTMLElement {
|
|
// Replace input
|
|
let replaceInput = document.createElement('div');
|
|
replaceInput.className = 'replace-input';
|
|
replaceInput.style.width = REPLACE_INPUT_AREA_WIDTH + 'px';
|
|
this._replaceInputBox = this._register(new ContextScopedHistoryInputBox(replaceInput, null, {
|
|
ariaLabel: NLS_REPLACE_INPUT_LABEL,
|
|
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
|
|
history: []
|
|
}, this._contextKeyService));
|
|
|
|
this._register(dom.addStandardDisposableListener(this._replaceInputBox.inputElement, 'keydown', (e) => this._onReplaceInputKeyDown(e)));
|
|
this._register(dom.addStandardDisposableListener(this._replaceInputBox.inputElement, 'input', (e) => {
|
|
this._state.change({ replaceString: this._replaceInputBox.value }, false);
|
|
}));
|
|
|
|
// Replace one button
|
|
this._replaceBtn = this._register(new SimpleButton({
|
|
label: NLS_REPLACE_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.ReplaceOneAction),
|
|
className: 'replace',
|
|
onTrigger: () => {
|
|
this._controller.replace();
|
|
},
|
|
onKeyDown: (e) => {
|
|
if (e.equals(KeyMod.Shift | KeyCode.Tab)) {
|
|
this._closeBtn.focus();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
}));
|
|
|
|
// Replace all button
|
|
this._replaceAllBtn = this._register(new SimpleButton({
|
|
label: NLS_REPLACE_ALL_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.ReplaceAllAction),
|
|
className: 'replace-all',
|
|
onTrigger: () => {
|
|
this._controller.replaceAll();
|
|
}
|
|
}));
|
|
|
|
let replacePart = document.createElement('div');
|
|
replacePart.className = 'replace-part';
|
|
replacePart.appendChild(replaceInput);
|
|
replacePart.appendChild(this._replaceBtn.domNode);
|
|
replacePart.appendChild(this._replaceAllBtn.domNode);
|
|
|
|
return replacePart;
|
|
}
|
|
|
|
private _buildDomNode(): void {
|
|
// Find part
|
|
let findPart = this._buildFindPart();
|
|
|
|
// Replace part
|
|
let replacePart = this._buildReplacePart();
|
|
|
|
// Toggle replace button
|
|
this._toggleReplaceBtn = this._register(new SimpleButton({
|
|
label: NLS_TOGGLE_REPLACE_MODE_BTN_LABEL,
|
|
className: 'toggle left',
|
|
onTrigger: () => {
|
|
this._state.change({ isReplaceRevealed: !this._isReplaceVisible }, false);
|
|
if (this._isReplaceVisible) {
|
|
this._replaceInputBox.width = this._findInput.inputBox.width;
|
|
}
|
|
this._showViewZone();
|
|
}
|
|
}));
|
|
this._toggleReplaceBtn.toggleClass('expand', this._isReplaceVisible);
|
|
this._toggleReplaceBtn.toggleClass('collapse', !this._isReplaceVisible);
|
|
this._toggleReplaceBtn.setExpanded(this._isReplaceVisible);
|
|
|
|
// Widget
|
|
this._domNode = document.createElement('div');
|
|
this._domNode.className = 'editor-widget find-widget';
|
|
this._domNode.setAttribute('aria-hidden', 'true');
|
|
// We need to set this explicitly, otherwise on IE11, the width inheritence of flex doesn't work.
|
|
this._domNode.style.width = `${FIND_WIDGET_INITIAL_WIDTH}px`;
|
|
|
|
this._domNode.appendChild(this._toggleReplaceBtn.domNode);
|
|
this._domNode.appendChild(findPart);
|
|
this._domNode.appendChild(replacePart);
|
|
|
|
this._buildSash();
|
|
}
|
|
|
|
private _buildSash() {
|
|
this._resizeSash = new Sash(this._domNode, this, { orientation: Orientation.VERTICAL });
|
|
this._resized = false;
|
|
let originalWidth = FIND_WIDGET_INITIAL_WIDTH;
|
|
|
|
this._register(this._resizeSash.onDidStart((e: ISashEvent) => {
|
|
originalWidth = dom.getTotalWidth(this._domNode);
|
|
}));
|
|
|
|
this._register(this._resizeSash.onDidChange((evt: ISashEvent) => {
|
|
this._resized = true;
|
|
let width = originalWidth + evt.startX - evt.currentX;
|
|
|
|
if (width < FIND_WIDGET_INITIAL_WIDTH) {
|
|
// narrow down the find widget should be handled by CSS.
|
|
return;
|
|
}
|
|
|
|
let inputBoxWidth = width - FIND_ALL_CONTROLS_WIDTH;
|
|
let maxWidth = parseFloat(dom.getComputedStyle(this._domNode).maxWidth) || 0;
|
|
if (width > maxWidth) {
|
|
return;
|
|
}
|
|
this._domNode.style.width = `${width}px`;
|
|
if (this._isReplaceVisible) {
|
|
this._replaceInputBox.width = inputBoxWidth;
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
|
|
interface ISimpleCheckboxOpts {
|
|
readonly parent: HTMLElement;
|
|
readonly title: string;
|
|
readonly onChange: () => void;
|
|
}
|
|
|
|
class SimpleCheckbox extends Widget {
|
|
|
|
private static _COUNTER = 0;
|
|
|
|
private readonly _opts: ISimpleCheckboxOpts;
|
|
private readonly _domNode: HTMLElement;
|
|
private readonly _checkbox: HTMLInputElement;
|
|
private readonly _label: HTMLLabelElement;
|
|
|
|
constructor(opts: ISimpleCheckboxOpts) {
|
|
super();
|
|
this._opts = opts;
|
|
|
|
this._domNode = document.createElement('div');
|
|
this._domNode.className = 'monaco-checkbox';
|
|
this._domNode.title = this._opts.title;
|
|
this._domNode.tabIndex = 0;
|
|
|
|
this._checkbox = document.createElement('input');
|
|
this._checkbox.type = 'checkbox';
|
|
this._checkbox.className = 'checkbox';
|
|
this._checkbox.id = 'checkbox-' + SimpleCheckbox._COUNTER++;
|
|
this._checkbox.tabIndex = -1;
|
|
|
|
this._label = document.createElement('label');
|
|
this._label.className = 'label';
|
|
// Connect the label and the checkbox. Checkbox will get checked when the label receives a click.
|
|
this._label.htmlFor = this._checkbox.id;
|
|
this._label.tabIndex = -1;
|
|
|
|
this._domNode.appendChild(this._checkbox);
|
|
this._domNode.appendChild(this._label);
|
|
|
|
this._opts.parent.appendChild(this._domNode);
|
|
|
|
this.onchange(this._checkbox, (e) => {
|
|
this._opts.onChange();
|
|
});
|
|
}
|
|
|
|
public get domNode(): HTMLElement {
|
|
return this._domNode;
|
|
}
|
|
|
|
public get checked(): boolean {
|
|
return this._checkbox.checked;
|
|
}
|
|
|
|
public set checked(newValue: boolean) {
|
|
this._checkbox.checked = newValue;
|
|
}
|
|
|
|
public focus(): void {
|
|
this._checkbox.focus();
|
|
}
|
|
|
|
private enable(): void {
|
|
this._checkbox.removeAttribute('disabled');
|
|
}
|
|
|
|
private disable(): void {
|
|
this._checkbox.disabled = true;
|
|
}
|
|
|
|
public setEnabled(enabled: boolean): void {
|
|
if (enabled) {
|
|
this.enable();
|
|
this.domNode.tabIndex = 0;
|
|
} else {
|
|
this.disable();
|
|
this.domNode.tabIndex = -1;
|
|
}
|
|
}
|
|
}
|
|
|
|
export interface ISimpleButtonOpts {
|
|
readonly label: string;
|
|
readonly className: string;
|
|
readonly onTrigger: () => void;
|
|
readonly onKeyDown?: (e: IKeyboardEvent) => void;
|
|
}
|
|
|
|
export class SimpleButton extends Widget {
|
|
|
|
private readonly _opts: ISimpleButtonOpts;
|
|
private readonly _domNode: HTMLElement;
|
|
|
|
constructor(opts: ISimpleButtonOpts) {
|
|
super();
|
|
this._opts = opts;
|
|
|
|
this._domNode = document.createElement('div');
|
|
this._domNode.title = this._opts.label;
|
|
this._domNode.tabIndex = 0;
|
|
this._domNode.className = 'button ' + this._opts.className;
|
|
this._domNode.setAttribute('role', 'button');
|
|
this._domNode.setAttribute('aria-label', this._opts.label);
|
|
|
|
this.onclick(this._domNode, (e) => {
|
|
this._opts.onTrigger();
|
|
e.preventDefault();
|
|
});
|
|
|
|
this.onkeydown(this._domNode, (e) => {
|
|
if (e.equals(KeyCode.Space) || e.equals(KeyCode.Enter)) {
|
|
this._opts.onTrigger();
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
if (this._opts.onKeyDown) {
|
|
this._opts.onKeyDown(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
public get domNode(): HTMLElement {
|
|
return this._domNode;
|
|
}
|
|
|
|
public isEnabled(): boolean {
|
|
return (this._domNode.tabIndex >= 0);
|
|
}
|
|
|
|
public focus(): void {
|
|
this._domNode.focus();
|
|
}
|
|
|
|
public setEnabled(enabled: boolean): void {
|
|
dom.toggleClass(this._domNode, 'disabled', !enabled);
|
|
this._domNode.setAttribute('aria-disabled', String(!enabled));
|
|
this._domNode.tabIndex = enabled ? 0 : -1;
|
|
}
|
|
|
|
public setExpanded(expanded: boolean): void {
|
|
this._domNode.setAttribute('aria-expanded', String(!!expanded));
|
|
}
|
|
|
|
public toggleClass(className: string, shouldHaveIt: boolean): void {
|
|
dom.toggleClass(this._domNode, className, shouldHaveIt);
|
|
}
|
|
}
|
|
|
|
// theming
|
|
|
|
registerThemingParticipant((theme, collector) => {
|
|
const addBackgroundColorRule = (selector: string, color: Color): void => {
|
|
if (color) {
|
|
collector.addRule(`.monaco-editor ${selector} { background-color: ${color}; }`);
|
|
}
|
|
};
|
|
|
|
addBackgroundColorRule('.findMatch', theme.getColor(editorFindMatchHighlight));
|
|
addBackgroundColorRule('.currentFindMatch', theme.getColor(editorFindMatch));
|
|
addBackgroundColorRule('.findScope', theme.getColor(editorFindRangeHighlight));
|
|
|
|
const widgetBackground = theme.getColor(editorWidgetBackground);
|
|
addBackgroundColorRule('.find-widget', widgetBackground);
|
|
|
|
const widgetShadowColor = theme.getColor(widgetShadow);
|
|
if (widgetShadowColor) {
|
|
collector.addRule(`.monaco-editor .find-widget { box-shadow: 0 2px 8px ${widgetShadowColor}; }`);
|
|
}
|
|
|
|
const findMatchHighlightBorder = theme.getColor(editorFindMatchHighlightBorder);
|
|
if (findMatchHighlightBorder) {
|
|
collector.addRule(`.monaco-editor .findMatch { border: 1px ${theme.type === 'hc' ? 'dotted' : 'solid'} ${findMatchHighlightBorder}; box-sizing: border-box; }`);
|
|
}
|
|
|
|
const findMatchBorder = theme.getColor(editorFindMatchBorder);
|
|
if (findMatchBorder) {
|
|
collector.addRule(`.monaco-editor .currentFindMatch { border: 2px solid ${findMatchBorder}; padding: 1px; box-sizing: border-box; }`);
|
|
}
|
|
|
|
const findRangeHighlightBorder = theme.getColor(editorFindRangeHighlightBorder);
|
|
if (findRangeHighlightBorder) {
|
|
collector.addRule(`.monaco-editor .findScope { border: 1px ${theme.type === 'hc' ? 'dashed' : 'solid'} ${findRangeHighlightBorder}; }`);
|
|
}
|
|
|
|
const hcBorder = theme.getColor(contrastBorder);
|
|
if (hcBorder) {
|
|
collector.addRule(`.monaco-editor .find-widget { border: 2px solid ${hcBorder}; }`);
|
|
}
|
|
|
|
const error = theme.getColor(errorForeground);
|
|
if (error) {
|
|
collector.addRule(`.monaco-editor .find-widget.no-results .matchesCount { color: ${error}; }`);
|
|
}
|
|
|
|
const resizeBorderBackground = theme.getColor(editorWidgetResizeBorder);
|
|
if (resizeBorderBackground) {
|
|
collector.addRule(`.monaco-editor .find-widget .monaco-sash { background-color: ${resizeBorderBackground}; width: 3px !important; margin-left: -4px;}`);
|
|
} else {
|
|
const border = theme.getColor(editorWidgetBorder);
|
|
if (border) {
|
|
collector.addRule(`.monaco-editor .find-widget .monaco-sash { background-color: ${border}; width: 3px !important; margin-left: -4px;}`);
|
|
}
|
|
}
|
|
|
|
});
|