From 034aeb15e45b90bdeef02d386023fc3295fb3038 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Wed, 22 Jul 2026 14:11:19 -0700 Subject: [PATCH] feat(editor): seed Find from selected text (#9982) --- .../src/components/editor/DiffSectionBody.tsx | 7 ++----- src/renderer/src/components/editor/DiffViewer.tsx | 7 ++----- src/renderer/src/components/editor/MonacoEditor.tsx | 7 ++----- .../components/editor/monaco-find-options.test.ts | 12 ++++++++++++ .../src/components/editor/monaco-find-options.ts | 7 +++++++ 5 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 src/renderer/src/components/editor/monaco-find-options.test.ts create mode 100644 src/renderer/src/components/editor/monaco-find-options.ts diff --git a/src/renderer/src/components/editor/DiffSectionBody.tsx b/src/renderer/src/components/editor/DiffSectionBody.tsx index 8a1dc3cef..5bf443347 100644 --- a/src/renderer/src/components/editor/DiffSectionBody.tsx +++ b/src/renderer/src/components/editor/DiffSectionBody.tsx @@ -10,6 +10,7 @@ import type { DiffSection } from './diff-section-types' import { translate } from '@/i18n/i18n' import { LargeDiffFallback } from './LargeDiffFallback' import { buildDiffEditorWordWrapOptions } from './diff-editor-word-wrap-options' +import { monacoFindOptions } from './monaco-find-options' const ImageDiffViewer = lazy(() => import('./ImageDiffViewer')) @@ -198,11 +199,7 @@ export function DiffSectionBody({ renderOverviewRuler: false, scrollbar: combinedDiffSectionScrollbarOptions, hideUnchangedRegions: { enabled: true }, - find: { - addExtraSpaceOnTop: false, - autoFindInSelection: 'never', - seedSearchStringFromSelection: 'never' - } + find: monacoFindOptions }} /> )} diff --git a/src/renderer/src/components/editor/DiffViewer.tsx b/src/renderer/src/components/editor/DiffViewer.tsx index 5aed5c967..e2f364a2c 100644 --- a/src/renderer/src/components/editor/DiffViewer.tsx +++ b/src/renderer/src/components/editor/DiffViewer.tsx @@ -26,6 +26,7 @@ import type { DiffViewerProps } from './diff-viewer-props' import { buildDiffEditorWordWrapOptions } from './diff-editor-word-wrap-options' import { useDiffEditorRegistration } from './diff-navigation-context' import { preserveDiffViewStateAcrossModelSwaps } from './diff-model-swap-view-state' +import { monacoFindOptions } from './monaco-find-options' export default function DiffViewer({ modelKey, @@ -429,11 +430,7 @@ export default function DiffViewer({ renderOverviewRuler: true, scrollbar: diffEditorScrollbarOptions, padding: { top: 0 }, - find: { - addExtraSpaceOnTop: false, - autoFindInSelection: 'never', - seedSearchStringFromSelection: 'never' - } + find: monacoFindOptions }} /> )} diff --git a/src/renderer/src/components/editor/MonacoEditor.tsx b/src/renderer/src/components/editor/MonacoEditor.tsx index dbb5bd0b2..c6996ad34 100644 --- a/src/renderer/src/components/editor/MonacoEditor.tsx +++ b/src/renderer/src/components/editor/MonacoEditor.tsx @@ -65,6 +65,7 @@ import { isMonacoAutoHeightCapped } from './monaco-auto-height' import { installMonacoE2EProbe } from './monaco-e2e-probe' +import { monacoFindOptions } from './monaco-find-options' type MonacoEditorProps = { fileId: string @@ -848,11 +849,7 @@ export default function MonacoEditor({ smoothScrolling: true, cursorSmoothCaretAnimation: 'off', padding: { top: 0 }, - find: { - addExtraSpaceOnTop: false, - autoFindInSelection: 'never', - seedSearchStringFromSelection: 'never' - }, + find: monacoFindOptions, // Why: Monaco owns its rendered line surface, so align its selection-clipboard with the app opt-out (the global DOM hook can't). selectionClipboard: settings?.primarySelectionMiddleClickPaste ?? isLinuxUserAgent() }} diff --git a/src/renderer/src/components/editor/monaco-find-options.test.ts b/src/renderer/src/components/editor/monaco-find-options.test.ts new file mode 100644 index 000000000..8bf024a5e --- /dev/null +++ b/src/renderer/src/components/editor/monaco-find-options.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from 'vitest' +import { monacoFindOptions } from './monaco-find-options' + +describe('monacoFindOptions', () => { + it('seeds Find only from an explicit selection without changing its layout or scope', () => { + expect(monacoFindOptions).toEqual({ + addExtraSpaceOnTop: false, + autoFindInSelection: 'never', + seedSearchStringFromSelection: 'selection' + }) + }) +}) diff --git a/src/renderer/src/components/editor/monaco-find-options.ts b/src/renderer/src/components/editor/monaco-find-options.ts new file mode 100644 index 000000000..fa0e0589f --- /dev/null +++ b/src/renderer/src/components/editor/monaco-find-options.ts @@ -0,0 +1,7 @@ +import type { editor } from 'monaco-editor' + +export const monacoFindOptions = { + addExtraSpaceOnTop: false, + autoFindInSelection: 'never', + seedSearchStringFromSelection: 'selection' +} satisfies editor.IEditorFindOptions