Merge pull request #2137 from ajaxorg/autocomplete

Fix several small issues
This commit is contained in:
Ruben Daniels 2014-09-12 20:18:22 +02:00
commit e894b5f9e0
9 changed files with 122 additions and 24 deletions

View file

@ -1 +1,17 @@
TODO
%{
%{
Ace Matlab demo
%}
%}
classdef hello
methods
function greet(this)
disp('Hello!') % say hi
end
end
end
% transpose
a = [ 'x''y', "x\n\
y", 1' ]' + 2'

View file

@ -46,4 +46,10 @@ body {
position: absolute;
right: 0;
border-left: 1px solid;
}
}
/* .ace_text-input {
z-index: 10!important;
opacity: 1!important;
background: rgb(84, 0, 255)!important;
}*/

View file

@ -171,7 +171,11 @@ function highlight() {
var highlighter = ace.require("ace/ext/static_highlight")
var dom = ace.require("ace/lib/dom")
function qsa(sel) {
return Array.apply(null, document.querySelectorAll(sel));
var els = document.querySelectorAll(sel);
var result = [];
for (var i = 0, l = els.length; i < l; i++)
result[i] = els[i];
return result;
}
qsa("code[class]").forEach(function(el) {

View file

@ -89,6 +89,8 @@ var Autocomplete = function() {
pos.left += renderer.$gutterLayer.gutterWidth;
this.popup.show(pos, lineHeight);
} else if (keepPopupPosition && !prefix) {
this.detach();
}
};
@ -206,7 +208,8 @@ var Autocomplete = function() {
var prefix = util.retrievePrecedingIdentifier(line, pos.column);
this.base = session.doc.createAnchor(pos.row, pos.column - prefix.length);
this.base.$insertRight = true;
var matches = [];
var total = editor.completers.length;
editor.completers.forEach(function(completer, i) {
@ -297,7 +300,7 @@ var Autocomplete = function() {
return detachIfFinished();
// Autoinsert if one result
if (this.autoInsert && filtered.length == 1)
if (this.autoInsert && filtered.length == 1 && results.finished)
return this.insertMatch(filtered[0]);
this.openPopup(this.editor, prefix, keepPopupPosition);

View file

@ -969,8 +969,10 @@ var EditSession = function(text, mode) {
try {
this.$worker = this.$mode.createWorker(this);
} catch (e) {
console.log("Could not load worker");
console.log(e);
if (typeof console == "object") {
console.log("Could not load worker");
console.log(e);
}
this.$worker = null;
}
};
@ -1958,6 +1960,8 @@ var EditSession = function(text, mode) {
split = lastSplit + wrapLimit;
// The split is inside of a CHAR or CHAR_EXT token and no space
// around -> force a split.
if (tokens[split] == CHAR_EXT)
split--;
addSplit(split);
}
return splits;

View file

@ -51,6 +51,7 @@ var TextInput = function(parentNode, host) {
text.spellcheck = false;
text.style.opacity = "0";
if (useragent.isOldIE) text.style.top = "-100px";
parentNode.insertBefore(text, parentNode.firstChild);
var PLACEHOLDER = "\x01\x01";
@ -436,6 +437,8 @@ var TextInput = function(parentNode, host) {
};
this.moveToMouse = function(e, bringToFront) {
if (!bringToFront && useragent.isOldIE)
return;
if (!tempStyle)
tempStyle = text.style.cssText;
text.style.cssText = (bringToFront ? "z-index:100000;" : "")
@ -460,13 +463,15 @@ var TextInput = function(parentNode, host) {
host.renderer.$keepTextAreaAtCursor = null;
// on windows context menu is opened after mouseup
if (useragent.isWin)
if (useragent.isWin && !useragent.isOldIE)
event.capture(host.container, move, onContextMenuClose);
};
this.onContextMenuClose = onContextMenuClose;
var closeTimeout;
function onContextMenuClose() {
setTimeout(function () {
clearTimeout(closeTimeout)
closeTimeout = setTimeout(function () {
if (tempStyle) {
text.style.cssText = tempStyle;
tempStyle = '';
@ -475,7 +480,7 @@ var TextInput = function(parentNode, host) {
host.renderer.$keepTextAreaAtCursor = true;
host.renderer.$moveTextAreaToCursor();
}
}, 0);
}, useragent.isOldIE ? 200 : 0);
}
var onContextMenu = function(e) {

View file

@ -322,7 +322,7 @@ var Text = function(parentEl) {
this.$renderToken = function(stringBuilder, screenColumn, token, value) {
var self = this;
var replaceReg = /\t|&|<|( +)|([\x00-\x1f\x80-\xa0\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
var replaceReg = /\t|&|<|( +)|([\x00-\x1f\x80-\xa0\xad\u1680\u180E\u2000-\u200f\u2028\u2029\u202F\u205F\u3000\uFEFF])|[\u1100-\u115F\u11A3-\u11A7\u11FA-\u11FF\u2329-\u232A\u2E80-\u2E99\u2E9B-\u2EF3\u2F00-\u2FD5\u2FF0-\u2FFB\u3000-\u303E\u3041-\u3096\u3099-\u30FF\u3105-\u312D\u3131-\u318E\u3190-\u31BA\u31C0-\u31E3\u31F0-\u321E\u3220-\u3247\u3250-\u32FE\u3300-\u4DBF\u4E00-\uA48C\uA490-\uA4C6\uA960-\uA97C\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFAFF\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE66\uFE68-\uFE6B\uFF01-\uFF60\uFFE0-\uFFE6]/g;
var replaceFunc = function(c, a, b, tabIdx, idx4) {
if (a) {
return self.showInvisibles ?

View file

@ -34,6 +34,8 @@ For more information about SproutCore, visit http://www.sproutcore.com
define(function(require, exports, module) {
"use strict";
require("./fixoldbrowsers");
var oop = require("./oop");
/*
@ -136,7 +138,7 @@ var Keys = (function() {
(function() {
var mods = ["cmd", "ctrl", "alt", "shift"];
for (var i = Math.pow(2, mods.length); i--;) {
for (var i = Math.pow(2, mods.length); i--;) {
ret.KEY_MODS[i] = mods.filter(function(x) {
return i & ret.KEY_MODS[x];
}).join("-") + "-";

View file

@ -164,15 +164,53 @@ var keywords = (
}, "identifier", true);
this.$rules = {
"start" : [ {
// allowQstring
start: [{
token : "string",
regex : "'",
stateName : "qstring",
next : [{
token : "constant.language.escape",
regex : "''"
}, {
token : "string",
regex : "'|$",
next : "start"
}, {
defaultToken: "string"
}]
}, {
token : "text",
regex : "\\s+"
}, {
regex: "",
next: "noQstring"
}],
noQstring : [{
regex: "^\\s*%{\\s*$",
token: "comment.start",
push: "blockComment"
}, {
token : "comment",
regex : "%[^\r\n]*"
}, {
token : "string", // " string
regex : '".*?"'
}, {
token : "string", // ' string
regex : "'.*?'"
token : "string",
regex : '"',
stateName : "qqstring",
next : [{
token : "constant.language.escape",
regex : /\\./
}, {
token : "string",
regex : "\\\\$",
next : "qqstring"
}, {
token : "string",
regex : '"|$',
next : "start"
}, {
defaultToken: "string"
}]
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
@ -181,21 +219,41 @@ var keywords = (
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token : "keyword.operator",
regex : "\\+|\\-|\\/|\\/\\/|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|="
regex : "\\+|\\-|\\/|\\/\\/|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|=",
next: "start"
}, {
token : "punctuation.operator",
regex : "\\?|\\:|\\,|\\;|\\."
token : "punctuation.operator",
regex : "\\?|\\:|\\,|\\;|\\.",
next: "start"
}, {
token : "paren.lparen",
regex : "[\\(]"
regex : "[({\\[]",
next: "start"
}, {
token : "paren.rparen",
regex : "[\\)]"
regex : "[\\]})]"
}, {
token : "text",
regex : "\\s+"
} ]
}, {
token : "text",
regex : "$",
next : "start"
}],
blockComment: [{
regex: "^\\s*%{\\s*$",
token: "comment.start",
push: "blockComment"
}, {
regex: "^\\s*%}\\s*$",
token: "comment.end",
next: "pop"
}, {
defaultToken: "comment"
}],
};
this.normalizeRules();
};
oop.inherits(MatlabHighlightRules, TextHighlightRules);