Browse Source

Find sidebar empty name support (#826)

Lutz Roeder 4 years ago
parent
commit
f60c0c74fe
2 changed files with 64 additions and 55 deletions
  1. 57 52
      source/view-sidebar.js
  2. 7 3
      source/view.js

+ 57 - 52
source/view-sidebar.js

@@ -1351,65 +1351,67 @@ sidebar.FindSidebar = class {
         const nodes = new Set();
         const edges = new Set();
 
-        for (const node of this._graph.nodes) {
-
+        for (const v of this._graph.nodes()) {
+            const node = this._graph.node(v);
             const initializers = [];
-
-            for (const input of node.inputs) {
-                for (const argument of input.arguments) {
-                    if (argument.name && !edges.has(argument.name)) {
-                        const match = (argument, term) => {
-                            if (argument.name && argument.name.toLowerCase().indexOf(term) !== -1) {
-                                return true;
-                            }
-                            if (argument.type) {
-                                if (argument.type.dataType && term === argument.type.dataType.toLowerCase()) {
+            if (node.class === 'graph-node' || node.class === 'graph-input') {
+                for (const input of node.inputs) {
+                    for (const argument of input.arguments) {
+                        if (argument.name && !edges.has(argument.name)) {
+                            const match = (argument, term) => {
+                                if (argument.name && argument.name.toLowerCase().indexOf(term) !== -1) {
                                     return true;
                                 }
-                                if (argument.type.shape) {
-                                    if (term === argument.type.shape.toString().toLowerCase()) {
+                                if (argument.type) {
+                                    if (argument.type.dataType && term === argument.type.dataType.toLowerCase()) {
                                         return true;
                                     }
-                                    if (argument.type.shape && Array.isArray(argument.type.shape.dimensions)) {
-                                        const dimensions = argument.type.shape.dimensions.map((dimension) => dimension ? dimension.toString().toLowerCase() : '');
-                                        if (term === dimensions.join(',')) {
+                                    if (argument.type.shape) {
+                                        if (term === argument.type.shape.toString().toLowerCase()) {
                                             return true;
                                         }
-                                        if (dimensions.some((dimension) => term === dimension)) {
-                                            return true;
+                                        if (argument.type.shape && Array.isArray(argument.type.shape.dimensions)) {
+                                            const dimensions = argument.type.shape.dimensions.map((dimension) => dimension ? dimension.toString().toLowerCase() : '');
+                                            if (term === dimensions.join(',')) {
+                                                return true;
+                                            }
+                                            if (dimensions.some((dimension) => term === dimension)) {
+                                                return true;
+                                            }
                                         }
                                     }
                                 }
-                            }
-                            return false;
-                        };
-                        if (terms.every((term) => match(argument, term))) {
-                            if (!argument.initializer) {
-                                const inputItem = this._host.document.createElement('li');
-                                inputItem.innerText = '\u2192 ' + argument.name.split('\n').shift(); // custom argument id
-                                inputItem.id = 'edge-' + argument.name;
-                                this._resultElement.appendChild(inputItem);
-                                edges.add(argument.name);
-                            }
-                            else {
-                                initializers.push(argument);
+                                return false;
+                            };
+                            if (terms.every((term) => match(argument, term))) {
+                                if (!argument.initializer) {
+                                    const inputItem = this._host.document.createElement('li');
+                                    inputItem.innerText = '\u2192 ' + argument.name.split('\n').shift(); // custom argument id
+                                    inputItem.id = 'edge-' + argument.name;
+                                    this._resultElement.appendChild(inputItem);
+                                    edges.add(argument.name);
+                                }
+                                else {
+                                    initializers.push(argument);
+                                }
                             }
                         }
                     }
                 }
             }
-
-            const name = node.name;
-            const type = node.type.name;
-            if (name && !nodes.has(name) &&
-                terms.every((term) => name.toLowerCase().indexOf(term) != -1 || (type && type.toLowerCase().indexOf(term) != -1))) {
-                const nameItem = this._host.document.createElement('li');
-                nameItem.innerText = '\u25A2 ' + node.name;
-                nameItem.id = 'node-name-' + node.name;
-                this._resultElement.appendChild(nameItem);
-                nodes.add(node.name);
+            if (node.class === 'graph-node') {
+                const name = node.value.name;
+                const type = node.value.type.name;
+                if (!nodes.has(node.id) &&
+                    ((name && terms.some((term) => name.toLowerCase().indexOf(term) != -1) ||
+                     (type && terms.some((term) => type.toLowerCase().indexOf(term) != -1))))) {
+                    const nameItem = this._host.document.createElement('li');
+                    nameItem.innerText = '\u25A2 ' + (name || '[' + type + ']');
+                    nameItem.id = node.id;
+                    this._resultElement.appendChild(nameItem);
+                    nodes.add(node.id);
+                }
             }
-
             for (const argument of initializers) {
                 if (argument.name) {
                     const initializeItem = this._host.document.createElement('li');
@@ -1420,15 +1422,18 @@ sidebar.FindSidebar = class {
             }
         }
 
-        for (const node of this._graph.nodes) {
-            for (const output of node.outputs) {
-                for (const argument of output.arguments) {
-                    if (argument.name && !edges.has(argument.name) && terms.every((term) => argument.name.toLowerCase().indexOf(term) != -1)) {
-                        const outputItem = this._host.document.createElement('li');
-                        outputItem.innerText = '\u2192 ' + argument.name.split('\n').shift(); // custom argument id
-                        outputItem.id = 'edge-' + argument.name;
-                        this._resultElement.appendChild(outputItem);
-                        edges.add(argument.name);
+        for (const v of this._graph.nodes()) {
+            const node = this._graph.node(v);
+            if (node.class === 'graph-node' || node.class === 'graph-output') {
+                for (const output of node.outputs) {
+                    for (const argument of output.arguments) {
+                        if (argument.name && !edges.has(argument.name) && terms.every((term) => argument.name.toLowerCase().indexOf(term) != -1)) {
+                            const outputItem = this._host.document.createElement('li');
+                            outputItem.innerText = '\u2192 ' + argument.name.split('\n').shift(); // custom argument id
+                            outputItem.id = 'edge-' + argument.name;
+                            this._resultElement.appendChild(outputItem);
+                            edges.add(argument.name);
+                        }
                     }
                 }
             }

+ 7 - 3
source/view.js

@@ -111,11 +111,10 @@ view.View = class {
     }
 
     find() {
-        const graph = this.activeGraph;
-        if (graph) {
+        if (this._viewGraph) {
             this.clearSelection();
             const graphElement = this._getElementById('canvas');
-            const view = new sidebar.FindSidebar(this._host, graphElement, graph);
+            const view = new sidebar.FindSidebar(this._host, graphElement, this._viewGraph);
             view.on('search-text-changed', (sender, text) => {
                 this._searchText = text;
             });
@@ -501,6 +500,7 @@ view.View = class {
                     }
                 }
             }
+            this._viewGraph = null;
             return this.renderGraph(model, graph).then(() => {
                 this._model = model;
                 this._graphs = graphs;
@@ -510,6 +510,7 @@ view.View = class {
                 update();
                 return this._model;
             }).catch((error) => {
+                this._viewGraph = null;
                 return this.renderGraph(this._model, this.activeGraph).then(() => {
                     if (!graphs || graphs.length <= 1) {
                         this.show('default');
@@ -748,6 +749,9 @@ view.View = class {
                         const top = (container.scrollTop + (canvasRect.height / 2) - graphRect.top) - (graphRect.height / 2);
                         container.scrollTo({ left: left, top: top, behavior: 'auto' });
                     }
+
+                    this._viewGraph = viewGraph;
+
                     return;
                 });
             }