Просмотр исходного кода

Select matched text when a file is opened from a full project search result (#23139)

GitOrigin-RevId: bd3b66e89b70c4fa1d77e401d9e5fa755876ce9f
Alf Eaton 1 год назад
Родитель
Сommit
9e040d6946

+ 2 - 1
services/web/frontend/js/features/ide-react/context/editor-manager-context.tsx

@@ -246,7 +246,8 @@ export const EditorManagerProvider: FC = ({ children }) => {
       goToLineEmitter(
       goToLineEmitter(
         options.gotoLine,
         options.gotoLine,
         options.gotoColumn ?? 0,
         options.gotoColumn ?? 0,
-        options.syncToPdf ?? false
+        options.syncToPdf ?? false,
+        options.selectionLength
       )
       )
     },
     },
     [goToLineEmitter]
     [goToLineEmitter]

+ 1 - 0
services/web/frontend/js/features/ide-react/types/goto-line-options.ts

@@ -1,5 +1,6 @@
 export interface GotoLineOptions {
 export interface GotoLineOptions {
   gotoLine: number
   gotoLine: number
   gotoColumn?: number
   gotoColumn?: number
+  selectionLength?: number
   syncToPdf?: boolean
   syncToPdf?: boolean
 }
 }

+ 5 - 2
services/web/frontend/js/features/source-editor/extensions/cursor-position.ts

@@ -134,14 +134,17 @@ const dispatchSelectionAndScroll = (
 export const setCursorLineAndScroll = (
 export const setCursorLineAndScroll = (
   view: EditorView,
   view: EditorView,
   lineNumber: number,
   lineNumber: number,
-  columnNumber = 0
+  columnNumber = 0,
+  selectionLength?: number
 ) => {
 ) => {
   // TODO: map the position through any changes since the previous compile?
   // TODO: map the position through any changes since the previous compile?
 
 
   let selectionRange
   let selectionRange
   try {
   try {
     const pos = findValidPosition(view.state.doc, lineNumber, columnNumber)
     const pos = findValidPosition(view.state.doc, lineNumber, columnNumber)
-    selectionRange = EditorSelection.cursor(pos)
+    selectionRange = selectionLength
+      ? EditorSelection.range(pos, pos + selectionLength)
+      : EditorSelection.cursor(pos)
   } catch (error) {
   } catch (error) {
     // ignore invalid cursor position
     // ignore invalid cursor position
     debugConsole.debug('invalid cursor position', error)
     debugConsole.debug('invalid cursor position', error)

+ 2 - 2
services/web/frontend/js/features/source-editor/hooks/use-codemirror-scope.ts

@@ -468,8 +468,8 @@ function useCodeMirrorScope(view: EditorView) {
   const emitSyncToPdf = useScopeEventEmitter('cursor:editor:syncToPdf')
   const emitSyncToPdf = useScopeEventEmitter('cursor:editor:syncToPdf')
 
 
   const handleGoToLine = useCallback(
   const handleGoToLine = useCallback(
-    (event, lineNumber, columnNumber, syncToPdf) => {
-      setCursorLineAndScroll(view, lineNumber, columnNumber)
+    (event, lineNumber, columnNumber, syncToPdf, selectionLength) => {
+      setCursorLineAndScroll(view, lineNumber, columnNumber, selectionLength)
       if (syncToPdf) {
       if (syncToPdf) {
         emitSyncToPdf()
         emitSyncToPdf()
       }
       }