From f49a69363413464bbf0f24b82971219be20e8b1f Mon Sep 17 00:00:00 2001 From: ninabreznik Date: Tue, 28 Nov 2017 06:26:00 +0100 Subject: [PATCH] Work in progress - debugging getActiveHighlights in connection with next/previous --- src/app/editor/contextView.js | 49 +++++++++++++++++++--------- src/app/editor/contextualListener.js | 3 ++ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/app/editor/contextView.js b/src/app/editor/contextView.js index 0f3ff374c7..b24c4b32ca 100644 --- a/src/app/editor/contextView.js +++ b/src/app/editor/contextView.js @@ -115,7 +115,6 @@ class ContextView { } _render (node) { - console.log('rendering') if (!node) return yo`
` var self = this var references = this._api.contextualListener.referencesOf(node) @@ -132,26 +131,44 @@ class ContextView { } function next () { - var currentName = node.attributes.name - if (currentName === this.refName) { - this.ref = this.ref === undefined ? 0 : this.ref - } else { this.ref = 0 } var nodes = self._api.contextualListener.getActiveHighlights() - self._api.jumpTo(nodes[this.ref].position) - this.ref = (this.ref + 1) % nodes.length - this.refName = currentName + var currentName = node.attributes.name + var position = self.sourceMappingDecoder.decode(node.src) + + if (currentName !== self.refName) self.ref = 0 + var k = self.ref + + /// LOGS /// + nodes.forEach(node => console.log(node.position.start)) + console.log('----') + console.log(k) + console.log('----') + + var pos = nodes[k].position + self._api.jumpTo(pos) + + self.ref = (self.ref + 1) % nodes.length + self.refName = currentName } function previous () { - var currentName = node.attributes.name - if (currentName === this.refName) { - this.ref = this.ref === undefined ? 0 : this.ref - } else { this.ref = 0 } // should be this.ref = ref of the selected node (loop through all nodes to find this one) var nodes = self._api.contextualListener.getActiveHighlights() - this.ref = this.ref === undefined ? 0 : this.ref - self._api.jumpTo(nodes[nodes.length - 1 - this.ref].position) - this.ref = (this.ref + 1) % nodes.length - this.refName = currentName + var currentName = node.attributes.name + if (currentName !== self.refName) self.ref = nodes.length - 1 + + var k = nodes.length - 1 - self.ref + + /// LOGS /// + nodes.forEach(node => console.log(node.position.start)) + console.log('----') + console.log(k) + console.log('----') + + var pos = nodes[k].position + self._api.jumpTo(pos) + + self.ref = (self.ref + 1) % nodes.length + self.refName = currentName } return yo`
diff --git a/src/app/editor/contextualListener.js b/src/app/editor/contextualListener.js index 33dada2539..4739e9bcca 100644 --- a/src/app/editor/contextualListener.js +++ b/src/app/editor/contextualListener.js @@ -39,6 +39,9 @@ class ContextualListener { getActiveHighlights () { return [...this._activeHighlights] + // return [...this._activeHighlights].sort((a,b) => { + // return a.position.start - b.position.start + // }) } declarationOf (node) {