Merge VS Code 1.31.1 (#4283)

This commit is contained in:
Matt Irvine
2019-03-15 13:09:45 -07:00
committed by GitHub
parent 7d31575149
commit 86bac90001
1716 changed files with 53308 additions and 48375 deletions

View File

@@ -28,9 +28,12 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
const SEARCH_STRING_MAX_LENGTH = 524288;
export function getSelectionSearchString(editor: ICodeEditor): string {
let selection = editor.getSelection();
export function getSelectionSearchString(editor: ICodeEditor): string | null {
if (!editor.hasModel()) {
return null;
}
const selection = editor.getSelection();
// if selection spans multiple lines, default search string to empty
if (selection.startLineNumber === selection.endLineNumber) {
if (selection.isEmpty()) {
@@ -71,7 +74,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
private _findWidgetVisible: IContextKey<boolean>;
protected _state: FindReplaceState;
protected _updateHistoryDelayer: Delayer<void>;
private _model: FindModelBoundToEditorModel;
private _model: FindModelBoundToEditorModel | null;
private _storageService: IStorageService;
private _clipboardService: IClipboardService;
protected readonly _contextKeyService: IContextKeyService;
@@ -178,7 +181,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
}
public isFindInputFocused(): boolean {
return CONTEXT_FIND_INPUT_FOCUSED.getValue(this._contextKeyService);
return !!CONTEXT_FIND_INPUT_FOCUSED.getValue(this._contextKeyService);
}
public getState(): FindReplaceState {
@@ -218,12 +221,14 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
if (this._state.searchScope) {
this._state.change({ searchScope: null }, true);
} else {
let selection = this._editor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, this._editor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
if (!selection.isEmpty()) {
this._state.change({ searchScope: selection }, true);
if (this._editor.hasModel()) {
let selection = this._editor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, this._editor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
if (!selection.isEmpty()) {
this._state.change({ searchScope: selection }, true);
}
}
}
}
@@ -242,7 +247,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
protected _start(opts: IFindStartOptions): void {
this.disposeModel();
if (!this._editor.getModel()) {
if (!this._editor.hasModel()) {
// cannot do anything with an editor that doesn't have a model...
return;
}
@@ -338,6 +343,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
public getGlobalBufferTerm(): string {
if (this._editor.getConfiguration().contribInfo.find.globalFindClipboard
&& this._clipboardService
&& this._editor.hasModel()
&& !this._editor.getModel().isTooLargeForSyncing()
) {
return this._clipboardService.readFindText();
@@ -348,6 +354,7 @@ export class CommonFindController extends Disposable implements editorCommon.IEd
public setGlobalBufferTerm(text: string) {
if (this._editor.getConfiguration().contribInfo.find.globalFindClipboard
&& this._clipboardService
&& this._editor.hasModel()
&& !this._editor.getModel().isTooLargeForSyncing()
) {
this._clipboardService.writeFindText(text);
@@ -430,7 +437,7 @@ export class StartFindAction extends EditorAction {
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
let controller = CommonFindController.get(editor);
if (controller) {
controller.start({
@@ -481,7 +488,7 @@ export class StartFindWithSelectionAction extends EditorAction {
}
}
export abstract class MatchFindAction extends EditorAction {
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
let controller = CommonFindController.get(editor);
if (controller && !this._run(controller)) {
controller.start({
@@ -544,7 +551,7 @@ export class PreviousMatchFindAction extends MatchFindAction {
}
export abstract class SelectionMatchFindAction extends EditorAction {
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
let controller = CommonFindController.get(editor);
if (!controller) {
return;
@@ -634,8 +641,8 @@ export class StartFindReplaceAction extends EditorAction {
});
}
public run(accessor: ServicesAccessor, editor: ICodeEditor): void {
if (editor.getConfiguration().readOnly) {
public run(accessor: ServicesAccessor | null, editor: ICodeEditor): void {
if (!editor.hasModel() || editor.getConfiguration().readOnly) {
return;
}

View File

@@ -80,8 +80,7 @@ export class FindDecorations implements IDisposable {
public getCurrentMatchesPosition(desiredRange: Range): number {
let candidates = this._editor.getModel().getDecorationsInRange(desiredRange);
for (let i = 0, len = candidates.length; i < len; i++) {
const candidate = candidates[i];
for (const candidate of candidates) {
const candidateOpts = candidate.options;
if (candidateOpts === FindDecorations._FIND_MATCH_DECORATION || candidateOpts === FindDecorations._CURRENT_FIND_MATCH_DECORATION) {
return this._getDecorationIndex(candidate.id);

View File

@@ -131,7 +131,7 @@ export class FindModelBoundToEditorModel {
// The find model is disposed during a find state changed event
return;
}
if (!this._editor.getModel()) {
if (!this._editor.hasModel()) {
// The find model will be disposed momentarily
return;
}

View File

@@ -46,7 +46,7 @@ export class FindOptionsWidget extends Widget implements IOverlayWidget {
this._domNode.setAttribute('role', 'presentation');
this._domNode.setAttribute('aria-hidden', 'true');
let inputActiveOptionBorderColor = themeService.getTheme().getColor(inputActiveOptionBorder);
const inputActiveOptionBorderColor = themeService.getTheme().getColor(inputActiveOptionBorder) || undefined;
this.caseSensitive = this._register(new CaseSensitiveCheckbox({
appendTitle: this._keybindingLabelFor(FIND_IDS.ToggleCaseSensitiveCommand),
@@ -179,7 +179,7 @@ export class FindOptionsWidget extends Widget implements IOverlayWidget {
}
private _applyTheme(theme: ITheme) {
let inputStyles = { inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder) };
let inputStyles = { inputActiveOptionBorder: theme.getColor(inputActiveOptionBorder) || undefined };
this.caseSensitive.style(inputStyles);
this.wholeWords.style(inputStyles);
this.regex.style(inputStyles);

View File

@@ -41,7 +41,7 @@ export interface INewFindReplaceState {
wholeWordOverride?: FindOptionOverride;
matchCase?: boolean;
matchCaseOverride?: FindOptionOverride;
searchScope?: Range;
searchScope?: Range | null;
}
function effectiveOptionValue(override: FindOptionOverride, value: boolean): boolean {

View File

@@ -111,7 +111,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
private _replaceFocusTracker: dom.IFocusTracker;
private _replaceInputFocused: IContextKey<boolean>;
private _viewZone: FindWidgetViewZone;
private _viewZoneId: number;
private _viewZoneId?: number;
private _resizeSash: Sash;
private _resized: boolean;
@@ -210,7 +210,9 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return;
}
this._codeEditor.changeViewZones((accessor) => {
accessor.removeZone(this._viewZoneId);
if (this._viewZoneId) {
accessor.removeZone(this._viewZoneId);
}
this._viewZoneId = undefined;
});
}));
@@ -239,7 +241,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return this._domNode;
}
public getPosition(): IOverlayWidgetPosition {
public getPosition(): IOverlayWidgetPosition | null {
if (this._isVisible) {
return {
preference: OverlayWidgetPositionPreference.TOP_RIGHT_CORNER
@@ -401,8 +403,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
if (!this._isVisible) {
this._isVisible = true;
let selection = this._codeEditor.getSelection();
let isSelection = selection ? (selection.startLineNumber !== selection.endLineNumber || selection.startColumn !== selection.endColumn) : false;
const selection = this._codeEditor.getSelection();
const isSelection = selection ? (selection.startLineNumber !== selection.endLineNumber || selection.startColumn !== selection.endColumn) : false;
if (isSelection && this._codeEditor.getConfiguration().contribInfo.find.autoFindInSelection) {
this._toggleSelectionFind.checked = true;
} else {
@@ -425,24 +427,27 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
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;
const domNode = this._codeEditor.getDomNode();
if (domNode) {
const editorCoords = dom.getDomNodePagePosition(domNode);
const startCoords = this._codeEditor.getScrolledVisiblePosition(selection.getStartPosition());
const startLeft = editorCoords.left + (startCoords ? startCoords.left : 0);
const startTop = startCoords ? startCoords.top : 0;
if (startTop < this._viewZone.heightInPx) {
if (selection.endLineNumber > selection.startLineNumber) {
adjustEditorScrollTop = false;
}
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;
const leftOfFindWidget = dom.getTopLeftOffset(this._domNode).left;
if (startLeft > leftOfFindWidget) {
adjustEditorScrollTop = false;
}
const endCoords = this._codeEditor.getScrolledVisiblePosition(selection.getEndPosition());
const endLeft = editorCoords.left + (endCoords ? endCoords.left : 0);
if (endLeft > leftOfFindWidget) {
adjustEditorScrollTop = false;
}
}
}
}
@@ -609,12 +614,16 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
}
private _updateSearchScope(): void {
if (!this._codeEditor.hasModel()) {
return;
}
if (this._toggleSelectionFind.checked) {
let selection = this._codeEditor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, this._codeEditor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
let currentMatch = this._state.currentMatch;
const currentMatch = this._state.currentMatch;
if (selection.startLineNumber !== selection.endLineNumber) {
if (!Range.equalsRange(selection, currentMatch)) {
// Reseed find scope
@@ -634,13 +643,13 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
private _onFindInputKeyDown(e: IKeyboardEvent): void {
if (e.equals(KeyCode.Enter)) {
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().then(null, onUnexpectedError);
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().then(undefined, onUnexpectedError);
e.preventDefault();
return;
}
if (e.equals(KeyMod.Shift | KeyCode.Enter)) {
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().then(null, onUnexpectedError);
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().then(undefined, onUnexpectedError);
e.preventDefault();
return;
}
@@ -725,7 +734,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
appendCaseSensitiveLabel: this._keybindingLabelFor(FIND_IDS.ToggleCaseSensitiveCommand),
appendWholeWordsLabel: this._keybindingLabelFor(FIND_IDS.ToggleWholeWordCommand),
appendRegexLabel: this._keybindingLabelFor(FIND_IDS.ToggleRegexCommand),
validation: (value: string): InputBoxMessage => {
validation: (value: string): InputBoxMessage | null => {
if (value.length === 0) {
return null;
}
@@ -780,7 +789,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
label: NLS_PREVIOUS_MATCH_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.PreviousMatchFindAction),
className: 'previous',
onTrigger: () => {
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().then(null, onUnexpectedError);
this._codeEditor.getAction(FIND_IDS.PreviousMatchFindAction).run().then(undefined, onUnexpectedError);
}
}));
@@ -789,7 +798,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
label: NLS_NEXT_MATCH_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.NextMatchFindAction),
className: 'next',
onTrigger: () => {
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().then(null, onUnexpectedError);
this._codeEditor.getAction(FIND_IDS.NextMatchFindAction).run().then(undefined, onUnexpectedError);
}
}));
@@ -806,15 +815,17 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
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, this._codeEditor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
if (!selection.isEmpty()) {
this._state.change({ searchScope: selection }, true);
if (this._codeEditor.hasModel()) {
let selection = this._codeEditor.getSelection();
if (selection.endColumn === 1 && selection.endLineNumber > selection.startLineNumber) {
selection = selection.setEndPosition(selection.endLineNumber - 1, this._codeEditor.getModel().getLineMaxColumn(selection.endLineNumber - 1));
}
if (!selection.isEmpty()) {
this._state.change({ searchScope: selection }, true);
}
}
} else {
this._state.change({ searchScope: null }, true);
this._state.change({ searchScope: undefined }, true);
}
}
}));
@@ -824,7 +835,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
label: NLS_CLOSE_BTN_LABEL + this._keybindingLabelFor(FIND_IDS.CloseFindWidgetCommand),
className: 'close-fw',
onTrigger: () => {
this._state.change({ isRevealed: false, searchScope: null }, false);
this._state.change({ isRevealed: false, searchScope: undefined }, false);
},
onKeyDown: (e) => {
if (e.equals(KeyCode.Tab)) {
@@ -850,7 +861,7 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
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, {
this._replaceInputBox = this._register(new ContextScopedHistoryInputBox(replaceInput, undefined, {
ariaLabel: NLS_REPLACE_INPUT_LABEL,
placeholder: NLS_REPLACE_INPUT_PLACEHOLDER,
history: []
@@ -950,8 +961,8 @@ export class FindWidget extends Widget implements IOverlayWidget, IHorizontalSas
return;
}
let inputBoxWidth = width - FIND_ALL_CONTROLS_WIDTH;
let maxWidth = parseFloat(dom.getComputedStyle(this._domNode).maxWidth) || 0;
const inputBoxWidth = width - FIND_ALL_CONTROLS_WIDTH;
const maxWidth = parseFloat(dom.getComputedStyle(this._domNode).maxWidth!) || 0;
if (width > maxWidth) {
return;
}
@@ -1119,7 +1130,7 @@ export class SimpleButton extends Widget {
// theming
registerThemingParticipant((theme, collector) => {
const addBackgroundColorRule = (selector: string, color: Color): void => {
const addBackgroundColorRule = (selector: string, color: Color | null): void => {
if (color) {
collector.addRule(`.monaco-editor ${selector} { background-color: ${color}; }`);
}

View File

@@ -57,8 +57,8 @@ export class ReplaceAllCommand implements editorCommon.ICommand {
}
resultOps.push(previousOp);
for (let i = 0; i < resultOps.length; i++) {
builder.addEditOperation(resultOps[i].range, resultOps[i].text);
for (const op of resultOps) {
builder.addEditOperation(op.range, op.text);
}
}

View File

@@ -18,7 +18,7 @@
.monaco-workbench .simple-find-part {
z-index: 10;
position: relative;
top: -40px;
top: -45px;
display: flex;
padding: 4px;
align-items: center;

View File

@@ -26,7 +26,7 @@ const NLS_CLOSE_BTN_LABEL = nls.localize('label.closeButton', "Close");
export abstract class SimpleFindWidget extends Widget {
private _findInput: FindInput;
private _domNode: HTMLElement;
private _domNode?: HTMLElement;
private _innerDomNode: HTMLElement;
private _isVisible: boolean = false;
private _focusTracker: dom.IFocusTracker;
@@ -186,7 +186,7 @@ export abstract class SimpleFindWidget extends Widget {
}
}
public getDomNode(): HTMLElement {
public getDomNode() {
return this._domNode;
}

View File

@@ -51,8 +51,8 @@ export class TestFindController extends CommonFindController {
}
}
function fromRange(rng: Range): number[] {
return [rng.startLineNumber, rng.startColumn, rng.endLineNumber, rng.endColumn];
function fromSelection(slc: Selection): number[] {
return [slc.startLineNumber, slc.startColumn, slc.endLineNumber, slc.endColumn];
}
suite('FindController', () => {
@@ -67,8 +67,8 @@ suite('FindController', () => {
getBoolean: (key: string) => !!queryState[key],
getInteger: (key: string) => undefined,
store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); },
remove: (key) => void 0
} as IStorageService);
remove: (key) => undefined
} as any);
if (platform.isMacintosh) {
serviceCollection.set(IClipboardService, <any>{
@@ -122,7 +122,7 @@ suite('FindController', () => {
nextMatchFindAction.run(null, editor);
assert.equal(findState.searchString, 'ABC');
assert.deepEqual(fromRange(editor.getSelection()), [1, 1, 1, 4]);
assert.deepEqual(fromSelection(editor.getSelection()!), [1, 1, 1, 4]);
findController.dispose();
});
@@ -175,14 +175,14 @@ suite('FindController', () => {
findState.change({ searchString: 'ABC' }, true);
// The first ABC is highlighted.
assert.deepEqual(fromRange(editor.getSelection()), [1, 1, 1, 4]);
assert.deepEqual(fromSelection(editor.getSelection()!), [1, 1, 1, 4]);
// I hit Esc to exit the Find dialog.
findController.closeFindWidget();
findController.hasFocus = false;
// The cursor is now at end of the first line, with ABC on that line highlighted.
assert.deepEqual(fromRange(editor.getSelection()), [1, 1, 1, 4]);
assert.deepEqual(fromSelection(editor.getSelection()!), [1, 1, 1, 4]);
// I hit delete to remove it and change the text to XYZ.
editor.pushUndoStop();
@@ -195,10 +195,10 @@ suite('FindController', () => {
// ABC
// XYZ
// ABC
assert.equal(editor.getModel().getLineContent(1), 'XYZ');
assert.equal(editor.getModel()!.getLineContent(1), 'XYZ');
// The cursor is at end of the first line.
assert.deepEqual(fromRange(editor.getSelection()), [1, 4, 1, 4]);
assert.deepEqual(fromSelection(editor.getSelection()!), [1, 4, 1, 4]);
// I hit F3 to "Find Next" to find the next occurrence of ABC, but instead it searches for XYZ.
nextMatchFindAction.run(null, editor);
@@ -224,10 +224,10 @@ suite('FindController', () => {
});
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 26, 1, 29]);
assert.deepEqual(fromSelection(editor.getSelection()!), [1, 26, 1, 29]);
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 8, 1, 11]);
assert.deepEqual(fromSelection(editor.getSelection()!), [1, 8, 1, 11]);
findController.dispose();
});
@@ -250,10 +250,10 @@ suite('FindController', () => {
startFindAction.run(null, editor);
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [2, 9, 2, 13]);
assert.deepEqual(fromSelection(editor.getSelection()!), [2, 9, 2, 13]);
nextMatchFindAction.run(null, editor);
assert.deepEqual(fromRange(editor.getSelection()), [1, 9, 1, 13]);
assert.deepEqual(fromSelection(editor.getSelection()!), [1, 9, 1, 13]);
findController.dispose();
});
@@ -330,7 +330,7 @@ suite('FindController', () => {
findController.getState().change({ searchString: '\\b\\s{3}\\b', replaceString: ' ', isRegex: true }, false);
findController.moveToNextMatch();
assert.deepEqual(editor.getSelections().map(fromRange), [
assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[1, 39, 1, 42]
]);
@@ -357,7 +357,7 @@ suite('FindController', () => {
findController.getState().change({ searchString: '^', replaceString: 'x', isRegex: true }, false);
findController.moveToNextMatch();
assert.deepEqual(editor.getSelections().map(fromRange), [
assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[2, 1, 2, 1]
]);
@@ -388,7 +388,7 @@ suite('FindController', () => {
// cmd+f3
nextSelectionMatchFindAction.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[3, 1, 3, 9]
]);
@@ -419,7 +419,7 @@ suite('FindController', () => {
// cmd+f3
nextSelectionMatchFindAction.run(null, editor);
assert.deepEqual(editor.getSelections().map(fromRange), [
assert.deepEqual(editor.getSelections()!.map(fromSelection), [
[3, 1, 3, 9]
]);
@@ -442,8 +442,8 @@ suite('FindController query options persistence', () => {
getBoolean: (key: string) => !!queryState[key],
getInteger: (key: string) => undefined,
store: (key: string, value: any) => { queryState[key] = value; return Promise.resolve(); },
remove: (key) => void 0
} as IStorageService);
remove: (key) => undefined
} as any);
test('matchCase', () => {
withTestCodeEditor([
@@ -464,7 +464,7 @@ suite('FindController query options persistence', () => {
// I type ABC.
findState.change({ searchString: 'ABC' }, true);
// The second ABC is highlighted as matchCase is true.
assert.deepEqual(fromRange(editor.getSelection()), [2, 1, 2, 4]);
assert.deepEqual(fromSelection(editor.getSelection()!), [2, 1, 2, 4]);
findController.dispose();
});
@@ -491,7 +491,7 @@ suite('FindController query options persistence', () => {
// I type AB.
findState.change({ searchString: 'AB' }, true);
// The second AB is highlighted as wholeWord is true.
assert.deepEqual(fromRange(editor.getSelection()), [2, 1, 2, 3]);
assert.deepEqual(fromSelection(editor.getSelection()!), [2, 1, 2, 3]);
findController.dispose();
});

View File

@@ -5,7 +5,7 @@
import * as assert from 'assert';
import { CoreNavigationCommands } from 'vs/editor/browser/controller/coreCommands';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ICodeEditor, IActiveCodeEditor } from 'vs/editor/browser/editorBrowser';
import { Cursor } from 'vs/editor/common/controller/cursor';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
@@ -18,7 +18,7 @@ import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
suite('FindModel', () => {
function findTest(testName: string, callback: (editor: ICodeEditor, cursor: Cursor) => void): void {
function findTest(testName: string, callback: (editor: IActiveCodeEditor, cursor: Cursor) => void): void {
test(testName, () => {
const textArr = [
'// my cool header',
@@ -34,7 +34,7 @@ suite('FindModel', () => {
'// blablablaciao',
''
];
withTestCodeEditor(textArr, {}, callback);
withTestCodeEditor(textArr, {}, (editor, cursor) => callback(editor as unknown as IActiveCodeEditor, cursor));
const text = textArr.join('\n');
const ptBuilder = new PieceTreeTextBufferBuilder();
@@ -45,7 +45,9 @@ suite('FindModel', () => {
withTestCodeEditor([],
{
model: new TextModel(factory, TextModel.DEFAULT_CREATION_OPTIONS, null, null)
}, callback);
},
(editor, cursor) => callback(editor as unknown as IActiveCodeEditor, cursor)
);
});
}
@@ -54,7 +56,7 @@ suite('FindModel', () => {
}
function _getFindState(editor: ICodeEditor) {
let model = editor.getModel();
let model = editor.getModel()!;
let currentFindMatches: Range[] = [];
let allFindMatches: Range[] = [];
@@ -76,8 +78,8 @@ suite('FindModel', () => {
};
}
function assertFindState(editor: ICodeEditor, cursor: number[], highlighted: number[], findDecorations: number[][]): void {
assert.deepEqual(fromRange(editor.getSelection()), cursor, 'cursor');
function assertFindState(editor: ICodeEditor, cursor: number[], highlighted: number[] | null, findDecorations: number[][]): void {
assert.deepEqual(fromRange(editor.getSelection()!), cursor, 'cursor');
let expectedState = {
highlighted: highlighted ? [highlighted] : [],
@@ -1177,7 +1179,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello world, Hello!" << endl;');
findModel.replace();
assertFindState(
@@ -1191,7 +1193,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello world, Hello!" << endl;');
findModel.replace();
assertFindState(
@@ -1204,7 +1206,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello world, hi!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello world, hi!" << endl;');
findModel.replace();
assertFindState(
@@ -1216,7 +1218,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hi world again" << endl;');
findModel.replace();
assertFindState(
@@ -1227,7 +1229,7 @@ suite('FindModel', () => {
[6, 14, 6, 19]
]
);
assert.equal(editor.getModel().getLineContent(8), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "hi world again" << endl;');
findModel.replace();
assertFindState(
@@ -1236,7 +1238,7 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, hi!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hi world, hi!" << endl;');
findModel.dispose();
findState.dispose();
@@ -1269,7 +1271,7 @@ suite('FindModel', () => {
[11, 10, 11, 13]
]
);
assert.equal(editor.getModel().getLineContent(11), '// blablablaciao');
assert.equal(editor.getModel()!.getLineContent(11), '// blablablaciao');
findModel.replace();
assertFindState(
@@ -1281,7 +1283,7 @@ suite('FindModel', () => {
[11, 11, 11, 14]
]
);
assert.equal(editor.getModel().getLineContent(11), '// ciaoblablaciao');
assert.equal(editor.getModel()!.getLineContent(11), '// ciaoblablaciao');
findModel.replace();
assertFindState(
@@ -1292,7 +1294,7 @@ suite('FindModel', () => {
[11, 12, 11, 15]
]
);
assert.equal(editor.getModel().getLineContent(11), '// ciaociaoblaciao');
assert.equal(editor.getModel()!.getLineContent(11), '// ciaociaoblaciao');
findModel.replace();
assertFindState(
@@ -1301,7 +1303,7 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(11), '// ciaociaociaociao');
assert.equal(editor.getModel()!.getLineContent(11), '// ciaociaociaociao');
findModel.dispose();
findState.dispose();
@@ -1338,7 +1340,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello world, Hello!" << endl;');
findModel.replaceAll();
assertFindState(
@@ -1347,9 +1349,9 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, hi!" << endl;');
assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel().getLineContent(8), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hi world, hi!" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "hi world again" << endl;');
findModel.dispose();
findState.dispose();
@@ -1388,10 +1390,10 @@ suite('FindModel', () => {
[9, 1, 9, 3]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello world, Hello!" << endl;');
assert.equal(editor.getModel().getLineContent(7), ' cout << "hello world again" << endl;');
assert.equal(editor.getModel().getLineContent(8), ' cout << "Hello world again" << endl;');
assert.equal(editor.getModel().getLineContent(9), ' cout << "helloworld again" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hello world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "Hello world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(9), ' cout << "helloworld again" << endl;');
findModel.dispose();
findState.dispose();
@@ -1420,7 +1422,7 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(11), '// ciaociaociaociao');
assert.equal(editor.getModel()!.getLineContent(11), '// ciaociaociaociao');
findModel.dispose();
findState.dispose();
@@ -1449,10 +1451,10 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(11), '// <');
assert.equal(editor.getModel().getLineContent(12), '\t><');
assert.equal(editor.getModel().getLineContent(13), '\t><');
assert.equal(editor.getModel().getLineContent(14), '\t>ciao');
assert.equal(editor.getModel()!.getLineContent(11), '// <');
assert.equal(editor.getModel()!.getLineContent(12), '\t><');
assert.equal(editor.getModel()!.getLineContent(13), '\t><');
assert.equal(editor.getModel()!.getLineContent(14), '\t>ciao');
findModel.dispose();
findState.dispose();
@@ -1481,8 +1483,8 @@ suite('FindModel', () => {
[]
);
assert.equal(editor.getModel().getLineContent(2), '#bar "cool.h"');
assert.equal(editor.getModel().getLineContent(3), '#bar <iostream>');
assert.equal(editor.getModel()!.getLineContent(2), '#bar "cool.h"');
assert.equal(editor.getModel()!.getLineContent(3), '#bar <iostream>');
findModel.dispose();
findState.dispose();
@@ -1671,7 +1673,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello world, Hello!" << endl;');
findModel.replace();
assertFindState(
@@ -1683,7 +1685,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hi world, Hello!" << endl;');
findModel.replace();
assertFindState(
@@ -1694,7 +1696,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hi world again" << endl;');
findModel.replace();
assertFindState(
@@ -1703,7 +1705,7 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(8), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "hi world again" << endl;');
findModel.dispose();
findState.dispose();
@@ -1742,7 +1744,7 @@ suite('FindModel', () => {
]
);
assert.equal(editor.getModel().getLineContent(8), ' cout << "Hello world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "Hello world again" << endl;');
findModel.replace();
assertFindState(
@@ -1754,7 +1756,7 @@ suite('FindModel', () => {
[7, 14, 7, 19],
]
);
assert.equal(editor.getModel().getLineContent(8), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "hi world again" << endl;');
findModel.replace();
assertFindState(
@@ -1765,7 +1767,7 @@ suite('FindModel', () => {
[7, 14, 7, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hi world, Hello!" << endl;');
findModel.replace();
assertFindState(
@@ -1774,7 +1776,7 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hi world again" << endl;');
findModel.dispose();
findState.dispose();
@@ -1798,9 +1800,9 @@ suite('FindModel', () => {
findModel.replaceAll();
assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, Hello!" << endl;');
assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel().getLineContent(8), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hi world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "hi world again" << endl;');
assertFindState(
editor,
@@ -1841,7 +1843,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello world, Hello!" << endl;');
findModel.replace();
assertFindState(
@@ -1853,7 +1855,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hilo world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hilo world, Hello!" << endl;');
findModel.replace();
assertFindState(
@@ -1864,7 +1866,7 @@ suite('FindModel', () => {
[8, 14, 8, 19]
]
);
assert.equal(editor.getModel().getLineContent(7), ' cout << "hilo world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hilo world again" << endl;');
findModel.replace();
assertFindState(
@@ -1873,7 +1875,7 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(8), ' cout << "hilo world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "hilo world again" << endl;');
findModel.dispose();
findState.dispose();
@@ -1898,10 +1900,10 @@ suite('FindModel', () => {
findModel.replaceAll();
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello girl, Hello!" << endl;');
assert.equal(editor.getModel().getLineContent(7), ' cout << "hello girl again" << endl;');
assert.equal(editor.getModel().getLineContent(8), ' cout << "Hello girl again" << endl;');
assert.equal(editor.getModel().getLineContent(9), ' cout << "hellogirl again" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello girl, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hello girl again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "Hello girl again" << endl;');
assert.equal(editor.getModel()!.getLineContent(9), ' cout << "hellogirl again" << endl;');
assertFindState(
editor,
@@ -1931,8 +1933,8 @@ suite('FindModel', () => {
findModel.replaceAll();
assert.equal(editor.getModel().getLineContent(6), ' cout << "hello girl, Hello!" << endl;');
assert.equal(editor.getModel().getLineContent(8), ' cout << "Hello girl again" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hello girl, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << "Hello girl again" << endl;');
assertFindState(
editor,
@@ -1969,9 +1971,9 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << " world, !" << endl;');
assert.equal(editor.getModel().getLineContent(7), ' cout << " world again" << endl;');
assert.equal(editor.getModel().getLineContent(8), ' cout << " world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << " world, !" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << " world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(8), ' cout << " world again" << endl;');
findModel.dispose();
findState.dispose();
@@ -2023,9 +2025,9 @@ suite('FindModel', () => {
null,
[]
);
assert.equal(editor.getModel().getLineContent(6), ' cout << "hi world, Hello!" << endl;');
assert.equal(editor.getModel().getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel().getLineContent(9), ' cout << "hiworld again" << endl;');
assert.equal(editor.getModel()!.getLineContent(6), ' cout << "hi world, Hello!" << endl;');
assert.equal(editor.getModel()!.getLineContent(7), ' cout << "hi world again" << endl;');
assert.equal(editor.getModel()!.getLineContent(9), ' cout << "hiworld again" << endl;');
findModel.dispose();
findState.dispose();