Skip to content
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
8 changes: 6 additions & 2 deletions src/vs/workbench/contrib/chat/browser/widget/chatPetWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ function getSpriteSources(): Record<ChatPetState, { animated: string; reducedMot
return spriteSources;
}

export function isChatPetImageSource(image: Pick<HTMLImageElement, 'getAttribute'>, source: string): boolean {
return image.getAttribute('src') === source;
}

export function getChatPetBaseState(hasActiveRequest: boolean, needsInput: boolean, idleExpired: boolean): ChatPetState {
if (needsInput) {
return 'clapping';
Expand Down Expand Up @@ -435,7 +439,7 @@ export class ChatPetWidget extends Disposable {
private _renderState(state: ChatPetState, restart = false): void {
const sources = getSpriteSources()[state];
const source = this._motionReduced ? sources.reducedMotion : sources.animated;
if (!restart && this._activeImage?.src === source) {
if (!restart && this._activeImage && isChatPetImageSource(this._activeImage, source)) {
this._button.element.dataset.state = state;
this._renderedState = state;
return;
Expand All @@ -454,7 +458,7 @@ export class ChatPetWidget extends Disposable {
}

private _onImageLoad(image: HTMLImageElement): void {
if (image !== this._pendingImage || image.src !== this._pendingSource || this._pendingState === undefined) {
if (image !== this._pendingImage || this._pendingSource === undefined || !isChatPetImageSource(image, this._pendingSource) || this._pendingState === undefined) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import assert from 'assert';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/test/common/utils.js';
import { doesChatPetStateTrackCursor, getChatPetBaseState, getChatPetBuddyName, getChatPetClickInteraction, getChatPetGazeDirection, getChatPetHorizontalPosition, getChatPetSpriteName } from '../../../browser/widget/chatPetWidget.js';
import { doesChatPetStateTrackCursor, getChatPetBaseState, getChatPetBuddyName, getChatPetClickInteraction, getChatPetGazeDirection, getChatPetHorizontalPosition, getChatPetSpriteName, isChatPetImageSource } from '../../../browser/widget/chatPetWidget.js';

suite('ChatPetWidget', () => {

Expand Down Expand Up @@ -99,6 +99,20 @@ suite('ChatPetWidget', () => {
]);
});

test('matches sprite sources without browser URL normalization', () => {
const source = 'vscode-file://vscode-app/Applications/Visual Studio Code - Insiders.app/pet.gif';
const image = document.createElement('img');
image.src = source;

assert.deepStrictEqual([
image.src === source,
isChatPetImageSource(image, source),
], [
false,
true,
]);
});

test('maps the cursor to pixel-snapped gaze directions', () => {
assert.deepStrictEqual([
getChatPetGazeDirection(10, 0, 0, 0),
Expand Down
Loading