Add next/previous in editor IDE

pull/3094/head
ninabreznik 7 years ago committed by yann300
parent 51a0129363
commit 815c07ec74
  1. 3
      src/app.js
  2. 34
      src/app/editor/contextView.js
  3. 12
      src/app/editor/editor.js

@ -349,6 +349,7 @@ function run () {
// ---------------- ContextView ----------------------- // ---------------- ContextView -----------------------
this._components.contextView = new ContextView({ this._components.contextView = new ContextView({
contextualListener: this._components.contextualListener, contextualListener: this._components.contextualListener,
editor: editor,
jumpTo: (position) => { jumpTo: (position) => {
if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) { if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) {
var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult) var lineColumn = offsetToLineColumnConverter.offsetToLineColumn(position, position.file, compiler.lastCompilationResult)
@ -357,7 +358,7 @@ function run () {
fileManager.switchFile(filename) fileManager.switchFile(filename)
} }
if (lineColumn.start && lineColumn.start.line && lineColumn.start.column) { 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 { .name {
font-weight : bold; font-weight : bold;
margin-right : 15px; margin-right : 15px;
cursor : pointer;
} }
.jumpto { .jump {
cursor : pointer; cursor : pointer;
margin-right : 5px; margin : 0 5px;
color : ${styles.editor.icon_Color_Editor}; color : ${styles.editor.icon_Color_Editor};
} }
jumpto:hover { .jump:hover {
color : ${styles.editor.icon_HoverColor_Editor}; color : ${styles.editor.icon_HoverColor_Editor};
} }
.referencesnb { .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}> return yo`<div class=${css.line}>
<i class="fa fa-share ${css.jump}" aria-hidden="true" onclick=${jumpTo}></i>
<div title=${type} class=${css.type}>${type}</div> <div title=${type} class=${css.type}>${type}</div>
<div title=${node.attributes.name} class=${css.name}>${node.attributes.name}</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>
<span class=${css.referencesnb}>${references}</span> <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>` </div>`
} }
} }

@ -226,9 +226,7 @@ function Editor (opts = {}) {
editor.gotoLine(line + 1, col - 1, true) editor.gotoLine(line + 1, col - 1, true)
} }
this.find = function (string) { this.find = (string) => editor.find(string)
editor.find(string)
}
// Do setup on initialisation here // Do setup on initialisation here
editor.on('changeSession', function () { editor.on('changeSession', function () {
@ -242,14 +240,6 @@ function Editor (opts = {}) {
// Unmap ctrl-t & ctrl-f // Unmap ctrl-t & ctrl-f
editor.commands.bindKeys({ 'ctrl-t': null }) 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) editor.resize(true)
} }

Loading…
Cancel
Save