This commit is contained in:
nirali 2026-04-21 15:15:49 +07:00 committed by GitHub
commit cb80b252b7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 59 additions and 6 deletions

View file

@ -175,4 +175,45 @@ describe('EditorSettingsDialog', () => {
}
expect(frame).toContain('(Also modified');
});
it('emits error feedback only once when preferredEditor is invalid', async () => {
const mockEmitFeedback = vi.fn();
vi.spyOn(
await import('@google/gemini-cli-core').then((m) => m.coreEvents),
'emitFeedback',
).mockImplementation(mockEmitFeedback);
const invalidSettings = {
forScope: (_scope: string) => ({
settings: {
general: {
preferredEditor: 'invalideditor',
},
},
}),
merged: {
general: {
preferredEditor: 'invalideditor',
},
},
} as unknown as LoadedSettings;
const { unmount } = await renderWithProvider(
<EditorSettingsDialog
onSelect={vi.fn()}
settings={invalidSettings}
onExit={vi.fn()}
/>,
);
await waitFor(() => {
expect(mockEmitFeedback).toHaveBeenCalledWith(
'error',
'Editor is not supported: invalideditor',
);
});
expect(mockEmitFeedback).toHaveBeenCalledTimes(1);
unmount();
});
});

View file

@ -5,7 +5,7 @@
*/
import type React from 'react';
import { useState } from 'react';
import { useState, useEffect, useRef } from 'react';
import { Box, Text } from 'ink';
import { theme } from '../semantic-colors.js';
import {
@ -71,14 +71,26 @@ export function EditorSettingsDialog({
(item: EditorDisplay) => item.type === currentPreference,
)
: 0;
if (editorIndex === -1) {
coreEvents.emitFeedback(
'error',
`Editor is not supported: ${currentPreference}`,
);
const isUnsupportedEditor = editorIndex === -1;
if (isUnsupportedEditor) {
editorIndex = 0;
}
const reportedInvalidEditors = useRef(new Set<string>());
useEffect(() => {
if (
isUnsupportedEditor &&
currentPreference &&
!reportedInvalidEditors.current.has(currentPreference)
) {
coreEvents.emitFeedback(
'error',
`Editor is not supported: ${currentPreference}`,
);
reportedInvalidEditors.current.add(currentPreference);
}
}, [isUnsupportedEditor, currentPreference]);
const scopeItems: Array<{
label: string;
value: LoadableSettingScope;