-
Notifications
You must be signed in to change notification settings - Fork 40k
FindWidget/TerminalFindWidget: Provide random access to search matches via an inline "Nth Match" input field. #309109
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
Open
boborrob
wants to merge
21
commits into
microsoft:main
Choose a base branch
from
boborrob:findWidget_terminalFindWidget-arbitrary_access_to_matches
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
90dc328
findWidget - Editable Match Location Field:
32eeec1
findWidget - Editable Match Location Field:
622de8f
findWidget - Iterating and Misc. Improvements
ceda74b
findWidget - More Iteration and Cleanup
7da8071
simpleFindWidget - Add Nth Match support to the terminal's finder wid…
f272897
simpleFindWidget - Nth Match Support:
119f812
findWidget - Nth Match Support:
d366cfc
findWidget / simpleFindWidget: Merging changes
boborrob 9c2c341
findWidget / terminalFindWidget: Add inline "Find Nth" functionality …
boborrob 11d593c
findWidget / terminalFindWidget: Add inline, "Find Nth" functionality…
boborrob e607e3e
11.2.0
boborrob ee61f36
findWidget / terminalFindWidget: Stress Testing
boborrob fd67d22
Merge branch 'main' into clean_branch-findWidget_terminalFindWidget
boborrob ee803a0
Merge branch 'main' into findWidget_terminalFindWidget-arbitrary_acce…
boborrob 4449e9a
Merge branch 'main' into findWidget_terminalFindWidget-arbitrary_acce…
boborrob 2ed6713
findWidget / terminalFindWidget: More alignment
boborrob 8899bf0
findWidget / terminalFindWidget: Consolidate nthMatchInput styles and…
boborrob d5b4bb8
Merge branch 'main' into findWidget_terminalFindWidget-arbitrary_acce…
boborrob 1e582d2
findWidget/terminalFindWidget: More enhancements
boborrob 173ac8a
findWidget/terminalFindWidget: Last Match Button
boborrob 44a944a
findWidget/terminalFindWidget: Code Review - 1st Iteration
boborrob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const MATCHES_LIMIT = 19999; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
|
|
||
| /* ---------- Nth Match Input - FindWidget ---------- */ | ||
| .nth-match { | ||
| width: 45px; | ||
| min-width: 45px; | ||
| max-width: 60px; | ||
| background-color: var(--vscode-input-background); | ||
| color: var(--vscode-input-foreground); | ||
| bottom: 1.5px; | ||
| margin-right: 10px; | ||
| transition: width 300ms ease; | ||
| } | ||
|
|
||
| .nth-match.elongated { | ||
| width: 60px; | ||
| } | ||
|
|
||
| .nth-match input { | ||
| text-align: center; | ||
| overflow-x: hidden; | ||
| text-overflow: clip; | ||
| font-size: 12px; | ||
| } | ||
|
|
||
|
|
||
| /* ---------- Nth Match Input - SimpleFindWidget ---------- */ | ||
| .nth-match.simple-nth-match { | ||
| bottom: unset; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import * as dom from '../../dom.js'; | ||
| import { IKeyboardEvent } from '../../keyboardEvent.js'; | ||
| import { IMouseEvent } from '../../mouseEvent.js'; | ||
| import { IContextViewProvider } from '../contextview/contextview.js'; | ||
| import { InputBox, IInputBoxStyles, IMessage as InputBoxMessage } from '../inputbox/inputBox.js'; | ||
| import { Widget } from '../widget.js'; | ||
| import { Emitter, Event } from '../../../common/event.js'; | ||
| import { KeyCode } from '../../../common/keyCodes.js'; | ||
| import './nthMatchInput.css'; | ||
| import * as nls from '../../../../nls.js'; | ||
| import { MATCHES_LIMIT } from './findContants.js'; | ||
|
|
||
| export interface INthMatchInputOptions { | ||
| readonly placeholder?: string; | ||
| readonly tooltip?: string; | ||
| readonly label: string; | ||
| readonly type: 'text'; | ||
| readonly min?: number; | ||
| readonly max?: number; | ||
|
|
||
| readonly inputBoxStyles: IInputBoxStyles; | ||
| } | ||
|
|
||
| export interface IStepEvent { | ||
| to: 'previous' | 'next'; | ||
| } | ||
|
|
||
| const NLS_DEFAULT_LABEL = nls.localize('defaultLabel', "input"); | ||
|
|
||
| export class NthMatchInput extends Widget { | ||
|
|
||
| private placeholder: string; | ||
| private tooltip: string; | ||
| private label: string; | ||
| private type: string; | ||
| private imeSessionInProgress = false; | ||
|
|
||
| public readonly domNode: HTMLElement; | ||
| public readonly inputBox: InputBox; | ||
| public min: number; | ||
| public max: number; | ||
|
|
||
| private readonly _onDidOptionChange = this._register(new Emitter<boolean>()); | ||
| public readonly onDidOptionChange: Event<boolean /* via keyboard */> = this._onDidOptionChange.event; | ||
|
|
||
| private readonly _onKeyDown = this._register(new Emitter<IKeyboardEvent>()); | ||
| public readonly onKeyDown: Event<IKeyboardEvent> = this._onKeyDown.event; | ||
|
|
||
| private readonly _onMouseDown = this._register(new Emitter<IMouseEvent>()); | ||
| public readonly onMouseDown: Event<IMouseEvent> = this._onMouseDown.event; | ||
|
|
||
| private readonly _onInput = this._register(new Emitter<void>()); | ||
| public readonly onInput: Event<void> = this._onInput.event; | ||
|
|
||
| private readonly _onKeyUp = this._register(new Emitter<IKeyboardEvent>()); | ||
| public readonly onKeyUp: Event<IKeyboardEvent> = this._onKeyUp.event; | ||
|
|
||
| private readonly _onStep = this._register(new Emitter<IStepEvent>()); | ||
| public readonly onStep: Event<IStepEvent> = this._onStep.event; | ||
|
|
||
|
|
||
| constructor(parent: HTMLElement | null, contextViewProvider: IContextViewProvider | undefined, options: INthMatchInputOptions) { | ||
| super(); | ||
| this.placeholder = options.placeholder || ''; | ||
| this.tooltip = options.tooltip || ''; | ||
| this.label = options.label || NLS_DEFAULT_LABEL; | ||
| this.type = options.type || 'text'; | ||
| this.min = options.min || 1; | ||
| this.max = options.max || MATCHES_LIMIT; | ||
|
|
||
| this.domNode = document.createElement('div'); | ||
| this.domNode.classList.add('monaco-findInput'); | ||
|
|
||
| this.inputBox = this._register(new InputBox(this.domNode, contextViewProvider, { | ||
| placeholder: this.placeholder || '', | ||
| tooltip: this.tooltip || '', | ||
| ariaLabel: this.label || '', | ||
| inputBoxStyles: options.inputBoxStyles, | ||
| type: this.type | ||
| })); | ||
|
|
||
| this.onkeydown(this.domNode, (event: IKeyboardEvent) => { | ||
| // Arrow-Key support for stepping to the previous match or to the next one. | ||
| if (event.equals(KeyCode.UpArrow)) { | ||
| this._onStep.fire({ to: 'previous' }); | ||
| } | ||
| else if (event.equals(KeyCode.DownArrow)) { | ||
| this._onStep.fire({ to: 'next' }); | ||
| } | ||
| }); | ||
|
|
||
| this.onchange(this.domNode, () => { | ||
| this.updateInputWrapperWidth(); | ||
| }); | ||
|
|
||
| parent?.appendChild(this.domNode); | ||
|
|
||
| this._register(dom.addDisposableListener(this.inputBox.inputElement, 'compositionstart', (e: CompositionEvent) => { | ||
| this.imeSessionInProgress = true; | ||
| })); | ||
| this._register(dom.addDisposableListener(this.inputBox.inputElement, 'compositionend', (e: CompositionEvent) => { | ||
| this.imeSessionInProgress = false; | ||
| this._onInput.fire(); | ||
| })); | ||
|
|
||
| this.onkeydown(this.inputBox.inputElement, (e) => this._onKeyDown.fire(e)); | ||
| this.onkeyup(this.inputBox.inputElement, (e) => this._onKeyUp.fire(e)); | ||
| this.oninput(this.inputBox.inputElement, (e) => this._onInput.fire()); | ||
| this.onmousedown(this.inputBox.inputElement, (e) => this._onMouseDown.fire(e)); | ||
| } | ||
|
|
||
| public get isImeSessionInProgress(): boolean { | ||
| return this.imeSessionInProgress; | ||
| } | ||
|
|
||
| public get onDidChange(): Event<string> { | ||
| return this.inputBox.onDidChange; | ||
| } | ||
|
|
||
| public layout(style: { collapsedFindWidget: boolean; narrowFindWidget: boolean; reducedFindWidget: boolean }) { | ||
| this.inputBox.layout(); | ||
| this.updateInputBoxPadding(style.collapsedFindWidget); | ||
| this.updateInputWrapperWidth(); | ||
| } | ||
|
|
||
| public updateInputWrapperWidth() { | ||
| const currentInputValue = `${this.getSanitizedCurrentValue()}`; | ||
| const containerElem = (this.inputBox.element.parentElement as HTMLElement); | ||
| if ((currentInputValue.length >= 5)) { | ||
| if (!containerElem.classList.contains('elongated')) { | ||
| containerElem.classList.add(...['elongated']); | ||
| } | ||
| } | ||
| else if (currentInputValue.length <= 4) { | ||
| if (containerElem.classList.contains('elongated')) { | ||
| containerElem.classList.remove(...['elongated']); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public enable(): void { | ||
| this.domNode.classList.remove('disabled'); | ||
| this.inputBox.enable(); | ||
| } | ||
|
|
||
| public disable(): void { | ||
| this.domNode.classList.add('disabled'); | ||
| this.inputBox.disable(); | ||
| } | ||
|
|
||
| public setEnabled(enabled: boolean): void { | ||
| if (enabled) { | ||
| this.enable(); | ||
| } else { | ||
| this.disable(); | ||
| } | ||
| } | ||
|
|
||
| private updateInputBoxPadding(controlsHidden = false) { | ||
| if (controlsHidden) { | ||
| this.inputBox.paddingRight = 0; | ||
| } else { | ||
| this.inputBox.paddingRight = 0; | ||
| } | ||
| } | ||
|
|
||
| public clear(): void { | ||
| this.clearValidation(); | ||
| this.setValue(''); | ||
| this.focus(); | ||
| } | ||
|
|
||
| public getValue(): string { | ||
| return this.inputBox.value; | ||
| } | ||
|
|
||
| public setValue(value: string): void { | ||
| if (this.inputBox.value !== value) { | ||
| this.inputBox.value = value; | ||
| } | ||
| this.updateInputWrapperWidth(); | ||
| } | ||
|
|
||
| public select(): void { | ||
| this.inputBox.select(); | ||
| } | ||
|
|
||
| public focus(): void { | ||
| this.inputBox.focus(); | ||
| } | ||
|
|
||
| public validate(): void { | ||
| this.inputBox.validate(); | ||
| } | ||
|
|
||
| public showMessage(message: InputBoxMessage): void { | ||
| this.inputBox.showMessage(message); | ||
| } | ||
|
|
||
| public clearMessage(): void { | ||
| this.inputBox.hideMessage(); | ||
| } | ||
|
|
||
| private clearValidation(): void { | ||
| this.inputBox.hideMessage(); | ||
| } | ||
|
|
||
| public getSanitizedCurrentValue(): number { | ||
| if (!this || !this.getValue()) { | ||
| return this.min; | ||
| } | ||
|
|
||
| // Enforce the numerical input and min/max constraints here. | ||
| const currentValueAsInt = parseInt(this.getValue(), 10); | ||
| return isNaN(currentValueAsInt) ? | ||
| this.min : currentValueAsInt > this.max ? | ||
| this.max : currentValueAsInt < this.min ? | ||
| this.min : currentValueAsInt; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.