mirror of
https://github.com/google-gemini/gemini-cli
synced 2026-04-21 13:37:17 +00:00
Merge 5d0dea3c44 into a38e2f0048
This commit is contained in:
commit
cb80b252b7
2 changed files with 59 additions and 6 deletions
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue