Add next/previous in editor IDE

pull/1/head
ninabreznik 7 years ago committed by yann300
parent 02311a071c
commit 5a404f06ab
  1. 3
      src/app.js
  2. 38
      src/app/editor/contextView.js
  3. 12
      src/app/editor/editor.js

@ -349,6 +349,7 @@ function run () {
// ---------------- ContextView -----------------------
this._components.contextView = new ContextView({
contextualListener: this._components.contextualListener,
editor: editor,
jumpTo: (position) => {
if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) {
var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult)
@ -357,7 +358,7 @@ function run () {
fileManager.switchFile(filename)
}
if (lineColumn.start && lineColumn.start.line && lineColumn.start.column) {
editor.gotoLine(lineColumn.start.line, lineColumn.start.column + 1)
editor.gotoLine(lineColumn.start.line, lineColumn.end.column + 1)
}
}
}

@ -30,13 +30,14 @@ var css = csjs`
.name {
font-weight : bold;
margin-right : 15px;
cursor : pointer;
}
.jumpto {
.jump {
cursor : pointer;
margin-right : 5px;
margin : 0 5px;
color : ${styles.editor.icon_Color_Editor};
}
jumpto:hover {
.jump:hover {
color : ${styles.editor.icon_HoverColor_Editor};
}
.referencesnb {
@ -129,11 +130,36 @@ 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._activeHighlights
self._api.jumpTo(nodes[this.ref].position)
this.ref = (this.ref + 1) % nodes.length
this.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._activeHighlights
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
}
return yo`<div class=${css.line}>
<div title=${type} class=${css.type} >${type}</div>
<div title=${node.attributes.name} class=${css.name} >${node.attributes.name}</div>
<i title='Go to Definition' class="fa fa-share ${css.jumpto}" aria-hidden="true" onclick=${jumpTo}></i>
<i class="fa fa-share ${css.jump}" aria-hidden="true" onclick=${jumpTo}></i>
<div title=${type} class=${css.type}>${type}</div>
<div title=${node.attributes.name} class=${css.name}>${node.attributes.name}</div>
<span class=${css.referencesnb}>${references}</span>
<i class="fa fa-chevron-up ${css.jump}" aria-hidden="true" onclick=${previous}></i>
<i class="fa fa-chevron-down ${css.jump}" aria-hidden="true" onclick=${next}></i>
</div>`
}
}

@ -226,9 +226,7 @@ function Editor (opts = {}) {
editor.gotoLine(line + 1, col - 1, true)
}
this.find = function (string) {
editor.find(string)
}
this.find = (string) => editor.find(string)
// Do setup on initialisation here
editor.on('changeSession', function () {
@ -242,14 +240,6 @@ function Editor (opts = {}) {
// Unmap ctrl-t & ctrl-f
editor.commands.bindKeys({ 'ctrl-t': null })
editor.commands.addCommand({
name: "myCommand",
bindKey: { win: "Ctrl-L", mac: "Command-L" },
exec: function() {
editor.insert("Key binded!");
}
});
editor.resize(true)
}

Loading…
Cancel
Save