mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
Use equals helper function instead of re-implementing it so many places
This commit is contained in:
parent
6e593ab812
commit
40e0f496f9
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { OperatingSystem } from 'vs/base/common/platform';
|
||||
import { illegalArgument } from 'vs/base/common/errors';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
/**
|
||||
* Virtual Key Codes, the value does not hold any inherent meaning.
|
||||
|
@ -525,15 +526,7 @@ export class ChordKeybinding {
|
|||
if (other === null) {
|
||||
return false;
|
||||
}
|
||||
if (this.parts.length !== other.parts.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < this.parts.length; i++) {
|
||||
if (!this.parts[i].equals(other.parts[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return equals(this.parts, other.parts, (a, b) => a.equals(b));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { IPosition, Position } from 'vs/editor/common/core/position';
|
||||
import { Range } from 'vs/editor/common/core/range';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
/**
|
||||
* A selection in the editor.
|
||||
|
@ -171,15 +172,7 @@ export class Selection extends Range {
|
|||
if (!a && !b) {
|
||||
return true;
|
||||
}
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0, len = a.length; i < len; i++) {
|
||||
if (!this.selectionsEqual(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return equals(a, b, this.selectionsEqual);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import * as strings from 'vs/base/common/strings';
|
||||
import { Constants } from 'vs/editor/common/core/uint';
|
||||
import { InlineDecoration, InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
export class LineDecoration {
|
||||
_lineDecorationBrand: void;
|
||||
|
@ -27,18 +28,8 @@ export class LineDecoration {
|
|||
);
|
||||
}
|
||||
|
||||
public static equalsArr(a: LineDecoration[], b: LineDecoration[]): boolean {
|
||||
let aLen = a.length;
|
||||
let bLen = b.length;
|
||||
if (aLen !== bLen) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < aLen; i++) {
|
||||
if (!LineDecoration._equals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
public static equalsArr(a: readonly LineDecoration[], b: readonly LineDecoration[]): boolean {
|
||||
return equals(a, b, LineDecoration._equals);
|
||||
}
|
||||
|
||||
public static filter(lineDecorations: InlineDecoration[], lineNumber: number, minLineColumn: number, maxLineColumn: number): LineDecoration[] {
|
||||
|
|
|
@ -9,6 +9,7 @@ import { IViewLineTokens } from 'vs/editor/common/core/lineTokens';
|
|||
import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder';
|
||||
import { LineDecoration, LineDecorationsNormalizer } from 'vs/editor/common/viewLayout/lineDecorations';
|
||||
import { InlineDecorationType } from 'vs/editor/common/viewModel/viewModel';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
export const enum RenderWhitespace {
|
||||
None = 0,
|
||||
|
@ -131,17 +132,7 @@ export class RenderLineInput {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (otherSelections.length !== this.selectionsOnLine.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.selectionsOnLine.length; i++) {
|
||||
if (!this.selectionsOnLine[i].equals(otherSelections[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return equals(this.selectionsOnLine, otherSelections, (a, b) => a.equals(b));
|
||||
}
|
||||
|
||||
public equals(other: RenderLineInput): boolean {
|
||||
|
|
|
@ -12,6 +12,7 @@ import { Selection } from 'vs/editor/common/core/selection';
|
|||
import { IEditorContribution, ScrollType } from 'vs/editor/common/editorCommon';
|
||||
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
|
||||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
class CursorState {
|
||||
readonly selections: readonly Selection[];
|
||||
|
@ -21,17 +22,7 @@ class CursorState {
|
|||
}
|
||||
|
||||
public equals(other: CursorState): boolean {
|
||||
const thisLen = this.selections.length;
|
||||
const otherLen = other.selections.length;
|
||||
if (thisLen !== otherLen) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < thisLen; i++) {
|
||||
if (!this.selections[i].equalsSelection(other.selections[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return equals(this.selections, other.selections, (a, b) => a.equalsSelection(b));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { IViewLineTokens } from 'vs/editor/common/core/lineTokens';
|
||||
import { ColorId, TokenMetadata } from 'vs/editor/common/modes';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
/**
|
||||
* A token on a line.
|
||||
|
@ -42,18 +43,8 @@ export class ViewLineToken {
|
|||
);
|
||||
}
|
||||
|
||||
public static equalsArr(a: ViewLineToken[], b: ViewLineToken[]): boolean {
|
||||
const aLen = a.length;
|
||||
const bLen = b.length;
|
||||
if (aLen !== bLen) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < aLen; i++) {
|
||||
if (!this._equals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
public static equalsArr(a: readonly ViewLineToken[], b: readonly ViewLineToken[]): boolean {
|
||||
return equals(a, b, this._equals);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import { Event } from 'vs/base/common/event';
|
||||
import { isFalsyOrWhitespace } from 'vs/base/common/strings';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
export const enum ContextKeyExprType {
|
||||
Defined = 1,
|
||||
|
@ -574,15 +575,7 @@ export class ContextKeyAndExpr implements ContextKeyExpr {
|
|||
|
||||
public equals(other: ContextKeyExpr): boolean {
|
||||
if (other instanceof ContextKeyAndExpr) {
|
||||
if (this.expr.length !== other.expr.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0, len = this.expr.length; i < len; i++) {
|
||||
if (!this.expr[i].equals(other.expr[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return equals(this.expr, other.expr, (a, b) => a.equals(b));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -674,15 +667,7 @@ export class ContextKeyOrExpr implements ContextKeyExpr {
|
|||
|
||||
public equals(other: ContextKeyExpr): boolean {
|
||||
if (other instanceof ContextKeyOrExpr) {
|
||||
if (this.expr.length !== other.expr.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0, len = this.expr.length; i < len; i++) {
|
||||
if (!this.expr[i].equals(other.expr[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return equals(this.expr, other.expr, (a, b) => a.equals(b));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import { isMacintosh, isLinux } from 'vs/base/common/platform';
|
|||
import { IDiskFileChange, normalizeFileChanges, ILogMessage } from 'vs/platform/files/node/watcher/watcher';
|
||||
import { IWatcherRequest, IWatcherService, IWatcherOptions } from 'vs/platform/files/node/watcher/unix/watcher';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
interface IWatcher {
|
||||
requests: ExtendedWatcherRequest[];
|
||||
|
@ -363,14 +364,6 @@ function isEqualRequests(r1: IWatcherRequest[], r2: IWatcherRequest[]) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function isEqualIgnore(i1: string[], i2: string[]) {
|
||||
if (i1.length !== i2.length) {
|
||||
return false;
|
||||
}
|
||||
for (let k = 0; k < i1.length; k++) {
|
||||
if (i1[k] !== i2[k]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
function isEqualIgnore(i1: readonly string[], i2: readonly string[]) {
|
||||
return equals(i1, i2);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2
|
|||
import { IApplyEditsOptions, IEditorPropertiesChangeData, IResolvedTextEditorConfiguration, ITextEditorConfigurationUpdate, IUndoStopOptions, TextEditorRevealType } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { IEditor } from 'vs/workbench/common/editor';
|
||||
import { withNullAsUndefined } from 'vs/base/common/types';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
export interface IFocusTracker {
|
||||
onGainedFocus(): void;
|
||||
|
@ -124,28 +125,12 @@ export class MainThreadTextEditorProperties {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static _selectionsEqual(a: Selection[], b: Selection[]): boolean {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!a[i].equalsSelection(b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
private static _selectionsEqual(a: readonly Selection[], b: readonly Selection[]): boolean {
|
||||
return equals(a, b, (aValue, bValue) => aValue.equalsSelection(bValue));
|
||||
}
|
||||
|
||||
private static _rangesEqual(a: Range[], b: Range[]): boolean {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!a[i].equalsRange(b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
private static _rangesEqual(a: readonly Range[], b: readonly Range[]): boolean {
|
||||
return equals(a, b, (aValue, bValue) => aValue.equalsRange(bValue));
|
||||
}
|
||||
|
||||
private static _optionsEqual(a: IResolvedTextEditorConfiguration, b: IResolvedTextEditorConfiguration): boolean {
|
||||
|
|
|
@ -12,6 +12,7 @@ import { ensureValidWordDefinition, getWordAtText } from 'vs/editor/common/model
|
|||
import { MainThreadDocumentsShape } from 'vs/workbench/api/common/extHost.protocol';
|
||||
import { EndOfLine, Position, Range } from 'vs/workbench/api/common/extHostTypes';
|
||||
import * as vscode from 'vscode';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
const _modeId2WordDefinition = new Map<string, RegExp>();
|
||||
export function setWordDefinitionFor(modeId: string, wordDefinition: RegExp | undefined): void {
|
||||
|
@ -48,17 +49,8 @@ export class ExtHostDocumentData extends MirrorTextModel {
|
|||
this._isDirty = false;
|
||||
}
|
||||
|
||||
equalLines(lines: string[]): boolean {
|
||||
const len = lines.length;
|
||||
if (len !== this._lines.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (lines[i] !== this._lines[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
equalLines(lines: readonly string[]): boolean {
|
||||
return equals(this._lines, lines);
|
||||
}
|
||||
|
||||
get document(): vscode.TextDocument {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { DisposableStore, MutableDisposable } from 'vs/base/common/lifecycle';
|
|||
import { asPromise } from 'vs/base/common/async';
|
||||
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
|
||||
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceSplice, SCMRawResourceSplices, IMainContext, ExtHostSCMShape, ICommandDto } from './extHost.protocol';
|
||||
import { sortedDiff } from 'vs/base/common/arrays';
|
||||
import { sortedDiff, equals } from 'vs/base/common/arrays';
|
||||
import { comparePaths } from 'vs/base/common/comparers';
|
||||
import * as vscode from 'vscode';
|
||||
import { ISplice } from 'vs/base/common/sequence';
|
||||
|
@ -126,18 +126,8 @@ function commandEquals(a: vscode.Command, b: vscode.Command): boolean {
|
|||
&& (a.arguments && b.arguments ? compareArgs(a.arguments, b.arguments) : a.arguments === b.arguments);
|
||||
}
|
||||
|
||||
function commandListEquals(a: vscode.Command[], b: vscode.Command[]): boolean {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!commandEquals(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
function commandListEquals(a: readonly vscode.Command[], b: readonly vscode.Command[]): boolean {
|
||||
return equals(a, b, commandEquals);
|
||||
}
|
||||
|
||||
export interface IValidateInput {
|
||||
|
|
|
@ -29,6 +29,7 @@ import { IModelDeltaDecoration, ITextModel, TrackedRangeStickiness, OverviewRule
|
|||
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
|
||||
import { KeybindingParser } from 'vs/base/common/keybindingParser';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
const NLS_LAUNCH_MESSAGE = nls.localize('defineKeybinding.start', "Define Keybinding");
|
||||
const NLS_KB_LAYOUT_ERROR_MESSAGE = nls.localize('defineKeybinding.kbLayoutErrorMessage', "You won't be able to produce this key combination under your current keyboard layout.");
|
||||
|
@ -265,18 +266,7 @@ export class KeybindingEditorDecorationsRenderer extends Disposable {
|
|||
|
||||
const aParts = KeybindingParser.parseUserBinding(a);
|
||||
const bParts = KeybindingParser.parseUserBinding(b);
|
||||
|
||||
if (aParts.length !== bParts.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0, len = aParts.length; i < len; i++) {
|
||||
if (!this._userBindingEquals(aParts[i], bParts[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return equals(aParts, bParts, (a, b) => this._userBindingEquals(a, b));
|
||||
}
|
||||
|
||||
private static _userBindingEquals(a: SimpleKeybinding | ScanCodeBinding, b: SimpleKeybinding | ScanCodeBinding): boolean {
|
||||
|
|
Loading…
Reference in a new issue