Skip to content
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

debt - arrays.ts#tail can return undefined #209631

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/vs/base/browser/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,28 @@ export class Gesture extends Disposable {
holdTime = Date.now() - data.initialTimeStamp;

if (holdTime < Gesture.HOLD_DELAY
&& Math.abs(data.initialPageX - arrays.tail(data.rollingPageX)) < 30
&& Math.abs(data.initialPageY - arrays.tail(data.rollingPageY)) < 30) {
&& Math.abs(data.initialPageX - arrays.tail(data.rollingPageX)!) < 30
&& Math.abs(data.initialPageY - arrays.tail(data.rollingPageY)!) < 30) {

const evt = this.newGestureEvent(EventType.Tap, data.initialTarget);
evt.pageX = arrays.tail(data.rollingPageX);
evt.pageY = arrays.tail(data.rollingPageY);
evt.pageX = arrays.tail(data.rollingPageX)!;
evt.pageY = arrays.tail(data.rollingPageY)!;
this.dispatchEvent(evt);

} else if (holdTime >= Gesture.HOLD_DELAY
&& Math.abs(data.initialPageX - arrays.tail(data.rollingPageX)) < 30
&& Math.abs(data.initialPageY - arrays.tail(data.rollingPageY)) < 30) {
&& Math.abs(data.initialPageX - arrays.tail(data.rollingPageX)!) < 30
&& Math.abs(data.initialPageY - arrays.tail(data.rollingPageY)!) < 30) {

const evt = this.newGestureEvent(EventType.Contextmenu, data.initialTarget);
evt.pageX = arrays.tail(data.rollingPageX);
evt.pageY = arrays.tail(data.rollingPageY);
evt.pageX = arrays.tail(data.rollingPageX)!;
evt.pageY = arrays.tail(data.rollingPageY)!;
this.dispatchEvent(evt);

} else if (activeTouchCount === 1) {
const finalX = arrays.tail(data.rollingPageX);
const finalY = arrays.tail(data.rollingPageY);
const finalX = arrays.tail(data.rollingPageX)!;
const finalY = arrays.tail(data.rollingPageY)!;

const deltaT = arrays.tail(data.rollingTimestamps) - data.rollingTimestamps[0];
const deltaT = arrays.tail(data.rollingTimestamps)! - data.rollingTimestamps[0];
const deltaX = finalX - data.rollingPageX[0];
const deltaY = finalY - data.rollingPageY[0];

Expand Down Expand Up @@ -345,8 +345,8 @@ export class Gesture extends Disposable {
const data = this.activeTouches[touch.identifier];

const evt = this.newGestureEvent(EventType.Change, data.initialTarget);
evt.translationX = touch.pageX - arrays.tail(data.rollingPageX);
evt.translationY = touch.pageY - arrays.tail(data.rollingPageY);
evt.translationX = touch.pageX - arrays.tail(data.rollingPageX)!;
evt.translationY = touch.pageY - arrays.tail(data.rollingPageY)!;
evt.pageX = touch.pageX;
evt.pageY = touch.pageY;
this.dispatchEvent(evt);
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/common/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { findFirstIdxMonotonousOrArrLen } from './arraysFind';
* @param array The array.
* @param n Which element from the end (default is zero).
*/
export function tail<T>(array: ArrayLike<T>, n: number = 0): T {
export function tail<T>(array: ArrayLike<T>, n: number = 0): T | undefined {
return array[array.length - (1 + n)];
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/bulkEdit/browser/bulkFileEdits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export class BulkFileEdits {
for (let i = 1; i < edits.length; i++) {
const edit = edits[i];
const lastGroup = tail(groups);
if (lastGroup[0].type === edit.type) {
if (lastGroup?.[0].type === edit.type) {
lastGroup.push(edit);
} else {
groups.push([edit]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ export class InlineChatWidget {
if (!isNonEmptyArray(requests)) {
return undefined;
}
return tail(requests).response?.response.asString();
return tail(requests)?.response?.response.asString();
}

getChatModel(): IChatModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
.sort((a, b) => a.order - b.order);
const nonEmptyResultGroups = resultGroups.filter(group => group.result.filterMatches.length);

const startLine = tail(this.settingsGroups).range.endLineNumber + 2;
const startLine = tail(this.settingsGroups)!.range.endLineNumber + 2;
const { settingsGroups: filteredGroups, matches } = this.writeResultGroups(nonEmptyResultGroups, startLine);

const metadata = this.collectMetadata(resultGroups);
Expand Down
Loading