cleanup
This commit is contained in:
parent
dc198344d5
commit
68ebf08e8c
4 changed files with 279 additions and 290 deletions
|
|
@ -31,25 +31,9 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var EditSession = require("./edit_session").EditSession;
|
|
||||||
var Renderer = require("./virtual_renderer").VirtualRenderer;
|
|
||||||
var Range = require("./range").Range;
|
var Range = require("./range").Range;
|
||||||
var event = require("./lib/event");
|
|
||||||
var lang = require("./lib/lang");
|
|
||||||
|
|
||||||
var dom = require("./lib/dom");
|
|
||||||
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
var HashHandler = require("./keyboard/hash_handler").HashHandler;
|
||||||
var TextMode = require("./mode/text").Mode;
|
var AcePopup = require("./autocomplete/popup").AcePopup;
|
||||||
|
|
||||||
var WorkerClient = require("./worker/worker_client").WorkerClient;
|
|
||||||
var worker = new WorkerClient(["ace"], "ace/autocomplete/autocomplete_worker", "AutocompleteWorker");
|
|
||||||
|
|
||||||
var mode = new TextMode();
|
|
||||||
mode.$tokenizer = {
|
|
||||||
getLineTokens: function(line) {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var Autocomplete = function() {
|
var Autocomplete = function() {
|
||||||
this.keyboardHandler = new HashHandler();
|
this.keyboardHandler = new HashHandler();
|
||||||
|
|
@ -62,7 +46,7 @@ var Autocomplete = function() {
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
this.$init = function() {
|
this.$init = function() {
|
||||||
this.popup = new AcePopup();
|
this.popup = new AcePopup(document.body || document.documentElement);
|
||||||
this.popup.on("click", function(e) {
|
this.popup.on("click", function(e) {
|
||||||
this.insertMatch();
|
this.insertMatch();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
@ -150,13 +134,13 @@ var Autocomplete = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.commands = {
|
this.commands = {
|
||||||
"up": function(editor) { editor.completer.goTo("up"); },
|
"Up": function(editor) { editor.completer.goTo("up"); },
|
||||||
"down": function(editor) { editor.completer.goTo("down"); },
|
"Down": function(editor) { editor.completer.goTo("down"); },
|
||||||
"ctrl-up": function(editor) { editor.completer.goTo("start"); },
|
"Ctrl-Up": function(editor) { editor.completer.goTo("start"); },
|
||||||
"ctrl-down": function(editor) { editor.completer.goTo("end"); },
|
"Ctrl-Down": function(editor) { editor.completer.goTo("end"); },
|
||||||
|
|
||||||
"esc": function(editor) { editor.completer.detach(); },
|
"Esc": function(editor) { editor.completer.detach(); },
|
||||||
"space": function(editor) { editor.completer.detach(); editor.insert(" ");},
|
"Space": function(editor) { editor.completer.detach(); editor.insert(" ");},
|
||||||
"Return": function(editor) { editor.completer.insertMatch(); },
|
"Return": function(editor) { editor.completer.insertMatch(); },
|
||||||
"Shift-Return": function(editor) { editor.completer.insertMatch(true); },
|
"Shift-Return": function(editor) { editor.completer.insertMatch(true); },
|
||||||
"Tab": function(editor) { editor.completer.insertMatch(); }
|
"Tab": function(editor) { editor.completer.insertMatch(); }
|
||||||
|
|
@ -223,228 +207,6 @@ var FilteredList = function(array, mutateData) {
|
||||||
|
|
||||||
}).call(FilteredList.prototype);
|
}).call(FilteredList.prototype);
|
||||||
|
|
||||||
|
|
||||||
var $singleLineEditor = function(el) {
|
|
||||||
var renderer = new Renderer(el);
|
|
||||||
el.style.overflow = "hidden";
|
|
||||||
renderer.scrollBar.element.style.top = "0";
|
|
||||||
renderer.scrollBar.element.style.display = "none";
|
|
||||||
renderer.scrollBar.orginalWidth = renderer.scrollBar.width;
|
|
||||||
renderer.scrollBar.width = 0;
|
|
||||||
renderer.content.style.height = "auto";
|
|
||||||
|
|
||||||
renderer.screenToTextCoordinates = function(x, y) {
|
|
||||||
var pos = this.pixelToScreenCoordinates(x, y);
|
|
||||||
return this.session.screenToDocumentPosition(
|
|
||||||
Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
|
|
||||||
Math.max(pos.column, 0)
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
renderer.maxLines = 4;
|
|
||||||
renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig;
|
|
||||||
renderer.$computeLayerConfig = function() {
|
|
||||||
var config = this.layerConfig;
|
|
||||||
var height = this.session.getScreenLength() * this.lineHeight;
|
|
||||||
var maxHeight = this.maxLines * this.lineHeight
|
|
||||||
var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height))
|
|
||||||
var vScroll = height > maxHeight;
|
|
||||||
if (desiredHeight != this.desiredHeight || vScroll != this.$vScroll) {
|
|
||||||
if (vScroll != this.$vScroll) {
|
|
||||||
if (vScroll) {
|
|
||||||
this.scrollBar.element.style.display = "";
|
|
||||||
this.scrollBar.width = this.scrollBar.orginalWidth;
|
|
||||||
|
|
||||||
height = maxHeight;
|
|
||||||
this.scrollTop = height - this.maxLines * this.lineHeight;
|
|
||||||
} else {
|
|
||||||
this.scrollBar.element.style.display = "none";
|
|
||||||
this.scrollBar.width = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$size.height = 0;
|
|
||||||
this.$size.width = 0;
|
|
||||||
|
|
||||||
this.$vScroll = vScroll;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.container.style.height = desiredHeight + "px";
|
|
||||||
this.onResize();
|
|
||||||
this.$loop.changes = 0
|
|
||||||
this.desiredHeight = desiredHeight;
|
|
||||||
this.scroller.style.overflowX="hidden"
|
|
||||||
}
|
|
||||||
return renderer.$computeLayerConfigWithScroll();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var Editor = require("ace/editor").Editor;
|
|
||||||
var editor = new Editor(renderer);
|
|
||||||
|
|
||||||
editor.setHighlightActiveLine(false);
|
|
||||||
editor.setShowPrintMargin(false);
|
|
||||||
editor.renderer.setShowGutter(false);
|
|
||||||
editor.renderer.setHighlightGutterLine(false);
|
|
||||||
|
|
||||||
editor.$mouseHandler.$focusWaitTimout = 0;
|
|
||||||
|
|
||||||
return editor;
|
|
||||||
};
|
|
||||||
|
|
||||||
var AcePopup = function(e) {
|
|
||||||
var el = dom.createElement("div");
|
|
||||||
var popup = new $singleLineEditor(el);
|
|
||||||
document.body.appendChild(el);
|
|
||||||
el.style.display = "none";
|
|
||||||
popup.renderer.content.style.cursor = "default";
|
|
||||||
popup.renderer.setStyle("ace_autocomplete");
|
|
||||||
|
|
||||||
var noop = function(){};
|
|
||||||
|
|
||||||
popup.focus = noop;
|
|
||||||
popup.$isFocused = true;
|
|
||||||
|
|
||||||
popup.renderer.$cursorLayer.restartTimer = noop;
|
|
||||||
popup.renderer.$cursorLayer.element.style.opacity = 0;
|
|
||||||
|
|
||||||
popup.renderer.maxLines = 8
|
|
||||||
popup.renderer.$keepTextAreaAtCursor = false;
|
|
||||||
|
|
||||||
popup.setHighlightActiveLine(true);
|
|
||||||
popup.setSession(new EditSession(""));
|
|
||||||
|
|
||||||
popup.on("mousedown", function(e) {
|
|
||||||
var pos = e.getDocumentPosition();
|
|
||||||
popup.moveCursorToPosition(pos);
|
|
||||||
popup.selection.clearSelection();
|
|
||||||
e.stop();
|
|
||||||
});
|
|
||||||
|
|
||||||
popup.getRow = function() {
|
|
||||||
var line = this.getCursorPosition().row;
|
|
||||||
if (line == 0 && !this.getHighlightActiveLine())
|
|
||||||
line = -1;
|
|
||||||
return line;
|
|
||||||
};
|
|
||||||
|
|
||||||
popup.setRow = function(line) {
|
|
||||||
popup.setHighlightActiveLine(line != -1);
|
|
||||||
popup.selection.clearSelection();
|
|
||||||
popup.moveCursorTo(line, 0 || 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
var hoverMarker = new Range(-1,0,-1,Infinity);
|
|
||||||
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
|
|
||||||
popup.on("mousemove", function(e) {
|
|
||||||
//if (popup.lastOpened)
|
|
||||||
var row = e.getDocumentPosition().row;
|
|
||||||
hoverMarker.start.row = hoverMarker.end.row = row;
|
|
||||||
popup.session._emit("changeBackMarker");
|
|
||||||
});
|
|
||||||
var hideHoverMarker = function() {
|
|
||||||
hoverMarker.start.row = hoverMarker.end.row = -1;
|
|
||||||
popup.session._emit("changeBackMarker");
|
|
||||||
};
|
|
||||||
event.addListener(popup.container, "mouseout", hideHoverMarker);
|
|
||||||
popup.on("hide", hideHoverMarker);
|
|
||||||
popup.on("changeSelection", hideHoverMarker);
|
|
||||||
popup.on("mousewheel", function(e) {
|
|
||||||
setTimeout(function() {
|
|
||||||
popup._signal("mousemove", e);
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
popup.data = []
|
|
||||||
popup.setData = function(list) {
|
|
||||||
popup.data = list || [];
|
|
||||||
popup.setValue(lang.stringRepeat("\n", list.length), -1);
|
|
||||||
};
|
|
||||||
popup.session.doc.getLength = function() {
|
|
||||||
return popup.data.length;
|
|
||||||
};
|
|
||||||
popup.session.doc.getLine = function(i) {
|
|
||||||
var data = popup.data[i];
|
|
||||||
if (typeof data == "string")
|
|
||||||
return data;
|
|
||||||
return (data && data.value) || "";
|
|
||||||
};
|
|
||||||
|
|
||||||
var bgTokenizer = popup.session.bgTokenizer
|
|
||||||
bgTokenizer.$tokenizeRow = function(i) {
|
|
||||||
var data = popup.data[i];
|
|
||||||
var tokens = [];
|
|
||||||
if (!data)
|
|
||||||
return tokens;
|
|
||||||
if (typeof data == "string")
|
|
||||||
data = {type: data, value: data}//return [{type: "", value: data}];
|
|
||||||
|
|
||||||
tokens.push({type: "", value: data.value});
|
|
||||||
if (data.type) {
|
|
||||||
var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
|
|
||||||
if (data.type.length + data.value.length < maxW - 2)
|
|
||||||
tokens.push({type: "rightAlignedText", value: data.type});
|
|
||||||
}
|
|
||||||
return tokens;
|
|
||||||
};
|
|
||||||
bgTokenizer.$updateOnChange = noop
|
|
||||||
|
|
||||||
// highlight
|
|
||||||
popup.setHighlight = function(re) {
|
|
||||||
popup.session.highlight(re);
|
|
||||||
popup.session._emit("changeFrontMarker");
|
|
||||||
};
|
|
||||||
|
|
||||||
popup.hide = function() {
|
|
||||||
this.container.style.display = "none";
|
|
||||||
this._signal("hide");
|
|
||||||
}
|
|
||||||
|
|
||||||
popup.show = function(pos, lineHeight) {
|
|
||||||
var el = this.container;
|
|
||||||
if (pos.top > window.innerHeight / 2 + lineHeight) {
|
|
||||||
el.style.top = ""
|
|
||||||
el.style.bottom = window.innerHeight - pos.top + "px";
|
|
||||||
} else {
|
|
||||||
pos.top += lineHeight;
|
|
||||||
el.style.top = pos.top + "px";
|
|
||||||
el.style.bottom = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
el.style.left = pos.left + "px";
|
|
||||||
el.style.display = "";
|
|
||||||
|
|
||||||
this._signal("show");
|
|
||||||
}
|
|
||||||
return popup;
|
|
||||||
};
|
|
||||||
|
|
||||||
dom.importCssString("\
|
|
||||||
.ace_autocomplete.ace-tm .ace_marker-layer .ace_active-line {\
|
|
||||||
background-color: #abbffe;\
|
|
||||||
}\
|
|
||||||
.ace_autocomplete.ace-tm .ace_line-hover {\
|
|
||||||
border: 1px solid #abbffe;\
|
|
||||||
position: absolute;\
|
|
||||||
background: rgba(233,233,253,0.4);\
|
|
||||||
z-index: 2;\
|
|
||||||
margin-top: -1px;\
|
|
||||||
}\
|
|
||||||
.ace_rightAlignedText {\
|
|
||||||
color: gray;\
|
|
||||||
display: inline-block;\
|
|
||||||
position: absolute;\
|
|
||||||
right: 4px;\
|
|
||||||
text-align: right;\
|
|
||||||
z-index: -1;\
|
|
||||||
}\
|
|
||||||
.ace_autocomplete {\
|
|
||||||
width: 200px;\
|
|
||||||
z-index: 200000;\
|
|
||||||
background: #f8f8f8;\
|
|
||||||
border: 1px lightgray solid;\
|
|
||||||
position: fixed;\
|
|
||||||
}");
|
|
||||||
|
|
||||||
exports.Autocomplete = Autocomplete;
|
exports.Autocomplete = Autocomplete;
|
||||||
exports.FilteredList = FilteredList;
|
exports.FilteredList = FilteredList;
|
||||||
|
|
||||||
|
|
|
||||||
264
lib/ace/autocomplete/popup.js
Normal file
264
lib/ace/autocomplete/popup.js
Normal file
|
|
@ -0,0 +1,264 @@
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Distributed under the BSD license:
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012, Ajax.org B.V.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of Ajax.org B.V. nor the
|
||||||
|
* names of its contributors may be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
||||||
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
define(function(require, exports, module) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var EditSession = require("./edit_session").EditSession;
|
||||||
|
var Renderer = require("./virtual_renderer").VirtualRenderer;
|
||||||
|
var event = require("./lib/event");
|
||||||
|
var lang = require("./lib/lang");
|
||||||
|
var dom = require("./lib/dom");
|
||||||
|
|
||||||
|
var $singleLineEditor = function(el) {
|
||||||
|
var renderer = new Renderer(el);
|
||||||
|
el.style.overflow = "hidden";
|
||||||
|
renderer.scrollBar.element.style.top = "0";
|
||||||
|
renderer.scrollBar.element.style.display = "none";
|
||||||
|
renderer.scrollBar.orginalWidth = renderer.scrollBar.width;
|
||||||
|
renderer.scrollBar.width = 0;
|
||||||
|
renderer.content.style.height = "auto";
|
||||||
|
|
||||||
|
renderer.screenToTextCoordinates = function(x, y) {
|
||||||
|
var pos = this.pixelToScreenCoordinates(x, y);
|
||||||
|
return this.session.screenToDocumentPosition(
|
||||||
|
Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
|
||||||
|
Math.max(pos.column, 0)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
renderer.maxLines = 4;
|
||||||
|
renderer.$computeLayerConfigWithScroll = renderer.$computeLayerConfig;
|
||||||
|
renderer.$computeLayerConfig = function() {
|
||||||
|
var config = this.layerConfig;
|
||||||
|
var height = this.session.getScreenLength() * this.lineHeight;
|
||||||
|
var maxHeight = this.maxLines * this.lineHeight
|
||||||
|
var desiredHeight = Math.max(this.lineHeight, Math.min(maxHeight, height))
|
||||||
|
var vScroll = height > maxHeight;
|
||||||
|
if (desiredHeight != this.desiredHeight || vScroll != this.$vScroll) {
|
||||||
|
if (vScroll != this.$vScroll) {
|
||||||
|
if (vScroll) {
|
||||||
|
this.scrollBar.element.style.display = "";
|
||||||
|
this.scrollBar.width = this.scrollBar.orginalWidth;
|
||||||
|
|
||||||
|
height = maxHeight;
|
||||||
|
this.scrollTop = height - this.maxLines * this.lineHeight;
|
||||||
|
} else {
|
||||||
|
this.scrollBar.element.style.display = "none";
|
||||||
|
this.scrollBar.width = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.$size.height = 0;
|
||||||
|
this.$size.width = 0;
|
||||||
|
|
||||||
|
this.$vScroll = vScroll;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.container.style.height = desiredHeight + "px";
|
||||||
|
this.onResize();
|
||||||
|
this.$loop.changes = 0
|
||||||
|
this.desiredHeight = desiredHeight;
|
||||||
|
this.scroller.style.overflowX="hidden"
|
||||||
|
}
|
||||||
|
return renderer.$computeLayerConfigWithScroll();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var Editor = require("ace/editor").Editor;
|
||||||
|
var editor = new Editor(renderer);
|
||||||
|
|
||||||
|
editor.setHighlightActiveLine(false);
|
||||||
|
editor.setShowPrintMargin(false);
|
||||||
|
editor.renderer.setShowGutter(false);
|
||||||
|
editor.renderer.setHighlightGutterLine(false);
|
||||||
|
|
||||||
|
editor.$mouseHandler.$focusWaitTimout = 0;
|
||||||
|
|
||||||
|
return editor;
|
||||||
|
};
|
||||||
|
|
||||||
|
var AcePopup = function(parentNode) {
|
||||||
|
var el = dom.createElement("div");
|
||||||
|
var popup = new $singleLineEditor(el);
|
||||||
|
if (parentNode)
|
||||||
|
parentNode.appendChild(el);
|
||||||
|
el.style.display = "none";
|
||||||
|
popup.renderer.content.style.cursor = "default";
|
||||||
|
popup.renderer.setStyle("ace_autocomplete");
|
||||||
|
|
||||||
|
var noop = function(){};
|
||||||
|
|
||||||
|
popup.focus = noop;
|
||||||
|
popup.$isFocused = true;
|
||||||
|
|
||||||
|
popup.renderer.$cursorLayer.restartTimer = noop;
|
||||||
|
popup.renderer.$cursorLayer.element.style.opacity = 0;
|
||||||
|
|
||||||
|
popup.renderer.maxLines = 8
|
||||||
|
popup.renderer.$keepTextAreaAtCursor = false;
|
||||||
|
|
||||||
|
popup.setHighlightActiveLine(true);
|
||||||
|
popup.setSession(new EditSession(""));
|
||||||
|
|
||||||
|
popup.on("mousedown", function(e) {
|
||||||
|
var pos = e.getDocumentPosition();
|
||||||
|
popup.moveCursorToPosition(pos);
|
||||||
|
popup.selection.clearSelection();
|
||||||
|
e.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
popup.getRow = function() {
|
||||||
|
var line = this.getCursorPosition().row;
|
||||||
|
if (line == 0 && !this.getHighlightActiveLine())
|
||||||
|
line = -1;
|
||||||
|
return line;
|
||||||
|
};
|
||||||
|
|
||||||
|
popup.setRow = function(line) {
|
||||||
|
popup.setHighlightActiveLine(line != -1);
|
||||||
|
popup.selection.clearSelection();
|
||||||
|
popup.moveCursorTo(line, 0 || 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
var hoverMarker = new Range(-1,0,-1,Infinity);
|
||||||
|
hoverMarker.id = popup.session.addMarker(hoverMarker, "ace_line-hover", "fullLine");
|
||||||
|
popup.on("mousemove", function(e) {
|
||||||
|
//if (popup.lastOpened)
|
||||||
|
var row = e.getDocumentPosition().row;
|
||||||
|
hoverMarker.start.row = hoverMarker.end.row = row;
|
||||||
|
popup.session._emit("changeBackMarker");
|
||||||
|
});
|
||||||
|
var hideHoverMarker = function() {
|
||||||
|
hoverMarker.start.row = hoverMarker.end.row = -1;
|
||||||
|
popup.session._emit("changeBackMarker");
|
||||||
|
};
|
||||||
|
event.addListener(popup.container, "mouseout", hideHoverMarker);
|
||||||
|
popup.on("hide", hideHoverMarker);
|
||||||
|
popup.on("changeSelection", hideHoverMarker);
|
||||||
|
popup.on("mousewheel", function(e) {
|
||||||
|
setTimeout(function() {
|
||||||
|
popup._signal("mousemove", e);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
popup.data = []
|
||||||
|
popup.setData = function(list) {
|
||||||
|
popup.data = list || [];
|
||||||
|
popup.setValue(lang.stringRepeat("\n", list.length), -1);
|
||||||
|
};
|
||||||
|
popup.session.doc.getLength = function() {
|
||||||
|
return popup.data.length;
|
||||||
|
};
|
||||||
|
popup.session.doc.getLine = function(i) {
|
||||||
|
var data = popup.data[i];
|
||||||
|
if (typeof data == "string")
|
||||||
|
return data;
|
||||||
|
return (data && data.value) || "";
|
||||||
|
};
|
||||||
|
|
||||||
|
var bgTokenizer = popup.session.bgTokenizer
|
||||||
|
bgTokenizer.$tokenizeRow = function(i) {
|
||||||
|
var data = popup.data[i];
|
||||||
|
var tokens = [];
|
||||||
|
if (!data)
|
||||||
|
return tokens;
|
||||||
|
if (typeof data == "string")
|
||||||
|
data = {type: data, value: data}//return [{type: "", value: data}];
|
||||||
|
|
||||||
|
tokens.push({type: "", value: data.value});
|
||||||
|
if (data.type) {
|
||||||
|
var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
|
||||||
|
if (data.type.length + data.value.length < maxW - 2)
|
||||||
|
tokens.push({type: "rightAlignedText", value: data.type});
|
||||||
|
}
|
||||||
|
return tokens;
|
||||||
|
};
|
||||||
|
bgTokenizer.$updateOnChange = noop
|
||||||
|
|
||||||
|
// highlight
|
||||||
|
popup.setHighlight = function(re) {
|
||||||
|
popup.session.highlight(re);
|
||||||
|
popup.session._emit("changeFrontMarker");
|
||||||
|
};
|
||||||
|
|
||||||
|
popup.hide = function() {
|
||||||
|
this.container.style.display = "none";
|
||||||
|
this._signal("hide");
|
||||||
|
}
|
||||||
|
|
||||||
|
popup.show = function(pos, lineHeight) {
|
||||||
|
var el = this.container;
|
||||||
|
if (pos.top > window.innerHeight / 2 + lineHeight) {
|
||||||
|
el.style.top = ""
|
||||||
|
el.style.bottom = window.innerHeight - pos.top + "px";
|
||||||
|
} else {
|
||||||
|
pos.top += lineHeight;
|
||||||
|
el.style.top = pos.top + "px";
|
||||||
|
el.style.bottom = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
el.style.left = pos.left + "px";
|
||||||
|
el.style.display = "";
|
||||||
|
|
||||||
|
this._signal("show");
|
||||||
|
}
|
||||||
|
return popup;
|
||||||
|
};
|
||||||
|
|
||||||
|
dom.importCssString("\
|
||||||
|
.ace_autocomplete.ace-tm .ace_marker-layer .ace_active-line {\
|
||||||
|
background-color: #abbffe;\
|
||||||
|
}\
|
||||||
|
.ace_autocomplete.ace-tm .ace_line-hover {\
|
||||||
|
border: 1px solid #abbffe;\
|
||||||
|
position: absolute;\
|
||||||
|
background: rgba(233,233,253,0.4);\
|
||||||
|
z-index: 2;\
|
||||||
|
margin-top: -1px;\
|
||||||
|
}\
|
||||||
|
.ace_rightAlignedText {\
|
||||||
|
color: gray;\
|
||||||
|
display: inline-block;\
|
||||||
|
position: absolute;\
|
||||||
|
right: 4px;\
|
||||||
|
text-align: right;\
|
||||||
|
z-index: -1;\
|
||||||
|
}\
|
||||||
|
.ace_autocomplete {\
|
||||||
|
width: 200px;\
|
||||||
|
z-index: 200000;\
|
||||||
|
background: #f8f8f8;\
|
||||||
|
border: 1px lightgray solid;\
|
||||||
|
position: fixed;\
|
||||||
|
}");
|
||||||
|
|
||||||
|
exports.AcePopup = AcePopup;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -31,50 +31,14 @@
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var oop = require("../lib/oop");
|
var snippetManager = require("../snippets").snippetManager;
|
||||||
var Mirror = require("../worker/mirror").Mirror;
|
var Autocomplete = require("../autocomplete").Autocomplete;
|
||||||
|
|
||||||
var completer = require("./text_completer");
|
var completers = [];
|
||||||
|
exports.addCompleter = function(completer) {
|
||||||
var AutocompleteWorker = exports.AutocompleteWorker = function(sender) {
|
completers.push(completer);
|
||||||
this.setTimeout(0);
|
|
||||||
Mirror.call(this, sender);
|
|
||||||
this.setDeferredUpdate(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
oop.inherits(AutocompleteWorker, Mirror);
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
this.onUpdate = function() {
|
|
||||||
var _self = this;
|
|
||||||
|
|
||||||
var doc = this.doc.getValue();
|
|
||||||
var pos = this.data.cursor;
|
|
||||||
|
|
||||||
var currentPos = { line: pos.row, col: pos.column };
|
|
||||||
|
|
||||||
completer.complete(_self.doc, this.data.cursor, this.data.keywords, function(identifier, completions) {
|
|
||||||
if (!identifier) {
|
|
||||||
_self.sender.emit("complete", {
|
|
||||||
matches: []
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
_self.sender.emit("complete", {
|
|
||||||
startRow: pos.row,
|
|
||||||
startColumn: pos.column - identifier.length,
|
|
||||||
endRow: pos.row,
|
|
||||||
endColumn: Infinity,
|
|
||||||
matches: completions,
|
|
||||||
line: _self.doc.getLine(pos.row)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
}).call(AutocompleteWorker.prototype);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -533,7 +533,6 @@ var SnippetManager = function() {
|
||||||
}).call(SnippetManager.prototype);
|
}).call(SnippetManager.prototype);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var TabstopManager = function(editor) {
|
var TabstopManager = function(editor) {
|
||||||
if (editor.tabstopManager)
|
if (editor.tabstopManager)
|
||||||
return editor.tabstopManager;
|
return editor.tabstopManager;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue