From 0c9de4f157d07e5f577b5d2f2a557bd88b79e0ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Wed, 18 Mar 2020 16:22:51 +0100
Subject: [PATCH] [ivette] ast scrolling to current marker

---
 ivette/src/renderer/ASTview.js | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/ivette/src/renderer/ASTview.js b/ivette/src/renderer/ASTview.js
index e220194a0f3..db6830d63c5 100644
--- a/ivette/src/renderer/ASTview.js
+++ b/ivette/src/renderer/ASTview.js
@@ -20,13 +20,12 @@ import 'codemirror/theme/ambiance.css' ;
 // --- Rich Text Printer
 // --------------------------------------------------------------------------
 
-const print = async (buffer, text) => {
+const print = (buffer, text) => {
   if (Array.isArray(text)) {
     const tag = text.shift();
     if (tag !== '')
       buffer.openTextMarker( { id:tag } );
-    for (const k in text)
-      await print(buffer, text[k]);
+    text.forEach(txt => print(buffer, txt));
     if (tag !== '')
       buffer.closeTextMarker();
   } else if (typeof(text)==='string')
@@ -51,16 +50,22 @@ const ASTview = () => {
     if (theFunction) {
       buffer.log('// Loading',theFunction,'…');
       Server
-      .sendGET("kernel.ast.printFunction", theFunction)
-      .then(data => {
-        buffer.clear();
-        if (!data)
-          buffer.log('// No code for function ', theFunction);
-        return print(buffer,data);
+        .sendGET("kernel.ast.printFunction", theFunction)
+        .then(data => {
+          buffer.clear();
+          if (!data)
+            buffer.log('// No code for function ', theFunction);
+          print(buffer,data);
+          if (theMarker) buffer.scroll( theMarker );
       });
     }
   }, [ theFunction ] );
 
+  // Hook: scrolling
+  React.useEffect( () => {
+    if (theMarker) buffer.scroll( theMarker );
+  }, [ theMarker ] );
+
   // Callbacks
   const onSelection = marker => setSelect({ marker });
 
-- 
GitLab