mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
findMaxBy -> findLastMaxBy
This commit is contained in:
parent
983a71fad9
commit
137ea7552b
|
@ -625,6 +625,24 @@ export function findMaxBy<T>(items: readonly T[], comparator: Comparator<T>): T
|
||||||
return max;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the last item that is equal to or greater than every other item.
|
||||||
|
*/
|
||||||
|
export function findLastMaxBy<T>(items: readonly T[], comparator: Comparator<T>): T | undefined {
|
||||||
|
if (items.length === 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
let max = items[0];
|
||||||
|
for (let i = 1; i < items.length; i++) {
|
||||||
|
const item = items[i];
|
||||||
|
if (comparator(item, max) >= 0) {
|
||||||
|
max = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the first item that is equal to or less than every other item.
|
* Returns the first item that is equal to or less than every other item.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -347,6 +347,15 @@ suite('Arrays', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('findLastMaxBy', () => {
|
||||||
|
const array = [{ v: 3 }, { v: 5 }, { v: 2 }, { v: 2 }, { v: 2 }, { v: 5 }];
|
||||||
|
|
||||||
|
assert.strictEqual(
|
||||||
|
array.indexOf(arrays.findLastMaxBy(array, arrays.compareBy(v => v.v, arrays.numberComparator))!),
|
||||||
|
5
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('findMinBy', () => {
|
test('findMinBy', () => {
|
||||||
const array = [{ v: 3 }, { v: 5 }, { v: 2 }, { v: 2 }, { v: 2 }, { v: 5 }];
|
const array = [{ v: 3 }, { v: 5 }, { v: 2 }, { v: 2 }, { v: 2 }, { v: 5 }];
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import { compareBy, findMaxBy, findMinBy } from 'vs/base/common/arrays';
|
import { compareBy, findLastMaxBy, findMinBy } from 'vs/base/common/arrays';
|
||||||
import { CursorContext, CursorState, PartialCursorState } from 'vs/editor/common/controller/cursorCommon';
|
import { CursorContext, CursorState, PartialCursorState } from 'vs/editor/common/controller/cursorCommon';
|
||||||
import { Cursor } from 'vs/editor/common/controller/oneCursor';
|
import { Cursor } from 'vs/editor/common/controller/oneCursor';
|
||||||
import { Position } from 'vs/editor/common/core/position';
|
import { Position } from 'vs/editor/common/core/position';
|
||||||
|
@ -78,7 +78,7 @@ export class CursorCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBottomMostViewPosition(): Position {
|
public getBottomMostViewPosition(): Position {
|
||||||
return findMaxBy(
|
return findLastMaxBy(
|
||||||
this.cursors,
|
this.cursors,
|
||||||
compareBy(c => c.viewState.position, Position.compare)
|
compareBy(c => c.viewState.position, Position.compare)
|
||||||
)!.viewState.position;
|
)!.viewState.position;
|
||||||
|
|
Loading…
Reference in a new issue