Commit 2f7e42a6 authored by Franco Pariani's avatar Franco Pariani
Browse files

Showing function definition above the call with the file name in bold

parent 5e790b42
module.exports = {
Completion: function(cm, options) {
return Completion(cm, options);
},
parseOptions: function(cm, pos, options) {
return parseOptions(cm, pos, options);
}
}
......@@ -28,7 +28,6 @@
const hintWords = require('./hint_words');
var HINT_ELEMENT_CLASS = "CodeMirror-hint";
var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
var mac = /Mac/.test(navigator.platform);
function parseOptions(cm, pos, options) {
......@@ -43,7 +42,8 @@
return out;
}
function Completion(cm, options) {
function Completion(cm, options, filename) {
this.filename = filename;
this.cm = cm;
this.options = options;
this.widget = null;
......@@ -200,18 +200,22 @@
var completions = data.list;
for (var i = 0; i < completions.length; ++i) {
var elt = hints.appendChild(ownerDocument.createElement("li")), cur = completions[i];
var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
var className = HINT_ELEMENT_CLASS;
if (cur.className != null) className = cur.className + " " + className;
elt.className = className;
if (cur.render) cur.render(elt, data, cur);
else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur)));
else {
var rexp_name = new RegExp(/(.*\:\:)(.*)/.source, "g");
var m = rexp_name.exec(cur.displayText || getText(cur));
var b_elem = ownerDocument.createElement("b");
b_elem.appendChild(ownerDocument.createTextNode(completion.filename + '.' + m[1]));
elt.appendChild(b_elem);
elt.appendChild(ownerDocument.createTextNode(m[2]));
}
elt.hintId = i;
}
var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
var left = pos.left, top = pos.bottom, below = true;
hints.style.left = left + "px";
hints.style.top = top + "px";
// If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth);
var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight);
......@@ -220,20 +224,20 @@
var scrolls = hints.scrollHeight > hints.clientHeight + 1
var startScroll = cm.getScrollInfo();
if (overlapY > 0) {
var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
if (curTop - height > 0) { // Fits above cursor
hints.style.top = (top = pos.top - height) + "px";
below = false;
} else if (height > winH) {
hints.style.height = (winH - 5) + "px";
hints.style.top = (top = pos.bottom - box.top) + "px";
var cursor = cm.getCursor();
if (data.from.ch != cursor.ch) {
pos = cm.cursorCoords(cursor);
hints.style.left = (left = pos.left) + "px";
box = hints.getBoundingClientRect();
}
var height = box.bottom - box.top;
var left = pos.left - 1;
hints.style.left = left + "px";
hints.style.top = (pos.top - height) + "px";
var below = false;
if (overlapY > 0 && height > winH) {
hints.style.height = (winH - 5) + "px";
hints.style.top = (top = pos.bottom - box.top) + "px";
var cursor = cm.getCursor();
if (data.from.ch != cursor.ch) {
pos = cm.cursorCoords(cursor);
hints.style.left = (left = pos.left) + "px";
box = hints.getBoundingClientRect();
}
}
var overlapX = box.right - winW;
......@@ -274,16 +278,11 @@
});
CodeMirror.on(hints, "dblclick", function(e) {
var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
completion.close();
});
CodeMirror.on(hints, "click", function(e) {
var t = getHintElement(hints, e.target || e.srcElement);
if (t && t.hintId != null) {
widget.changeActive(t.hintId);
if (completion.options.completeOnSingleClick) widget.pick();
}
completion.close();
});
CodeMirror.on(hints, "mousedown", function() {
......@@ -415,7 +414,7 @@
hint: CodeMirror.hint.auto,
completeSingle: true,
alignWithWord: true,
closeCharacters: /[\s()\[\]{};:>,]/,
closeCharacters: /./,
closeOnUnfocus: true,
completeOnSingleClick: true,
container: null,
......@@ -439,10 +438,10 @@
// functions definitions
CodeMirror.defineExtension("functionDefinition", function(options) {
CodeMirror.defineExtension("functionDefinition", function(filename, options) {
options = parseOptions(this, this.getCursor("start"), options);
if (this.state.completionActive) this.state.completionActive.close();
var completion = this.state.completionActive = new Completion(this, options);
var completion = this.state.completionActive = new Completion(this, options, filename);
//if (!completion.options.hint) return;
CodeMirror.signal(this, "startFunctionDefinition", this);
......
......@@ -457,7 +457,7 @@ export class MateFunComponent {
}
clickEnEditor(event){
this.codemirror.instance.functionDefinition(this.codemirror.instance.doc, event);
this.codemirror.instance.functionDefinition(this.archivo.nombre, this.codemirror.instance.doc, event);
}
guardarArchivo(){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment