Răsfoiți Sursa

Scroll editor line into view after inserting a symbol (#6164)

GitOrigin-RevId: 20f80ec93148d36f951c956a942021f01490d120
Alf Eaton 4 ani în urmă
părinte
comite
6dec7fab63

+ 4 - 0
services/web/frontend/js/ide/editor/EditorManager.js

@@ -56,6 +56,10 @@ export default EditorManager = (function () {
         },
         },
       }
       }
 
 
+      window.addEventListener('editor:insert-symbol', event => {
+        this.$scope.editor.insertSymbol(event.detail)
+      })
+
       this.$scope.$on('entity:selected', (event, entity) => {
       this.$scope.$on('entity:selected', (event, entity) => {
         if (this.$scope.ui.view !== 'history' && entity.type === 'doc') {
         if (this.$scope.ui.view !== 'history' && entity.type === 'doc') {
           return this.openDoc(entity)
           return this.openDoc(entity)

+ 8 - 1
services/web/frontend/js/shared/context/editor-context.js

@@ -77,7 +77,6 @@ export function EditorProvider({ children, settings }) {
   const [permissionsLevel] = useScopeValue('permissionsLevel')
   const [permissionsLevel] = useScopeValue('permissionsLevel')
   const [showSymbolPalette] = useScopeValue('editor.showSymbolPalette')
   const [showSymbolPalette] = useScopeValue('editor.showSymbolPalette')
   const [toggleSymbolPalette] = useScopeValue('editor.toggleSymbolPalette')
   const [toggleSymbolPalette] = useScopeValue('editor.toggleSymbolPalette')
-  const [insertSymbol] = useScopeValue('editor.insertSymbol')
 
 
   useEffect(() => {
   useEffect(() => {
     if (ide?.socket) {
     if (ide?.socket) {
@@ -119,6 +118,14 @@ export function EditorProvider({ children, settings }) {
     )
     )
   }, [projectName, setTitle])
   }, [projectName, setTitle])
 
 
+  const insertSymbol = useCallback(symbol => {
+    window.dispatchEvent(
+      new CustomEvent('editor:insert-symbol', {
+        detail: symbol,
+      })
+    )
+  }, [])
+
   const value = useMemo(
   const value = useMemo(
     () => ({
     () => ({
       cobranding,
       cobranding,