Compare commits

..

No commits in common. "master" and "fix/webkit-focus-bug" have entirely different histories.

189 changed files with 2998 additions and 12966 deletions

View file

@ -7,9 +7,16 @@ Feel free to fork and improve/enhance Ace any way you want. If you feel that the
There are two versions of the agreement: There are two versions of the agreement:
1. [The Individual CLA](https://docs.google.com/a/c9.io/forms/d/1MfmfrxqD_PNlNsuK0lC2KSelRLxGLGfh_wEcG0ijVvo/viewform): use this version if you're working on the Cloud9 SDK or open source projects in your spare time, or can clearly claim ownership of copyright in what you'll be submitting. 1. [The Individual CLA](https://github.com/ajaxorg/ace/raw/master/doc/Contributor_License_Agreement-v2.pdf): use this version if you're working on an ajax.org in your spare time, or can clearly claim ownership of copyright in what you'll be submitting.
2. [The Corporate CLA](https://docs.google.com/a/c9.io/forms/d/1vFejn4111GdnCNuQ6BfnJDaxdsUEMD4KCo1ayovAfu0/viewform): have your corporate lawyer review and submit this if your company is going to be contributing to the Cloud9 SDK and/or open source projects. 2. [The Corporate CLA](https://github.com/ajaxorg/ace/raw/master/doc/Corporate_Contributor_License_Agreement-v2.pdf): have your corporate lawyer review and submit this if your company is going to be contributing to ajax.org projects
If you want to contribute to the Cloud9 SDK and/or open source projects please go to the online form, fill it out and submit it. If you want to contribute to an ajax.org project please print the CLA and fill it out and sign it. Then either send it by snail mail or fax to us or send it back scanned (or as a photo) by email.
Happy coding, Cloud9 Email: ace+cla@c9.io
Fax: +31 (0) 206388953
Address: Ajax.org B.V.
Keizersgracht 241
1016 EA, Amsterdam
the Netherlands

View file

@ -1,16 +1,3 @@
Version 1.2.0-pre
* New Features
- Indented soft wrap (danyaPostfactum)
* API Changes
- unified delta types `{start, end, action, lines}` (Alden Daniels https://github.com/ajaxorg/ace/pull/1745)
- "change" event listeners on session and editor get delta objects directly
2015.04.03 Version 1.1.9
- Small Enhancements and Bugfixes
2014.11.08 Version 1.1.8 2014.11.08 Version 1.1.8
* API Changes * API Changes

View file

@ -307,7 +307,6 @@ function buildAceModuleInternal(opts, callback) {
ignore: opts.ignore || [], ignore: opts.ignore || [],
withRequire: false, withRequire: false,
basepath: ACE_HOME, basepath: ACE_HOME,
transforms: [normalizeLineEndings],
afterRead: [optimizeTextModules] afterRead: [optimizeTextModules]
}, write); }, write);
} }
@ -408,10 +407,6 @@ function getLoadedFileList(options, callback, result) {
callback(Object.keys(deps)); callback(Object.keys(deps));
} }
function normalizeLineEndings(module) {
module.source = module.source.replace(/\r\n/g, "\n");
}
function optimizeTextModules(sources) { function optimizeTextModules(sources) {
var textModules = {}; var textModules = {};
return sources.filter(function(pkg) { return sources.filter(function(pkg) {
@ -457,10 +452,10 @@ function optimizeTextModules(sources) {
if (/\.css$/.test(pkg.id)) { if (/\.css$/.test(pkg.id)) {
// remove unnecessary whitespace from css // remove unnecessary whitespace from css
input = input.replace(/\n\s+/g, "\n"); input = input.replace(/\n\s+/g, "\n");
input = '"' + input.replace(/\n/g, '\\\n') + '"'; input = '"' + input.replace(/\r?\n/g, '\\\n') + '"';
} else { } else {
// but don't break other files! // but don't break other files!
input = '"' + input.replace(/\n/g, '\\n\\\n') + '"'; input = '"' + input.replace(/\r?\n/g, '\\n\\\n') + '"';
} }
textModules[pkg.id] = input; textModules[pkg.id] = input;
} }

View file

@ -79,7 +79,7 @@ By default the editor only supports plain text mode; many other languages are av
The mode can then be used like this: The mode can then be used like this:
```javascript ```javascript
var JavaScriptMode = ace.require("ace/mode/javascript").Mode; var JavaScriptMode = require("ace/mode/javascript").Mode;
editor.getSession().setMode(new JavaScriptMode()); editor.getSession().setMode(new JavaScriptMode());
``` ```

View file

@ -38,62 +38,69 @@
var ACE_NAMESPACE = ""; var ACE_NAMESPACE = "";
var global = (function() { return this; })(); var global = (function() {
if (!global && typeof window != "undefined") global = window; // strict mode return this;
})();
if (!ACE_NAMESPACE && typeof requirejs !== "undefined") if (!ACE_NAMESPACE && typeof requirejs !== "undefined")
return; return;
var define = function(module, deps, payload) { var _define = function(module, deps, payload) {
if (typeof module !== "string") { if (typeof module !== 'string') {
if (define.original) if (_define.original)
define.original.apply(this, arguments); _define.original.apply(window, arguments);
else { else {
console.error("dropping module because define wasn\'t a string."); console.error('dropping module because define wasn\'t a string.');
console.trace(); console.trace();
} }
return; return;
} }
if (arguments.length == 2) if (arguments.length == 2)
payload = deps; payload = deps;
if (!define.modules[module]) {
define.payloads[module] = payload;
define.modules[module] = null;
}
};
define.modules = {}; if (!_define.modules) {
define.payloads = {}; _define.modules = {};
_define.payloads = {};
}
_define.payloads[module] = payload;
_define.modules[module] = null;
};
/** /**
* Get at functionality define()ed using the function above * Get at functionality define()ed using the function above
*/ */
var _require = function(parentId, module, callback) { var _require = function(parentId, module, callback) {
if (typeof module === "string") { if (Object.prototype.toString.call(module) === "[object Array]") {
var payload = lookup(parentId, module);
if (payload != undefined) {
callback && callback();
return payload;
}
} else if (Object.prototype.toString.call(module) === "[object Array]") {
var params = []; var params = [];
for (var i = 0, l = module.length; i < l; ++i) { for (var i = 0, l = module.length; i < l; ++i) {
var dep = lookup(parentId, module[i]); var dep = lookup(parentId, module[i]);
if (dep == undefined && require.original) if (!dep && _require.original)
return; return _require.original.apply(window, arguments);
params.push(dep); params.push(dep);
} }
return callback && callback.apply(null, params) || true; if (callback) {
callback.apply(null, params);
}
} }
}; else if (typeof module === 'string') {
var payload = lookup(parentId, module);
if (!payload && _require.original)
return _require.original.apply(window, arguments);
var require = function(module, callback) { if (callback) {
var packagedModule = _require("", module, callback); callback();
if (packagedModule == undefined && require.original) }
return require.original.apply(this, arguments);
return packagedModule; return payload;
}
else {
if (_require.original)
return _require.original.apply(window, arguments);
}
}; };
var normalizeModule = function(parentId, moduleName) { var normalizeModule = function(parentId, moduleName) {
@ -112,6 +119,7 @@ var normalizeModule = function(parentId, moduleName) {
moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, ""); moduleName = moduleName.replace(/\/\.\//, "/").replace(/[^\/]+\/\.\.\//, "");
} }
} }
return moduleName; return moduleName;
}; };
@ -120,11 +128,12 @@ var normalizeModule = function(parentId, moduleName) {
* definition function if needed. * definition function if needed.
*/ */
var lookup = function(parentId, moduleName) { var lookup = function(parentId, moduleName) {
moduleName = normalizeModule(parentId, moduleName); moduleName = normalizeModule(parentId, moduleName);
var module = define.modules[moduleName]; var module = _define.modules[moduleName];
if (!module) { if (!module) {
module = define.payloads[moduleName]; module = _define.payloads[moduleName];
if (typeof module === 'function') { if (typeof module === 'function') {
var exports = {}; var exports = {};
var mod = { var mod = {
@ -140,15 +149,19 @@ var lookup = function(parentId, moduleName) {
var returnValue = module(req, exports, mod); var returnValue = module(req, exports, mod);
exports = returnValue || mod.exports; exports = returnValue || mod.exports;
define.modules[moduleName] = exports; _define.modules[moduleName] = exports;
delete define.payloads[moduleName]; delete _define.payloads[moduleName];
} }
module = define.modules[moduleName] = exports || module; module = _define.modules[moduleName] = exports || module;
} }
return module; return module;
}; };
function exportAce(ns) { function exportAce(ns) {
var require = function(module, callback) {
return _require("", module, callback);
};
var root = global; var root = global;
if (ns) { if (ns) {
if (!global[ns]) if (!global[ns])
@ -157,13 +170,13 @@ function exportAce(ns) {
} }
if (!root.define || !root.define.packaged) { if (!root.define || !root.define.packaged) {
define.original = root.define; _define.original = root.define;
root.define = define; root.define = _define;
root.define.packaged = true; root.define.packaged = true;
} }
if (!root.require || !root.require.packaged) { if (!root.require || !root.require.packaged) {
require.original = root.require; _require.original = root.require;
root.require = require; root.require = require;
root.require.packaged = true; root.require.packaged = true;
} }

View file

@ -7,13 +7,14 @@
<style type="text/css" media="screen"> <style type="text/css" media="screen">
.ace_editor { .ace_editor {
position: relative !important;
border: 1px solid lightgray; border: 1px solid lightgray;
margin: auto; margin: auto;
height: 200px; height: 200px;
width: 80%; width: 80%;
} }
.scrollmargin { .scrollmargin {
height: 80px; height: 100px;
text-align: center; text-align: center;
} }
</style> </style>
@ -23,8 +24,6 @@
<div class="scrollmargin"></div> <div class="scrollmargin"></div>
<pre id="editor2">minHeight = 2 lines</pre> <pre id="editor2">minHeight = 2 lines</pre>
<div class="scrollmargin"></div> <div class="scrollmargin"></div>
<pre id="editor3" style="width: 40%;"></pre>
<div class="scrollmargin"></div>
<pre id="editor"></pre> <pre id="editor"></pre>
<script src="kitchen-sink/require.js"></script> <script src="kitchen-sink/require.js"></script>
@ -47,13 +46,6 @@ require(["ace/ace"], function(ace) {
editor2.setOption("maxLines", 30); editor2.setOption("maxLines", 30);
editor2.setOption("minLines", 2); editor2.setOption("minLines", 2);
var editor = ace.edit("editor3");
editor.setOptions({
autoScrollEditorIntoView: true,
maxLines: 8
});
editor.renderer.setScrollMargin(10, 10, 10, 10);
var editor = ace.edit("editor"); var editor = ace.edit("editor");
editor.setTheme("ace/theme/tomorrow"); editor.setTheme("ace/theme/tomorrow");
editor.session.setMode("ace/mode/html"); editor.session.setMode("ace/mode/html");

View file

@ -23,7 +23,7 @@
<pre id="editor"></pre> <pre id="editor"></pre>
<!-- load emmet code and snippets compiled for browser --> <!-- load emmet code and snippets compiled for browser -->
<script src="https://cloud9ide.github.io/emmet-core/emmet.js"></script> <script src="https://nightwing.github.io/emmet-core/emmet.js"></script>
<script src="kitchen-sink/require.js"></script> <script src="kitchen-sink/require.js"></script>
<script> <script>

View file

@ -531,7 +531,7 @@ new StatusBar(env.editor, cmdLine.container);
var Emmet = require("ace/ext/emmet"); var Emmet = require("ace/ext/emmet");
net.loadScript("https://cloud9ide.github.io/emmet-core/emmet.js", function() { net.loadScript("https://nightwing.github.io/emmet-core/emmet.js", function() {
Emmet.setCore(window.emmet); Emmet.setCore(window.emmet);
env.editor.setOption("enableEmmet", true); env.editor.setOption("enableEmmet", true);
}); });

View file

@ -39,7 +39,7 @@ function warn() {
s.shift(); // remove the getter s.shift(); // remove the getter
s = s.join("\n"); s = s.join("\n");
// allow easy access to ace in console, but not in ace code // allow easy access to ace in console, but not in ace code
if (!/at Object.InjectedScript.|@debugger eval|snippets:\/{3}|\(<anonymous>:\d+:\d+\)/.test(s)) { if (!/at Object.InjectedScript.|@debugger eval|snippets:\/{3}/.test(s)) {
console.error("trying to access to global variable"); console.error("trying to access to global variable");
} }
} }

View file

@ -169,44 +169,13 @@ function loadDoc(name, callback) {
}); });
} }
function saveDoc(name, callback) {
var doc = fileCache[name] || name;
if (!doc || !doc.session)
return callback("Unknown document: " + name);
var path = doc.path;
var parts = path.split("/");
if (parts[0] == "docs")
path = "demo/kitchen-sink/" + path;
else if (parts[0] == "ace")
path = "lib/" + path;
upload(path, doc.session.getValue(), callback);
}
function upload(url, data, callback) {
url = net.qualifyURL(url);
if (!/https?:/.test(url))
return callback(new Error("Unsupported url scheme"));
var xhr = new XMLHttpRequest();
xhr.open("PUT", url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
callback(!/^2../.test(xhr.status));
}
};
xhr.send(data);
};
module.exports = { module.exports = {
fileCache: fileCache, fileCache: fileCache,
docs: sort(prepareDocList(docs)), docs: sort(prepareDocList(docs)),
ownSource: prepareDocList(ownSource), ownSource: prepareDocList(ownSource),
hugeDocs: prepareDocList(hugeDocs), hugeDocs: prepareDocList(hugeDocs),
initDoc: initDoc, initDoc: initDoc,
loadDoc: loadDoc, loadDoc: loadDoc
saveDoc: saveDoc,
}; };
module.exports.all = { module.exports.all = {
"Mode Examples": module.exports.docs, "Mode Examples": module.exports.docs,

View file

@ -1,171 +0,0 @@
%abc-2.1
H:This file contains some example English tunes
% note that the comments (like this one) are to highlight usages
% and would not normally be included in such detail
O:England % the origin of all tunes is England
X:1 % tune no 1
T:Dusty Miller, The % title
T:Binny's Jig % an alternative title
C:Trad. % traditional
R:DH % double hornpipe
M:3/4 % meter
K:G % key
B>cd BAG|FA Ac BA|B>cd BAG|DG GB AG:|
Bdd gfg|aA Ac BA|Bdd gfa|gG GB AG:|
BG G/2G/2G BG|FA Ac BA|BG G/2G/2G BG|DG GB AG:|
W:Hey, the dusty miller, and his dusty coat;
W:He will win a shilling, or he spend a groat.
W:Dusty was the coat, dusty was the colour;
W:Dusty was the kiss, that I got frae the miller.
X:2
T:Old Sir Simon the King
C:Trad.
S:Offord MSS % from Offord manuscript
N:see also Playford % reference note
M:9/8
R:SJ % slip jig
N:originally in C % transcription note
K:G
D|GFG GAG G2D|GFG GAG F2D|EFE EFE EFG|A2G F2E D2:|
D|GAG GAB d2D|GAG GAB c2D|[1 EFE EFE EFG|[A2G] F2E D2:|\ % no line-break in score
M:12/8 % change of meter
[2 E2E EFE E2E EFG|\ % no line-break in score
M:9/8 % change of meter
A2G F2E D2|]
X:3
T:William and Nancy
T:New Mown Hay
T:Legacy, The
C:Trad.
O:England; Gloucs; Bledington % place of origin
B:Sussex Tune Book % can be found in these books
B:Mally's Cotswold Morris vol.1 2
D:Morris On % can be heard on this record
P:(AB)2(AC)2A % play the parts in this order
M:6/8
K:G
[P:A] D|"G"G2G GBd|"C"e2e "G"dBG|"D7"A2d "G"BAG|"C"E2"D7"F "G"G2:|
[P:B] d|"G"e2d B2d|"C"gfe "G"d2d| "G"e2d B2d|"C"gfe "D7"d2c|
"G"B2B Bcd|"C"e2e "G"dBG|"D7"A2d "G"BAG|"C"E2"D7"F "G"G2:|
% changes of meter, using inline fields
[T:Slows][M:4/4][L:1/4][P:C]"G"d2|"C"e2 "G"d2|B2 d2|"Em"gf "A7"e2|"D7"d2 "G"d2|\
"C"e2 "G"d2|[M:3/8][L:1/8] "G"B2 d |[M:6/8] "C"gfe "D7"d2c|
"G"B2B Bcd|"C"e2e "G"dBG|"D7"A2d "G"BAG|"C"E2"D7"F "G"G2:|
X:4
T:South Downs Jig
R:jig
S:Robert Harbron
M:6/8
L:1/8
K:G
|: d | dcA G3 | EFG AFE | DEF GAB | cde d2d |
dcA G3 | EFG AFE | DEF GAB | cAF G2 :|
B | Bcd e2c | d2B c2A | Bcd e2c | [M:9/8]d2B c2B A3 |
[M:6/8]DGF E3 | cBA FED | DEF GAB |1 cAF G2 :|2 cAF G3 |]
X:5
T:Atholl Brose
% in this example, which reproduces Highland Bagpipe gracing,
% the large number of grace notes mean that it is more convenient to be specific about
% score line-breaks (using the $ symbol), rather than using code line breaks to indicate them
I:linebreak $
K:D
{gcd}c<{e}A {gAGAG}A2 {gef}e>A {gAGAG}Ad|
{gcd}c<{e}A {gAGAG}A>e {ag}a>f {gef}e>d|
{gcd}c<{e}A {gAGAG}A2 {gef}e>A {gAGAG}Ad|
{g}c/d/e {g}G>{d}B {gf}gG {dc}d>B:|$
{g}c<e {gf}g>e {ag}a>e {gf}g>e|
{g}c<e {gf}g>e {ag}a2 {GdG}a>d|
{g}c<e {gf}g>e {ag}a>e {gf}g>f|
{gef}e>d {gf}g>d {gBd}B<{e}G {dc}d>B|
{g}c<e {gf}g>e {ag}a>e {gf}g>e|
{g}c<e {gf}g>e {ag}a2 {GdG}ad|
{g}c<{GdG}e {gf}ga {f}g>e {g}f>d|
{g}e/f/g {Gdc}d>c {gBd}B<{e}G {dc}d2|]
X:6
T:Untitled Reel
C:Trad.
K:D
eg|a2ab ageg|agbg agef|g2g2 fgag|f2d2 d2:|\
ed|cecA B2ed|cAcA E2ed|cecA B2ed|c2A2 A2:|
K:G
AB|cdec BcdB|ABAF GFE2|cdec BcdB|c2A2 A2:|
X:7
T:Kitchen Girl
C:Trad.
K:D
[c4a4] [B4g4]|efed c2cd|e2f2 gaba|g2e2 e2fg|
a4 g4|efed cdef|g2d2 efed|c2A2 A4:|
K:G
ABcA BAGB|ABAG EDEG|A2AB c2d2|e3f edcB|ABcA BAGB|
ABAG EGAB|cBAc BAG2|A4 A4:|
%abc-2.1
%%pagewidth 21cm
%%pageheight 29.7cm
%%topspace 0.5cm
%%topmargin 1cm
%%botmargin 0cm
%%leftmargin 1cm
%%rightmargin 1cm
%%titlespace 0cm
%%titlefont Times-Bold 32
%%subtitlefont Times-Bold 24
%%composerfont Times 16
%%vocalfont Times-Roman 14
%%staffsep 60pt
%%sysstaffsep 20pt
%%musicspace 1cm
%%vocalspace 5pt
%%measurenb 0
%%barsperstaff 5
%%scale 0.7
X: 1
T: Canzonetta a tre voci
C: Claudio Monteverdi (1567-1643)
M: C
L: 1/4
Q: "Andante mosso" 1/4 = 110
%%score [1 2 3]
V: 1 clef=treble name="Soprano"sname="A"
V: 2 clef=treble name="Alto" sname="T"
V: 3 clef=bass middle=d name="Tenor" sname="B"
%%MIDI program 1 75 % recorder
%%MIDI program 2 75
%%MIDI program 3 75
K: Eb
% 1 - 4
[V: 1] |:z4 |z4 |f2ec |_ddcc |
w: Son que-sti~i cre-spi cri-ni~e
w: Que-sti son gli~oc-chi che mi-
[V: 2] |:c2BG|AAGc|(F/G/A/B/)c=A|B2AA |
w: Son que-sti~i cre-spi cri-ni~e que - - - - sto~il vi-so e
w: Que-sti son~gli oc-chi che mi-ran - - - - do fi-so mi-
[V: 3] |:z4 |f2ec|_ddcf |(B/c/_d/e/)ff|
w: Son que-sti~i cre-spi cri-ni~e que - - - - sto~il
w: Que-sti son~gli oc-chi che mi-ran - - - - do
% 5 - 9
[V: 1] cAB2 |cAAA |c3B|G2!fermata!Gz ::e4|
w: que-sto~il vi-so ond' io ri-man-go~uc-ci-so. Deh,
w: ran-do fi-so, tut-to re-stai con-qui-so.
[V: 2] AAG2 |AFFF |A3F|=E2!fermata!Ez::c4|
w: que-sto~il vi-so ond' io ri-man-go~uc-ci-so. Deh,
w: ran-do fi-so tut-to re-stai con-qui-so.
[V: 3] (ag/f/e2)|A_ddd|A3B|c2!fermata!cz ::A4|
w: vi - - - so ond' io ti-man-go~uc-ci-so. Deh,
w: fi - - - so tut-to re-stai con-qui-so.
% 10 - 15
[V: 1] f_dec |B2c2|zAGF |\
w: dim-me-lo ben mi-o, che que-sto\
=EFG2 |1F2z2:|2F8|] % more notes
w: sol de-si-o_. % more lyrics
[V: 2] ABGA |G2AA|GF=EF |(GF3/2=E//D//E)|1F2z2:|2F8|]
w: dim-me-lo ben mi-o, che que-sto sol de-si - - - - o_.
[V: 3] _dBc>d|e2AF|=EFc_d|c4 |1F2z2:|2F8|]
w: dim-me-lo ben mi-o, che que-sto sol de-si-o_.

View file

@ -1,9 +0,0 @@
import logic
section
variables (A : Type) (p q : A Prop)
example : (x : A, p x q x) y : A, p y :=
assume H : x : A, p x q x,
take y : A,
show p y, from and.elim_left (H y)
end

View file

@ -20,7 +20,7 @@ class Range
end end
end end
{:id => ?", :key => "value"} {:id => 34, :key => "value"}
herDocs = [<<'FOO', <<BAR, <<-BAZ, <<-`EXEC`] #comment herDocs = [<<'FOO', <<BAR, <<-BAZ, <<-`EXEC`] #comment

View file

@ -1,72 +0,0 @@
-- =============================================
-- Author: Morgan Yarbrough
-- Create date: 4/27/2015
-- Description: Test procedure that shows off language features.
-- Includes non-standard folding with region comments using either
-- line comments or block comments (both are demonstrated below).
-- This mode imitates SSMS and it designed to be used with SQL Server theme.
-- =============================================
CREATE PROCEDURE dbo.TestProcedure
--#region parameters
@vint INT = 1
,@vdate DATE = NULL
,@vdatetime DATETIME = DATEADD(dd, 1, GETDATE())
,@vvarchar VARCHAR(MAX) = ''
--#endregion
AS
BEGIN
/*#region set statements */
SET NOCOUNT ON;
SET XACT_ABORT ON;
SET QUOTED_IDENTIFIER ON;
/*#endregion*/
/**
* These comments will produce a fold widget
*/
-- folding demonstration
SET @vint = CASE
WHEN @vdate IS NULL
THEN 1
ELSE 2
END
-- another folding demonstration
IF @vint = 1
BEGIN
SET @vvarchar = 'one'
SET @vint = DATEDIFF(dd, @vdate, @vdatetime)
END
-- this mode handles strings properly
DECLARE @sql NVARCHAR(4000) = N'SELECT TOP(1) OrderID
FROM Orders
WHERE @OrderDate > GETDATE()'
-- this mode is aware of built in stored procedures
EXECUTE sp_executesql @sql
-- demonstrating some syntax highlighting
SELECT Orders.OrderID
,Customers.CompanyName
,DATEFROMPARTS(YEAR(GETDATE()), 1, 1) AS FirstDayOfYear
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID = Customers.CustomerID
WHERE CompanyName NOT LIKE '%something'
OR CompanyName IS NULL
OR CompanyName IN ('bla', 'nothing')
-- this mode includes snippets
-- place your cusor at the end of the line below and trigger auto complete (Ctrl+Space)
createpr
-- SQL Server allows using keywords as object names (not recommended) as long as they are wrapped in brackets
DATABASE -- keyword
[DATABASE] -- not a keyword
END

View file

@ -53,16 +53,16 @@ require("ace/commands/default_commands").commands.push({
return; return;
} }
var rowCount = 10; var rowCount = 10;
var w = { var w = {
row: row, row: row,
// rowCount: rowCount, // rowCount: rowCount,
fixedWidth: true, fixedWidth: true,
el: dom.createElement("div"), el: dom.createElement("div"),
editor: inlineEditor editor: editor
}; };
var el = w.el; var el = w.el;
el.appendChild(inlineEditor.container); el.appendChild(inlineEditor.container);
if (!editor.session.widgetManager) { if (!editor.session.widgetManager) {
editor.session.widgetManager = new LineWidgets(editor.session); editor.session.widgetManager = new LineWidgets(editor.session);

View file

@ -2,13 +2,13 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Static Code highlighter using Ace</title> <title>Static Code highlighter using Ace</title>
<meta name="author" content="Matthew Kastor"> <meta name="author" content="Matthew Kastor">
<style type="text/css"> <style type="text/css">
.code { .code {
width: 50%; width: 50%;
position: relative;
white-space: pre-wrap; white-space: pre-wrap;
border: solid lightgrey 1px
} }
</style> </style>
</head> </head>
@ -21,8 +21,9 @@
<div class="code" ace-mode="ace/mode/css" ace-theme="ace/theme/chrome" ace-gutter="true"> <div class="code" ace-mode="ace/mode/css" ace-theme="ace/theme/chrome" ace-gutter="true">
.code { .code {
width: 50%; width: 50%;
position: relative;
white-space: pre-wrap; white-space: pre-wrap;
border: solid lightgrey 1px
} }
</div> </div>
@ -34,26 +35,6 @@ function wobble (flam) {
</pre> </pre>
<div class="code" ace-mode="ace/mode/lua" ace-theme="ace/theme/chrome" ace-gutter="true" style="width: 30em;">
--[[--
num_args takes in 5.1 byte code and extracts the number of arguments from its function header.
--]]--
function int(t)
return t:byte(1) + t:byte(2) * 0x100 + t:byte(3) * 0x10000 + t:byte(4) * 0x1000000
end
function num_args(func)
local dump = string.dump(func)
local offset, cursor = int(dump:sub(13)), offset + 26
--Get the params and var flag (whether there's a ... in the param)
return dump:sub(cursor):byte(), dump:sub(cursor+1):byte()
end
</div>
<script src="kitchen-sink/require.js"></script> <script src="kitchen-sink/require.js"></script>
<script> <script>
require.config({paths: { "ace" : "../lib/ace"}}); require.config({paths: { "ace" : "../lib/ace"}});

View file

@ -2,13 +2,15 @@
* Simple node.js server, which generates the synax highlighted version of itself * Simple node.js server, which generates the synax highlighted version of itself
* using the Ace modes and themes on the server and serving a static web page. * using the Ace modes and themes on the server and serving a static web page.
*/ */
// $'
// include ace search path and modules // include ace search path and modules
require("amd-loader"); require("amd-loader");
// load jsdom, which is required by Ace
require("../../lib/ace/test/mockdom");
var http = require("http"); var http = require("http");
var fs = require("fs"); var fs = require("fs");
var resolve = require("path").resolve;
// load the highlighter and the desired mode and theme // load the highlighter and the desired mode and theme
var highlighter = require("../../lib/ace/ext/static_highlight"); var highlighter = require("../../lib/ace/ext/static_highlight");
@ -18,22 +20,15 @@ var theme = require("../../lib/ace/theme/twilight");
var port = process.env.PORT || 2222; var port = process.env.PORT || 2222;
http.createServer(function(req, res) { http.createServer(function(req, res) {
var url = req.url;
var path = /[^#?\x00]*/.exec(url)[0];
var root = resolve(__dirname + "/../../").replace(/\\/g, "/");
path = resolve(root + "/" + path).replace(/\\/g, "/");
if (path.indexOf(root + "/") != 0)
path = __filename;
res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"}); res.writeHead(200, {"Content-Type": "text/html; charset=utf-8"});
fs.readFile(path, "utf8", function(err, data) { fs.readFile(__filename, "utf8", function(err, data) {
if (err) data = err.message;
var highlighted = highlighter.render(data, new JavaScriptMode(), theme); var highlighted = highlighter.render(data, new JavaScriptMode(), theme);
res.end( res.end(
'<html><body>\n' + '<html><body>\n' +
'<style type="text/css" media="screen">\n' + '<style type="text/css" media="screen">\n' +
highlighted.css + highlighted.css +
'</style>\n' + '</style>\n' +
highlighted.html + highlighted.html +
'</body></html>' '</body></html>'
); );
}); });

Binary file not shown.

Binary file not shown.

View file

@ -18,7 +18,7 @@ $(function() {
}); });
ace.config.loadModule("ace/ext/emmet", function() { ace.config.loadModule("ace/ext/emmet", function() {
ace.require("ace/lib/net").loadScript("http://cloud9ide.github.io/emmet-core/emmet.js", function() { ace.require("ace/lib/net").loadScript("http://nightwing.github.io/emmet-core/emmet.js", function() {
embedded_editor.setOption("enableEmmet", true); embedded_editor.setOption("enableEmmet", true);
editor.setOption("enableEmmet", true); editor.setOption("enableEmmet", true);
}); });

View file

@ -1,59 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="../demo/kitchen-sink/require.js"></script>
<script type="text/javascript">
require.config({
paths: { ace: "../lib/ace" },
waitSeconds: 0
});
</script>
</head>
<body>
<p><button onclick="toggleEditor()">Toggle editor</button></p>
<div id="container"></div>
<script>
var editor;
var counter = 0
function toggleEditor() {
if (!editor) {
var root = document.createElement("div");
root.style.height = "100px";
root.setAttribute("id", "editor");
root.textContent = "function foo(items) {\nvar x = 'All this is syntax highlighted';\nreturn x;\n}";
document.getElementById("container").appendChild(root);
editor = ace.edit(root);
if (counter++ % 2)
editor.setTheme("ace/theme/monokai");
else
editor.setTheme("ace/theme/clouds");
editor.session.setMode("ace/mode/javascript");
} else {
editor.destroy();
var el = editor.container;
el.parentNode.removeChild(el);
editor.container = null
editor.renderer = null
editor = null;
var root = document.getElementById("editor")
if (root)
root.parentNode.removeChild(root);
}
}
require(["ace/ace"], function(ace) {
window.ace = ace;
toggleEditor();
})
</script>
</body>
</html>

View file

@ -196,7 +196,8 @@ console.log(addResult);
<p><span class="expand_arrow">&gt;</span> <a href="https://github.com/ajaxorg/ace/tree/master/lib/ace/theme" target="_blank">See all themes</a></p> <p><span class="expand_arrow">&gt;</span> <a href="https://github.com/ajaxorg/ace/tree/master/lib/ace/theme" target="_blank">See all themes</a></p>
<h2>Setting the Programming Language Mode</h2> <h2>Setting the Programming Language Mode</h2>
<p>By default, the editor supports plain text mode. All other language modes are available as separate modules, loaded on demand like this:</p> <p>By default, the editor supports plain text mode. All other language modes are available as separate modules, loaded on demand like this:</p>
<pre><code class="javascript">editor.getSession().setMode("ace/mode/javascript");</code></pre> <pre><code class="javascript">editor.getSession().setMode("ace/mode/javascript");
</code></pre>
<!--h2>One Editor, Multiple Sessions</h2> <!--h2>One Editor, Multiple Sessions</h2>
<p>Ace keeps everything about the state of the editor (selection, scroll position, etc.) <p>Ace keeps everything about the state of the editor (selection, scroll position, etc.)
in <code class="javascript">editor.session</code>. This means you can grab the in <code class="javascript">editor.session</code>. This means you can grab the
@ -470,6 +471,7 @@ var fonts = lang.arrayToMap(
<pre><code class="language-javascript">this.$rules = { <pre><code class="language-javascript">this.$rules = {
"start" : [ { "start" : [ {
token : "text", token : "text",
merge : true,
regex : "&lt;\\!\\[CDATA\\[", regex : "&lt;\\!\\[CDATA\\[",
next : "cdata" next : "cdata"
}, },
@ -479,7 +481,13 @@ var fonts = lang.arrayToMap(
regex : "\\]\\]&gt;", regex : "\\]\\]&gt;",
next : "start" next : "start"
}, { }, {
defaultToken : "text" token : "text",
merge : true,
regex : "\\s+"
}, {
token : "text",
merge : true,
regex : ".+"
} ] } ]
};</code></pre> };</code></pre>
<p>In this extremly short sample, we're defining some highlighting rules for when Ace detectes a <code>&lt;![CDATA</code> tag. When one is encountered, the tokenizer moves from <code>start</code> into the <code>cdata</code> state. It remains there, applying the <code>text</code> token to any string it encounters. Finally, when it hits a closing <code>]&gt;</code> symbol, it returns to the <code>start</code> state and continues to tokenize anything else.</p> <p>In this extremly short sample, we're defining some highlighting rules for when Ace detectes a <code>&lt;![CDATA</code> tag. When one is encountered, the tokenizer moves from <code>start</code> into the <code>cdata</code> state. It remains there, applying the <code>text</code> token to any string it encounters. Finally, when it hits a closing <code>]&gt;</code> symbol, it returns to the <code>start</code> state and continues to tokenize anything else.</p>

View file

@ -99,54 +99,72 @@ var Anchor = exports.Anchor = function(doc, row, column) {
* - `value`: An object describing the new Anchor position * - `value`: An object describing the new Anchor position
* *
**/ **/
this.onChange = function(delta) { this.onChange = function(e) {
if (delta.start.row == delta.end.row && delta.start.row != this.row) var delta = e.data;
var range = delta.range;
if (range.start.row == range.end.row && range.start.row != this.row)
return; return;
if (delta.start.row > this.row) if (range.start.row > this.row)
return; return;
var point = $getTransformedPoint(delta, {row: this.row, column: this.column}, this.$insertRight); if (range.start.row == this.row && range.start.column > this.column)
this.setPosition(point.row, point.column, true); return;
var row = this.row;
var column = this.column;
var start = range.start;
var end = range.end;
if (delta.action === "insertText") {
if (start.row === row && start.column <= column) {
if (start.column === column && this.$insertRight) {
// do nothing
} else if (start.row === end.row) {
column += end.column - start.column;
} else {
column -= start.column;
row += end.row - start.row;
}
} else if (start.row !== end.row && start.row < row) {
row += end.row - start.row;
}
} else if (delta.action === "insertLines") {
if (start.row === row && column === 0 && this.$insertRight) {
// do nothing
}
else if (start.row <= row) {
row += end.row - start.row;
}
} else if (delta.action === "removeText") {
if (start.row === row && start.column < column) {
if (end.column >= column)
column = start.column;
else
column = Math.max(0, column - (end.column - start.column));
} else if (start.row !== end.row && start.row < row) {
if (end.row === row)
column = Math.max(0, column - end.column) + start.column;
row -= (end.row - start.row);
} else if (end.row === row) {
row -= end.row - start.row;
column = Math.max(0, column - end.column) + start.column;
}
} else if (delta.action == "removeLines") {
if (start.row <= row) {
if (end.row <= row)
row -= end.row - start.row;
else {
row = start.row;
column = 0;
}
}
}
this.setPosition(row, column, true);
}; };
function $pointsInOrder(point1, point2, equalPointsInOrder) {
var bColIsAfter = equalPointsInOrder ? point1.column <= point2.column : point1.column < point2.column;
return (point1.row < point2.row) || (point1.row == point2.row && bColIsAfter);
}
function $getTransformedPoint(delta, point, moveIfEqual) {
// Get delta info.
var deltaIsInsert = delta.action == "insert";
var deltaRowShift = (deltaIsInsert ? 1 : -1) * (delta.end.row - delta.start.row);
var deltaColShift = (deltaIsInsert ? 1 : -1) * (delta.end.column - delta.start.column);
var deltaStart = delta.start;
var deltaEnd = deltaIsInsert ? deltaStart : delta.end; // Collapse insert range.
// DELTA AFTER POINT: No change needed.
if ($pointsInOrder(point, deltaStart, moveIfEqual)) {
return {
row: point.row,
column: point.column
};
}
// DELTA BEFORE POINT: Move point by delta shift.
if ($pointsInOrder(deltaEnd, point, !moveIfEqual)) {
return {
row: point.row + deltaRowShift,
column: point.column + (point.row == deltaEnd.row ? deltaColShift : 0)
};
}
// DELTA ENVELOPS POINT (delete only): Move point to delta start.
// TODO warn if delta.action != "remove" ?
return {
row: deltaStart.row,
column: deltaStart.column
};
}
/** /**
* Sets the anchor position to the specified row and column. If `noClip` is `true`, the position is not clipped. * Sets the anchor position to the specified row and column. If `noClip` is `true`, the position is not clipped.

View file

@ -71,7 +71,7 @@ module.exports = {
var doc = new Document("juhu\nkinners"); var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4); var anchor = new Anchor(doc, 1, 4);
doc.insertFullLines(1, ["123", "456"]); doc.insertLines(1, ["123", "456"]);
assert.position(anchor.getPosition(), 3, 4); assert.position(anchor.getPosition(), 3, 4);
}, },
@ -105,7 +105,7 @@ module.exports = {
var doc = new Document("juhu\nkinners"); var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4); var anchor = new Anchor(doc, 1, 4);
doc.insertMergedLines({row: 0, column: 0}, ['', '']); doc.insertNewLine({row: 0, column: 0});
assert.position(anchor.getPosition(), 2, 4); assert.position(anchor.getPosition(), 2, 4);
}, },
@ -113,7 +113,7 @@ module.exports = {
var doc = new Document("juhu\nkinners"); var doc = new Document("juhu\nkinners");
var anchor = new Anchor(doc, 1, 4); var anchor = new Anchor(doc, 1, 4);
doc.insertMergedLines({row: 1, column: 2}, ['', '']); doc.insertNewLine({row: 1, column: 2});
assert.position(anchor.getPosition(), 2, 2); assert.position(anchor.getPosition(), 2, 2);
}, },
@ -145,7 +145,7 @@ module.exports = {
var doc = new Document("juhu\n1\n2\nkinners"); var doc = new Document("juhu\n1\n2\nkinners");
var anchor = new Anchor(doc, 3, 4); var anchor = new Anchor(doc, 3, 4);
doc.removeFullLines(1, 2); doc.removeLines(1, 2);
assert.position(anchor.getPosition(), 1, 4); assert.position(anchor.getPosition(), 1, 4);
}, },
@ -169,7 +169,7 @@ module.exports = {
var doc = new Document("juhu\nkinners\n123"); var doc = new Document("juhu\nkinners\n123");
var anchor = new Anchor(doc, 1, 5); var anchor = new Anchor(doc, 1, 5);
doc.removeFullLines(1, 1); doc.removeLines(1, 1);
assert.position(anchor.getPosition(), 1, 0); assert.position(anchor.getPosition(), 1, 0);
}, },
@ -208,9 +208,9 @@ module.exports = {
var doc = new Document("juhu\nkinners\n123"); var doc = new Document("juhu\nkinners\n123");
var anchor = new Anchor(doc, 2, 4); var anchor = new Anchor(doc, 2, 4);
doc.removeFullLines(0, 3); doc.removeLines(0, 3);
assert.position(anchor.getPosition(), 0, 0); assert.position(anchor.getPosition(), 0, 0);
doc.insertFullLines(0, ["a", "b", "c"]); doc.insertLines(0, ["a", "b", "c"]);
assert.position(anchor.getPosition(), 3, 0); assert.position(anchor.getPosition(), 3, 0);
assert.equal(doc.getValue(), "a\nb\nc\n"); assert.equal(doc.getValue(), "a\nb\nc\n");
} }

View file

@ -1,108 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, 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";
function throwDeltaError(delta, errorText){
console.log("Invalid Delta:", delta);
throw "Invalid Delta: " + errorText;
}
function positionInDocument(docLines, position) {
return position.row >= 0 && position.row < docLines.length &&
position.column >= 0 && position.column <= docLines[position.row].length;
}
function validateDelta(docLines, delta) {
// Validate action string.
if (delta.action != "insert" && delta.action != "remove")
throwDeltaError(delta, "delta.action must be 'insert' or 'remove'");
// Validate lines type.
if (!(delta.lines instanceof Array))
throwDeltaError(delta, "delta.lines must be an Array");
// Validate range type.
if (!delta.start || !delta.end)
throwDeltaError(delta, "delta.start/end must be an present");
// Validate that the start point is contained in the document.
var start = delta.start;
if (!positionInDocument(docLines, delta.start))
throwDeltaError(delta, "delta.start must be contained in document");
// Validate that the end point is contained in the document (remove deltas only).
var end = delta.end;
if (delta.action == "remove" && !positionInDocument(docLines, end))
throwDeltaError(delta, "delta.end must contained in document for 'remove' actions");
// Validate that the .range size matches the .lines size.
var numRangeRows = end.row - start.row;
var numRangeLastLineChars = (end.column - (numRangeRows == 0 ? start.column : 0));
if (numRangeRows != delta.lines.length - 1 || delta.lines[numRangeRows].length != numRangeLastLineChars)
throwDeltaError(delta, "delta.range must match delta lines");
}
exports.applyDelta = function(docLines, delta, doNotValidate) {
// disabled validation since it breaks autocompletion popup
// if (!doNotValidate)
// validateDelta(docLines, delta);
var row = delta.start.row;
var startColumn = delta.start.column;
var line = docLines[row] || "";
switch (delta.action) {
case "insert":
var lines = delta.lines;
if (lines.length === 1) {
docLines[row] = line.substring(0, startColumn) + delta.lines[0] + line.substring(startColumn);
} else {
var args = [row, 1].concat(delta.lines);
docLines.splice.apply(docLines, args);
docLines[row] = line.substring(0, startColumn) + docLines[row];
docLines[row + delta.lines.length - 1] += line.substring(startColumn);
}
break;
case "remove":
var endColumn = delta.end.column;
var endRow = delta.end.row;
if (row === endRow) {
docLines[row] = line.substring(0, startColumn) + line.substring(endColumn);
} else {
docLines.splice(
row, endRow - row + 1,
line.substring(0, startColumn) + docLines[endRow].substring(endColumn)
);
}
break;
}
}
});

View file

@ -40,10 +40,9 @@ var dom = require("./lib/dom");
var snippetManager = require("./snippets").snippetManager; var snippetManager = require("./snippets").snippetManager;
var Autocomplete = function() { var Autocomplete = function() {
this.autoInsert = false; this.autoInsert = true;
this.autoSelect = true; this.autoSelect = true;
this.exactMatch = false; this.exactMatch = false;
this.gatherCompletionsId = 0;
this.keyboardHandler = new HashHandler(); this.keyboardHandler = new HashHandler();
this.keyboardHandler.bindKeys(this.commands); this.keyboardHandler.bindKeys(this.commands);
@ -60,6 +59,7 @@ var Autocomplete = function() {
}; };
(function() { (function() {
this.gatherCompletionsId = 0;
this.$init = function() { this.$init = function() {
this.popup = new AcePopup(document.body || document.documentElement); this.popup = new AcePopup(document.body || document.documentElement);
@ -84,8 +84,6 @@ var Autocomplete = function() {
this.popup.setData(this.completions.filtered); this.popup.setData(this.completions.filtered);
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
var renderer = editor.renderer; var renderer = editor.renderer;
this.popup.setRow(this.autoSelect ? 0 : -1); this.popup.setRow(this.autoSelect ? 0 : -1);
if (!keepPopupPosition) { if (!keepPopupPosition) {
@ -100,7 +98,7 @@ var Autocomplete = function() {
var rect = editor.container.getBoundingClientRect(); var rect = editor.container.getBoundingClientRect();
pos.top += rect.top - renderer.layerConfig.offset; pos.top += rect.top - renderer.layerConfig.offset;
pos.left += rect.left - editor.renderer.scrollLeft; pos.left += rect.left - editor.renderer.scrollLeft;
pos.left += renderer.gutterWidth; pos.left += renderer.$gutterLayer.gutterWidth;
this.popup.show(pos, lineHeight); this.popup.show(pos, lineHeight);
} else if (keepPopupPosition && !prefix) { } else if (keepPopupPosition && !prefix) {
@ -117,9 +115,10 @@ var Autocomplete = function() {
this.changeTimer.cancel(); this.changeTimer.cancel();
this.hideDocTooltip(); this.hideDocTooltip();
this.gatherCompletionsId += 1; if (this.popup && this.popup.isOpen) {
if (this.popup && this.popup.isOpen) this.gatherCompletionsId += 1;
this.popup.hide(); this.popup.hide();
}
if (this.base) if (this.base)
this.base.detach(); this.base.detach();
@ -142,11 +141,10 @@ var Autocomplete = function() {
// we have to check if activeElement is a child of popup because // we have to check if activeElement is a child of popup because
// on IE preventDefault doesn't stop scrollbar from being focussed // on IE preventDefault doesn't stop scrollbar from being focussed
var el = document.activeElement; var el = document.activeElement;
var text = this.editor.textInput.getElement(); var text = this.editor.textInput.getElement()
var fromTooltip = e.relatedTarget && e.relatedTarget == this.tooltipNode; if (el != text && el.parentNode != this.popup.container
var container = this.popup && this.popup.container; && el != this.tooltipNode && e.relatedTarget != this.tooltipNode
if (el != text && el.parentNode != container && !fromTooltip && e.relatedTarget != text
&& el != this.tooltipNode && e.relatedTarget != text
) { ) {
this.detach(); this.detach();
} }
@ -206,6 +204,7 @@ var Autocomplete = function() {
"Ctrl-Down|Ctrl-End": function(editor) { editor.completer.goTo("end"); }, "Ctrl-Down|Ctrl-End": 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(" ");},
"Return": function(editor) { return editor.completer.insertMatch(); }, "Return": function(editor) { return editor.completer.insertMatch(); },
"Shift-Return": function(editor) { editor.completer.insertMatch(true); }, "Shift-Return": function(editor) { editor.completer.insertMatch(true); },
"Tab": function(editor) { "Tab": function(editor) {
@ -262,6 +261,7 @@ var Autocomplete = function() {
editor.completer = this; editor.completer = this;
} }
editor.keyBinding.addKeyboardHandler(this.keyboardHandler);
editor.on("changeSelection", this.changeListener); editor.on("changeSelection", this.changeListener);
editor.on("blur", this.blurListener); editor.on("blur", this.blurListener);
editor.on("mousedown", this.mousedownListener); editor.on("mousedown", this.mousedownListener);
@ -350,7 +350,7 @@ var Autocomplete = function() {
doc = selected; doc = selected;
if (typeof doc == "string") if (typeof doc == "string")
doc = {docText: doc}; doc = {docText: doc}
if (!doc || !(doc.docHTML || doc.docText)) if (!doc || !(doc.docHTML || doc.docText))
return this.hideDocTooltip(); return this.hideDocTooltip();
this.showDocTooltip(doc); this.showDocTooltip(doc);
@ -408,16 +408,16 @@ Autocomplete.startCommand = {
exec: function(editor) { exec: function(editor) {
if (!editor.completer) if (!editor.completer)
editor.completer = new Autocomplete(); editor.completer = new Autocomplete();
editor.completer.autoInsert = false; editor.completer.autoInsert =
editor.completer.autoSelect = true; editor.completer.autoSelect = true;
editor.completer.showPopup(editor); editor.completer.showPopup(editor);
// prevent ctrl-space opening context menu on firefox on mac // needed for firefox on mac
editor.completer.cancelContextMenu(); editor.completer.cancelContextMenu();
}, },
bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space" bindKey: "Ctrl-Space|Ctrl-Shift-Space|Alt-Space"
}; };
var FilteredList = function(array, filterText) { var FilteredList = function(array, filterText, mutateData) {
this.all = array; this.all = array;
this.filtered = array; this.filtered = array;
this.filterText = filterText || ""; this.filterText = filterText || "";

View file

@ -31,6 +31,7 @@
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 Renderer = require("../virtual_renderer").VirtualRenderer;
var Editor = require("../editor").Editor; var Editor = require("../editor").Editor;
var Range = require("../range").Range; var Range = require("../range").Range;
@ -196,12 +197,8 @@ var AcePopup = function(parentNode) {
if (data.meta) { if (data.meta) {
var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth; var maxW = popup.renderer.$size.scrollerWidth / popup.renderer.layerConfig.characterWidth;
var metaData = data.meta; if (data.meta.length + data.caption.length < maxW - 2)
if (metaData.length + data.caption.length > maxW - 2) { tokens.push({type: "rightAlignedText", value: data.meta});
// trim meta to fit this popup and add ellipsis
metaData = metaData.substr(0, maxW - data.caption.length - 3) + "\u2026"
}
tokens.push({type: "rightAlignedText", value: metaData});
} }
return tokens; return tokens;
}; };
@ -220,8 +217,8 @@ var AcePopup = function(parentNode) {
popup.data = []; popup.data = [];
popup.setData = function(list) { popup.setData = function(list) {
popup.setValue(lang.stringRepeat("\n", list.length), -1);
popup.data = list || []; popup.data = list || [];
popup.setValue(lang.stringRepeat("\n", list.length), -1);
popup.setRow(0); popup.setRow(0);
}; };
popup.getData = function(row) { popup.getData = function(row) {
@ -341,4 +338,4 @@ dom.importCssString("\
exports.AcePopup = AcePopup; exports.AcePopup = AcePopup;
}); });

View file

@ -68,10 +68,11 @@ var BackgroundTokenizer = function(tokenizer, editor) {
var endLine = -1; var endLine = -1;
var doc = self.doc; var doc = self.doc;
var startLine = currentLine;
while (self.lines[currentLine]) while (self.lines[currentLine])
currentLine++; currentLine++;
var startLine = currentLine;
var len = doc.getLength(); var len = doc.getLength();
var processedLines = 0; var processedLines = 0;
self.running = false; self.running = false;
@ -171,12 +172,13 @@ var BackgroundTokenizer = function(tokenizer, editor) {
} }
this.$updateOnChange = function(delta) { this.$updateOnChange = function(delta) {
var startRow = delta.start.row; var range = delta.range;
var len = delta.end.row - startRow; var startRow = range.start.row;
var len = range.end.row - startRow;
if (len === 0) { if (len === 0) {
this.lines[startRow] = null; this.lines[startRow] = null;
} else if (delta.action == "remove") { } else if (delta.action == "removeText" || delta.action == "removeLines") {
this.lines.splice(startRow, len + 1, null); this.lines.splice(startRow, len + 1, null);
this.states.splice(startRow, len + 1, null); this.states.splice(startRow, len + 1, null);
} else { } else {

View file

@ -75,49 +75,6 @@ module.exports = {
forceTokenize(doc) forceTokenize(doc)
testStates(doc, ["comment_regex_allowed", "start", "no_regex"]) testStates(doc, ["comment_regex_allowed", "start", "no_regex"])
},
"test background tokenizer sends update event" : function() {
var doc = new EditSession([
"/*",
"var",
"juhu",
"*/"
]);
doc.setMode("./mode/javascript");
var updateEvent = null;
doc.bgTokenizer.on("update", function(e) {
updateEvent = e.data;
});
function checkEvent(first, last) {
assert.ok(!updateEvent, "unneccessary update event");
doc.bgTokenizer.running = 1;
doc.bgTokenizer.$worker();
assert.ok(updateEvent);
assert.equal([first, last] + "",
[updateEvent.first, updateEvent.last] + "")
updateEvent = null;
}
forceTokenize(doc);
var comment = "comment_regex_allowed";
testStates(doc, [comment, comment, comment, "start"]);
doc.remove(new Range(0,0,0,2));
testStates(doc, [comment, comment, comment, "start"]);
checkEvent(0, 3);
testStates(doc, ["start", "no_regex", "no_regex", "regex"]);
// insert /* and and press down several times quickly
doc.insert({row:0, column:0}, "/*");
doc.getTokens(0);
doc.getTokens(1);
doc.getTokens(2);
checkEvent(0, 3);
forceTokenize(doc);
testStates(doc, [comment, comment, comment, "start"]);
} }
}; };

View file

@ -97,33 +97,29 @@ exports.commands = [{
name: "fold", name: "fold",
bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"), bindKey: bindKey("Alt-L|Ctrl-F1", "Command-Alt-L|Command-F1"),
exec: function(editor) { editor.session.toggleFold(false); }, exec: function(editor) { editor.session.toggleFold(false); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "unfold", name: "unfold",
bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"), bindKey: bindKey("Alt-Shift-L|Ctrl-Shift-F1", "Command-Alt-Shift-L|Command-Shift-F1"),
exec: function(editor) { editor.session.toggleFold(true); }, exec: function(editor) { editor.session.toggleFold(true); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "toggleFoldWidget", name: "toggleFoldWidget",
bindKey: bindKey("F2", "F2"), bindKey: bindKey("F2", "F2"),
exec: function(editor) { editor.session.toggleFoldWidget(); }, exec: function(editor) { editor.session.toggleFoldWidget(); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "toggleParentFoldWidget", name: "toggleParentFoldWidget",
bindKey: bindKey("Alt-F2", "Alt-F2"), bindKey: bindKey("Alt-F2", "Alt-F2"),
exec: function(editor) { editor.session.toggleFoldWidget(true); }, exec: function(editor) { editor.session.toggleFoldWidget(true); },
multiSelectAction: "forEach",
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
}, { }, {
name: "foldall", name: "foldall",
bindKey: bindKey(null, "Ctrl-Command-Option-0"), bindKey: bindKey("Ctrl-Alt-0", "Ctrl-Command-Option-0"),
exec: function(editor) { editor.session.foldAll(); }, exec: function(editor) { editor.session.foldAll(); },
scrollIntoView: "center", scrollIntoView: "center",
readOnly: true readOnly: true
@ -419,16 +415,10 @@ exports.commands = [{
readOnly: true readOnly: true
}, { }, {
name: "passKeysToBrowser", name: "passKeysToBrowser",
bindKey: bindKey(null, null), bindKey: bindKey("null", "null"),
exec: function() {}, exec: function() {},
passEvent: true, passEvent: true,
readOnly: true readOnly: true
}, {
name: "copy",
exec: function(editor) {
// placeholder for replay macro
},
readOnly: true
}, },
// commands disabled in readOnly mode // commands disabled in readOnly mode
@ -445,12 +435,6 @@ exports.commands = [{
}, },
scrollIntoView: "cursor", scrollIntoView: "cursor",
multiSelectAction: "forEach" multiSelectAction: "forEach"
}, {
name: "paste",
exec: function(editor, args) {
editor.$handlePaste(args);
},
scrollIntoView: "cursor"
}, { }, {
name: "removeline", name: "removeline",
bindKey: bindKey("Ctrl-D", "Command-D"), bindKey: bindKey("Ctrl-D", "Command-D"),

View file

@ -69,14 +69,18 @@ exports.iSearchCommands = [{
bindKey: {win: "Ctrl-F", mac: "Command-F"}, bindKey: {win: "Ctrl-F", mac: "Command-F"},
exec: function(iSearch) { exec: function(iSearch) {
iSearch.cancelSearch(true); iSearch.cancelSearch(true);
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: "searchForward", name: "searchForward",
bindKey: {win: "Ctrl-S|Ctrl-K", mac: "Ctrl-S|Command-G"}, bindKey: {win: "Ctrl-S|Ctrl-K", mac: "Ctrl-S|Command-G"},
exec: function(iSearch, options) { exec: function(iSearch, options) {
options.useCurrentOrPrevSearch = true; options.useCurrentOrPrevSearch = true;
iSearch.next(options); iSearch.next(options);
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: "searchBackward", name: "searchBackward",
bindKey: {win: "Ctrl-R|Ctrl-Shift-K", mac: "Ctrl-R|Command-Shift-G"}, bindKey: {win: "Ctrl-R|Ctrl-Shift-K", mac: "Ctrl-R|Command-Shift-G"},
@ -84,30 +88,42 @@ exports.iSearchCommands = [{
options.useCurrentOrPrevSearch = true; options.useCurrentOrPrevSearch = true;
options.backwards = true; options.backwards = true;
iSearch.next(options); iSearch.next(options);
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: "extendSearchTerm", name: "extendSearchTerm",
exec: function(iSearch, string) { exec: function(iSearch, string) {
iSearch.addString(string); iSearch.addString(string);
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: "extendSearchTermSpace", name: "extendSearchTermSpace",
bindKey: "space", bindKey: "space",
exec: function(iSearch) { iSearch.addString(' '); } exec: function(iSearch) { iSearch.addString(' '); },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: "shrinkSearchTerm", name: "shrinkSearchTerm",
bindKey: "backspace", bindKey: "backspace",
exec: function(iSearch) { exec: function(iSearch) {
iSearch.removeChar(); iSearch.removeChar();
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: 'confirmSearch', name: 'confirmSearch',
bindKey: 'return', bindKey: 'return',
exec: function(iSearch) { iSearch.deactivate(); } exec: function(iSearch) { iSearch.deactivate(); },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: 'cancelSearch', name: 'cancelSearch',
bindKey: 'esc|Ctrl-G', bindKey: 'esc|Ctrl-G',
exec: function(iSearch) { iSearch.deactivate(true); } exec: function(iSearch) { iSearch.deactivate(true); },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: 'occurisearch', name: 'occurisearch',
bindKey: 'Ctrl-O', bindKey: 'Ctrl-O',
@ -115,7 +131,9 @@ exports.iSearchCommands = [{
var options = oop.mixin({}, iSearch.$options); var options = oop.mixin({}, iSearch.$options);
iSearch.deactivate(); iSearch.deactivate();
occurStartCommand.exec(iSearch.$editor, options); occurStartCommand.exec(iSearch.$editor, options);
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: "yankNextWord", name: "yankNextWord",
bindKey: "Ctrl-w", bindKey: "Ctrl-w",
@ -124,7 +142,9 @@ exports.iSearchCommands = [{
range = ed.selection.getRangeOfMovements(function(sel) { sel.moveCursorWordRight(); }), range = ed.selection.getRangeOfMovements(function(sel) { sel.moveCursorWordRight(); }),
string = ed.session.getTextRange(range); string = ed.session.getTextRange(range);
iSearch.addString(string); iSearch.addString(string);
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: "yankNextChar", name: "yankNextChar",
bindKey: "Ctrl-Alt-y", bindKey: "Ctrl-Alt-y",
@ -133,11 +153,15 @@ exports.iSearchCommands = [{
range = ed.selection.getRangeOfMovements(function(sel) { sel.moveCursorRight(); }), range = ed.selection.getRangeOfMovements(function(sel) { sel.moveCursorRight(); }),
string = ed.session.getTextRange(range); string = ed.session.getTextRange(range);
iSearch.addString(string); iSearch.addString(string);
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: 'recenterTopBottom', name: 'recenterTopBottom',
bindKey: 'Ctrl-l', bindKey: 'Ctrl-l',
exec: function(iSearch) { iSearch.$editor.execCommand('recenterTopBottom'); } exec: function(iSearch) { iSearch.$editor.execCommand('recenterTopBottom'); },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: 'selectAllMatches', name: 'selectAllMatches',
bindKey: 'Ctrl-space', bindKey: 'Ctrl-space',
@ -149,19 +173,18 @@ exports.iSearchCommands = [{
return ranges.concat(ea ? ea : []); }, []) : []; return ranges.concat(ea ? ea : []); }, []) : [];
iSearch.deactivate(false); iSearch.deactivate(false);
ranges.forEach(ed.selection.addRange.bind(ed.selection)); ranges.forEach(ed.selection.addRange.bind(ed.selection));
} },
readOnly: true,
isIncrementalSearchCommand: true
}, { }, {
name: 'searchAsRegExp', name: 'searchAsRegExp',
bindKey: 'Alt-r', bindKey: 'Alt-r',
exec: function(iSearch) { exec: function(iSearch) {
iSearch.convertNeedleToRegExp(); iSearch.convertNeedleToRegExp();
} },
}].map(function(cmd) { readOnly: true,
cmd.readOnly = true; isIncrementalSearchCommand: true
cmd.isIncrementalSearchCommand = true; }];
cmd.scrollIntoView = "animate-cursor";
return cmd;
});
function IncrementalSearchKeyboardHandler(iSearch) { function IncrementalSearchKeyboardHandler(iSearch) {
this.$iSearch = iSearch; this.$iSearch = iSearch;
@ -169,7 +192,7 @@ function IncrementalSearchKeyboardHandler(iSearch) {
oop.inherits(IncrementalSearchKeyboardHandler, HashHandler); oop.inherits(IncrementalSearchKeyboardHandler, HashHandler);
(function() { ;(function() {
this.attach = function(editor) { this.attach = function(editor) {
var iSearch = this.$iSearch; var iSearch = this.$iSearch;
@ -178,19 +201,15 @@ oop.inherits(IncrementalSearchKeyboardHandler, HashHandler);
if (!e.command.isIncrementalSearchCommand) return undefined; if (!e.command.isIncrementalSearchCommand) return undefined;
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
var scrollTop = editor.session.getScrollTop(); return e.command.exec(iSearch, e.args || {});
var result = e.command.exec(iSearch, e.args || {});
editor.renderer.scrollCursorIntoView(null, 0.5);
editor.renderer.animateScrolling(scrollTop);
return result;
}); });
}; }
this.detach = function(editor) { this.detach = function(editor) {
if (!this.$commandExecHandler) return; if (!this.$commandExecHandler) return;
editor.commands.removeEventListener('exec', this.$commandExecHandler); editor.commands.removeEventListener('exec', this.$commandExecHandler);
delete this.$commandExecHandler; delete this.$commandExecHandler;
}; }
var handleKeyboard$super = this.handleKeyboard; var handleKeyboard$super = this.handleKeyboard;
this.handleKeyboard = function(data, hashId, key, keyCode) { this.handleKeyboard = function(data, hashId, key, keyCode) {
@ -203,7 +222,7 @@ oop.inherits(IncrementalSearchKeyboardHandler, HashHandler);
if (extendCmd) { return {command: extendCmd, args: key}; } if (extendCmd) { return {command: extendCmd, args: key}; }
} }
return {command: "null", passEvent: hashId == 0 || hashId == 4}; return {command: "null", passEvent: hashId == 0 || hashId == 4};
}; }
}).call(IncrementalSearchKeyboardHandler.prototype); }).call(IncrementalSearchKeyboardHandler.prototype);

View file

@ -39,7 +39,7 @@ var AppConfig = require("./lib/app_config").AppConfig;
module.exports = exports = new AppConfig(); module.exports = exports = new AppConfig();
var global = (function() { var global = (function() {
return this || typeof window != "undefined" && window; return this;
})(); })();
var options = { var options = {

View file

@ -160,8 +160,6 @@
z-index: 1; z-index: 1;
position: absolute; position: absolute;
overflow: hidden; overflow: hidden;
/* workaround for chrome bug https://github.com/ajaxorg/ace/issues/2312*/
word-wrap: normal;
white-space: pre; white-space: pre;
height: 100%; height: 100%;
width: 100%; width: 100%;
@ -422,30 +420,3 @@
position: absolute; position: absolute;
z-index: 8; z-index: 8;
} }
/*
styles = []
for (var i = 1; i < 16; i++) {
styles.push(".ace_br" + i + "{" + (
["top-left", "top-right", "bottom-right", "bottom-left"]
).map(function(x, j) {
return i & (1<<j) ? "border-" + x + "-radius: 3px;" : ""
}).filter(Boolean).join(" ") + "}")
}
styles.join("\n")
*/
.ace_br1 {border-top-left-radius : 3px;}
.ace_br2 {border-top-right-radius : 3px;}
.ace_br3 {border-top-left-radius : 3px; border-top-right-radius: 3px;}
.ace_br4 {border-bottom-right-radius: 3px;}
.ace_br5 {border-top-left-radius : 3px; border-bottom-right-radius: 3px;}
.ace_br6 {border-top-right-radius : 3px; border-bottom-right-radius: 3px;}
.ace_br7 {border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px;}
.ace_br8 {border-bottom-left-radius : 3px;}
.ace_br9 {border-top-left-radius : 3px; border-bottom-left-radius: 3px;}
.ace_br10{border-top-right-radius : 3px; border-bottom-left-radius: 3px;}
.ace_br11{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-left-radius: 3px;}
.ace_br12{border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
.ace_br13{border-top-left-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
.ace_br14{border-top-right-radius : 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}
.ace_br15{border-top-left-radius : 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;}

View file

@ -32,36 +32,36 @@ define(function(require, exports, module) {
"use strict"; "use strict";
var oop = require("./lib/oop"); var oop = require("./lib/oop");
var applyDelta = require("./apply_delta").applyDelta;
var EventEmitter = require("./lib/event_emitter").EventEmitter; var EventEmitter = require("./lib/event_emitter").EventEmitter;
var Range = require("./range").Range; var Range = require("./range").Range;
var Anchor = require("./anchor").Anchor; var Anchor = require("./anchor").Anchor;
/** /**
* Contains the text of the document. Document can be attached to several [[EditSession `EditSession`]]s. * Contains the text of the document. Document can be attached to several [[EditSession `EditSession`]]s.
*
* At its core, `Document`s are just an array of strings, with each row in the document matching up to the array index. * At its core, `Document`s are just an array of strings, with each row in the document matching up to the array index.
* *
* @class Document * @class Document
**/ **/
/** /**
* *
* Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty. * Creates a new `Document`. If `text` is included, the `Document` contains those strings; otherwise, it's empty.
* @param {String | Array} text The starting text * @param {String | Array} text The starting text
* @constructor * @constructor
**/ **/
var Document = function(textOrLines) { var Document = function(text) {
this.$lines = [""]; this.$lines = [];
// There has to be one line at least in the document. If you pass an empty // There has to be one line at least in the document. If you pass an empty
// string to the insert function, nothing will happen. Workaround. // string to the insert function, nothing will happen. Workaround.
if (textOrLines.length === 0) { if (text.length === 0) {
this.$lines = [""]; this.$lines = [""];
} else if (Array.isArray(textOrLines)) { } else if (Array.isArray(text)) {
this.insertMergedLines({row: 0, column: 0}, textOrLines); this._insertLines(0, text);
} else { } else {
this.insert({row: 0, column:0}, textOrLines); this.insert({row: 0, column:0}, text);
} }
}; };
@ -75,9 +75,9 @@ var Document = function(textOrLines) {
* @param {String} text The text to use * @param {String} text The text to use
**/ **/
this.setValue = function(text) { this.setValue = function(text) {
var len = this.getLength() - 1; var len = this.getLength();
this.remove(new Range(0, 0, len, this.getLine(len).length)); this.remove(new Range(0, 0, len, this.getLine(len-1).length));
this.insert({row: 0, column: 0}, text); this.insert({row: 0, column:0}, text);
}; };
/** /**
@ -98,7 +98,7 @@ var Document = function(textOrLines) {
}; };
/** /**
* Splits a string of text on any newline (`\n`) or carriage-return (`\r`) characters. * Splits a string of text on any newline (`\n`) or carriage-return ('\r') characters.
* *
* @method $split * @method $split
* @param {String} text The text to work with * @param {String} text The text to work with
@ -107,15 +107,14 @@ var Document = function(textOrLines) {
**/ **/
// check for IE split bug // check for IE split bug
if ("aaa".split(/a/).length === 0) { if ("aaa".split(/a/).length === 0)
this.$split = function(text) { this.$split = function(text) {
return text.replace(/\r\n|\r/g, "\n").split("\n"); return text.replace(/\r\n|\r/g, "\n").split("\n");
}; };
} else { else
this.$split = function(text) { this.$split = function(text) {
return text.split(/\r\n|\r|\n/); return text.split(/\r\n|\r|\n/);
}; };
}
this.$detectNewLine = function(text) { this.$detectNewLine = function(text) {
@ -208,49 +207,32 @@ var Document = function(textOrLines) {
}; };
/** /**
* Returns all the text within `range` as a single string. * [Given a range within the document, this function returns all the text within that range as a single string.]{: #Document.getTextRange.desc}
* @param {Range} range The range to work with. * @param {Range} range The range to work with
* *
* @returns {String} * @returns {String}
**/ **/
this.getTextRange = function(range) { this.getTextRange = function(range) {
return this.getLinesForRange(range).join(this.getNewLineCharacter()); if (range.start.row == range.end.row) {
}; return this.getLine(range.start.row)
.substring(range.start.column, range.end.column);
/**
* Returns all the text within `range` as an array of lines.
* @param {Range} range The range to work with.
*
* @returns {Array}
**/
this.getLinesForRange = function(range) {
var lines;
if (range.start.row === range.end.row) {
// Handle a single-line range.
lines = [this.getLine(range.start.row).substring(range.start.column, range.end.column)];
} else {
// Handle a multi-line range.
lines = this.getLines(range.start.row, range.end.row);
lines[0] = (lines[0] || "").substring(range.start.column);
var l = lines.length - 1;
if (range.end.row - range.start.row == l)
lines[l] = lines[l].substring(0, range.end.column);
} }
return lines; var lines = this.getLines(range.start.row, range.end.row);
lines[0] = (lines[0] || "").substring(range.start.column);
var l = lines.length - 1;
if (range.end.row - range.start.row == l)
lines[l] = lines[l].substring(0, range.end.column);
return lines.join(this.getNewLineCharacter());
}; };
// Deprecated methods retained for backwards compatibility. this.$clipPosition = function(position) {
this.insertLines = function(row, lines) { var length = this.getLength();
console.warn("Use of document.insertLines is deprecated. Use the insertFullLines method instead."); if (position.row >= length) {
return this.insertFullLines(row, lines); position.row = Math.max(0, length - 1);
}; position.column = this.getLine(length-1).length;
this.removeLines = function(firstRow, lastRow) { } else if (position.row < 0)
console.warn("Use of document.removeLines is deprecated. Use the removeFullLines method instead."); position.row = 0;
return this.removeFullLines(firstRow, lastRow); return position;
};
this.insertNewLine = function(position) {
console.warn("Use of document.insertNewLine is deprecated. Use insertMergedLines(position, [\'\', \'\']) instead.");
return this.insertMergedLines(position, ["", ""]);
}; };
/** /**
@ -261,160 +243,159 @@ var Document = function(textOrLines) {
* *
**/ **/
this.insert = function(position, text) { this.insert = function(position, text) {
// Only detect new lines if the document has no line break yet. if (!text || text.length === 0)
return position;
position = this.$clipPosition(position);
// only detect new lines if the document has no line break yet
if (this.getLength() <= 1) if (this.getLength() <= 1)
this.$detectNewLine(text); this.$detectNewLine(text);
return this.insertMergedLines(position, this.$split(text)); var lines = this.$split(text);
var firstLine = lines.splice(0, 1)[0];
var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
position = this.insertInLine(position, firstLine);
if (lastLine !== null) {
position = this.insertNewLine(position); // terminate first line
position = this._insertLines(position.row, lines);
position = this.insertInLine(position, lastLine || "");
}
return position;
}; };
/** /**
* Inserts `text` into the `position` at the current row. This method also triggers the `"change"` event. * Fires whenever the document changes.
* *
* This differs from the `insert` method in two ways: * Several methods trigger different `"change"` events. Below is a list of each action type, followed by each property that's also available:
* 1. This does NOT handle newline characters (single-line text only). *
* 2. This is faster than the `insert` method for single-line text insertions. * * `"insertLines"` (emitted by [[Document.insertLines]])
* * * `range`: the [[Range]] of the change within the document
* * `lines`: the lines in the document that are changing
* * `"insertText"` (emitted by [[Document.insertNewLine]])
* * `range`: the [[Range]] of the change within the document
* * `text`: the text that's being added
* * `"removeLines"` (emitted by [[Document.insertLines]])
* * `range`: the [[Range]] of the change within the document
* * `lines`: the lines in the document that were removed
* * `nl`: the new line character (as defined by [[Document.getNewLineCharacter]])
* * `"removeText"` (emitted by [[Document.removeInLine]] and [[Document.removeNewLine]])
* * `range`: the [[Range]] of the change within the document
* * `text`: the text that's being removed
*
* @event change
* @param {Object} e Contains at least one property called `"action"`. `"action"` indicates the action that triggered the change. Each action also has a set of additional properties.
*
**/
/**
* Inserts the elements in `lines` into the document, starting at the row index given by `row`. This method also triggers the `'change'` event.
* @param {Number} row The index of the row to insert at
* @param {Array} lines An array of strings
* @returns {Object} Contains the final row and column, like this:
* ```
* {row: endRow, column: 0}
* ```
* If `lines` is empty, this function returns an object containing the current row, and column, like this:
* ```
* {row: row, column: 0}
* ```
*
**/
this.insertLines = function(row, lines) {
if (row >= this.getLength())
return this.insert({row: row, column: 0}, "\n" + lines.join("\n"));
return this._insertLines(Math.max(row, 0), lines);
};
this._insertLines = function(row, lines) {
if (lines.length == 0)
return {row: row, column: 0};
// apply doesn't work for big arrays (smallest threshold is on safari 0xFFFF)
// to circumvent that we have to break huge inserts into smaller chunks here
while (lines.length > 0xF000) {
var end = this._insertLines(row, lines.slice(0, 0xF000));
lines = lines.slice(0xF000);
row = end.row;
}
var args = [row, 0];
args.push.apply(args, lines);
this.$lines.splice.apply(this.$lines, args);
var range = new Range(row, 0, row + lines.length, 0);
var delta = {
action: "insertLines",
range: range,
lines: lines
};
this._signal("change", { data: delta });
return range.end;
};
/**
* Inserts a new line into the document at the current row's `position`. This method also triggers the `'change'` event.
* @param {Object} position The position to insert at
* @returns {Object} Returns an object containing the final row and column, like this:<br/>
* ```
* {row: endRow, column: 0}
* ```
*
**/
this.insertNewLine = function(position) {
position = this.$clipPosition(position);
var line = this.$lines[position.row] || "";
this.$lines[position.row] = line.substring(0, position.column);
this.$lines.splice(position.row + 1, 0, line.substring(position.column, line.length));
var end = {
row : position.row + 1,
column : 0
};
var delta = {
action: "insertText",
range: Range.fromPoints(position, end),
text: this.getNewLineCharacter()
};
this._signal("change", { data: delta });
return end;
};
/**
* Inserts `text` into the `position` at the current row. This method also triggers the `'change'` event.
* @param {Object} position The position to insert at; it's an object that looks like `{ row: row, column: column}` * @param {Object} position The position to insert at; it's an object that looks like `{ row: row, column: column}`
* @param {String} text A chunk of text * @param {String} text A chunk of text
* @returns {Object} Returns an object containing the final row and column, like this: * @returns {Object} Returns an object containing the final row and column, like this:
* ``` * ```
* {row: endRow, column: 0} * {row: endRow, column: 0}
* ``` * ```
*
**/ **/
this.insertInLine = function(position, text) { this.insertInLine = function(position, text) {
var start = this.clippedPos(position.row, position.column); if (text.length == 0)
var end = this.pos(position.row, position.column + text.length); return position;
this.applyDelta({
start: start,
end: end,
action: "insert",
lines: [text]
}, true);
return this.clonePos(end);
};
this.clippedPos = function(row, column) {
var length = this.getLength();
if (row === undefined) {
row = length;
} else if (row < 0) {
row = 0;
} else if (row >= length) {
row = length - 1;
column = undefined;
}
var line = this.getLine(row);
if (column == undefined)
column = line.length;
column = Math.min(Math.max(column, 0), line.length);
return {row: row, column: column};
};
this.clonePos = function(pos) {
return {row: pos.row, column: pos.column};
};
this.pos = function(row, column) {
return {row: row, column: column};
};
this.$clipPosition = function(position) {
var length = this.getLength();
if (position.row >= length) {
position.row = Math.max(0, length - 1);
position.column = this.getLine(length - 1).length;
} else {
position.row = Math.max(0, position.row);
position.column = Math.min(Math.max(position.column, 0), this.getLine(position.row).length);
}
return position;
};
/** var line = this.$lines[position.row] || "";
* Fires whenever the document changes.
* this.$lines[position.row] = line.substring(0, position.column) + text
* Several methods trigger different `"change"` events. Below is a list of each action type, followed by each property that's also available: + line.substring(position.column);
*
* * `"insert"`
* * `range`: the [[Range]] of the change within the document
* * `lines`: the lines being added
* * `"remove"`
* * `range`: the [[Range]] of the change within the document
* * `lines`: the lines being removed
*
* @event change
* @param {Object} e Contains at least one property called `"action"`. `"action"` indicates the action that triggered the change. Each action also has a set of additional properties.
*
**/
/**
* Inserts the elements in `lines` into the document as full lines (does not merge with existing line), starting at the row index given by `row`. This method also triggers the `"change"` event.
* @param {Number} row The index of the row to insert at
* @param {Array} lines An array of strings
* @returns {Object} Contains the final row and column, like this:
* ```
* {row: endRow, column: 0}
* ```
* If `lines` is empty, this function returns an object containing the current row, and column, like this:
* ```
* {row: row, column: 0}
* ```
*
**/
this.insertFullLines = function(row, lines) {
// Clip to document.
// Allow one past the document end.
row = Math.min(Math.max(row, 0), this.getLength());
// Calculate insertion point.
var column = 0;
if (row < this.getLength()) {
// Insert before the specified row.
lines = lines.concat([""]);
column = 0;
} else {
// Insert after the last row in the document.
lines = [""].concat(lines);
row--;
column = this.$lines[row].length;
}
// Insert.
this.insertMergedLines({row: row, column: column}, lines);
};
/**
* Inserts the elements in `lines` into the document, starting at the position index given by `row`. This method also triggers the `"change"` event.
* @param {Number} row The index of the row to insert at
* @param {Array} lines An array of strings
* @returns {Object} Contains the final row and column, like this:
* ```
* {row: endRow, column: 0}
* ```
* If `lines` is empty, this function returns an object containing the current row, and column, like this:
* ```
* {row: row, column: 0}
* ```
*
**/
this.insertMergedLines = function(position, lines) {
var start = this.clippedPos(position.row, position.column);
var end = { var end = {
row: start.row + lines.length - 1, row : position.row,
column: (lines.length == 1 ? start.column : 0) + lines[lines.length - 1].length column : position.column + text.length
}; };
this.applyDelta({ var delta = {
start: start, action: "insertText",
end: end, range: Range.fromPoints(position, end),
action: "insert", text: text
lines: lines };
}); this._signal("change", { data: delta });
return this.clonePos(end); return end;
}; };
/** /**
@ -424,90 +405,113 @@ var Document = function(textOrLines) {
* *
**/ **/
this.remove = function(range) { this.remove = function(range) {
var start = this.clippedPos(range.start.row, range.start.column); if (!(range instanceof Range))
var end = this.clippedPos(range.end.row, range.end.column); range = Range.fromPoints(range.start, range.end);
this.applyDelta({ // clip to document
start: start, range.start = this.$clipPosition(range.start);
end: end, range.end = this.$clipPosition(range.end);
action: "remove",
lines: this.getLinesForRange({start: start, end: end}) if (range.isEmpty())
}); return range.start;
return this.clonePos(start);
var firstRow = range.start.row;
var lastRow = range.end.row;
if (range.isMultiLine()) {
var firstFullRow = range.start.column == 0 ? firstRow : firstRow + 1;
var lastFullRow = lastRow - 1;
if (range.end.column > 0)
this.removeInLine(lastRow, 0, range.end.column);
if (lastFullRow >= firstFullRow)
this._removeLines(firstFullRow, lastFullRow);
if (firstFullRow != firstRow) {
this.removeInLine(firstRow, range.start.column, this.getLine(firstRow).length);
this.removeNewLine(range.start.row);
}
}
else {
this.removeInLine(firstRow, range.start.column, range.end.column);
}
return range.start;
}; };
/** /**
* Removes the specified columns from the `row`. This method also triggers a `"change"` event. * Removes the specified columns from the `row`. This method also triggers the `'change'` event.
* @param {Number} row The row to remove from * @param {Number} row The row to remove from
* @param {Number} startColumn The column to start removing at * @param {Number} startColumn The column to start removing at
* @param {Number} endColumn The column to stop removing at * @param {Number} endColumn The column to stop removing at
* @returns {Object} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.<br/>If `startColumn` is equal to `endColumn`, this function returns nothing. * @returns {Object} Returns an object containing `startRow` and `startColumn`, indicating the new row and column values.<br/>If `startColumn` is equal to `endColumn`, this function returns nothing.
* *
**/ **/
this.removeInLine = function(row, startColumn, endColumn) { this.removeInLine = function(row, startColumn, endColumn) {
var start = this.clippedPos(row, startColumn); if (startColumn == endColumn)
var end = this.clippedPos(row, endColumn); return;
this.applyDelta({ var range = new Range(row, startColumn, row, endColumn);
start: start, var line = this.getLine(row);
end: end, var removed = line.substring(startColumn, endColumn);
action: "remove", var newLine = line.substring(0, startColumn) + line.substring(endColumn, line.length);
lines: this.getLinesForRange({start: start, end: end}) this.$lines.splice(row, 1, newLine);
}, true);
var delta = {
return this.clonePos(start); action: "removeText",
range: range,
text: removed
};
this._signal("change", { data: delta });
return range.start;
}; };
/** /**
* Removes a range of full lines. This method also triggers the `"change"` event. * Removes a range of full lines. This method also triggers the `'change'` event.
* @param {Number} firstRow The first row to be removed * @param {Number} firstRow The first row to be removed
* @param {Number} lastRow The last row to be removed * @param {Number} lastRow The last row to be removed
* @returns {[String]} Returns all the removed lines. * @returns {[String]} Returns all the removed lines.
* *
**/ **/
this.removeFullLines = function(firstRow, lastRow) { this.removeLines = function(firstRow, lastRow) {
// Clip to document. if (firstRow < 0 || lastRow >= this.getLength())
firstRow = Math.min(Math.max(0, firstRow), this.getLength() - 1); return this.remove(new Range(firstRow, 0, lastRow + 1, 0));
lastRow = Math.min(Math.max(0, lastRow ), this.getLength() - 1); return this._removeLines(firstRow, lastRow);
};
// Calculate deletion range.
// Delete the ending new line unless we're at the end of the document. this._removeLines = function(firstRow, lastRow) {
// If we're at the end of the document, delete the starting new line. var range = new Range(firstRow, 0, lastRow + 1, 0);
var deleteFirstNewLine = lastRow == this.getLength() - 1 && firstRow > 0; var removed = this.$lines.splice(firstRow, lastRow - firstRow + 1);
var deleteLastNewLine = lastRow < this.getLength() - 1;
var startRow = ( deleteFirstNewLine ? firstRow - 1 : firstRow ); var delta = {
var startCol = ( deleteFirstNewLine ? this.getLine(startRow).length : 0 ); action: "removeLines",
var endRow = ( deleteLastNewLine ? lastRow + 1 : lastRow ); range: range,
var endCol = ( deleteLastNewLine ? 0 : this.getLine(endRow).length ); nl: this.getNewLineCharacter(),
var range = new Range(startRow, startCol, endRow, endCol); lines: removed
};
// Store delelted lines with bounding newlines ommitted (maintains previous behavior). this._signal("change", { data: delta });
var deletedLines = this.$lines.slice(firstRow, lastRow + 1); return removed;
this.applyDelta({
start: range.start,
end: range.end,
action: "remove",
lines: this.getLinesForRange(range)
});
// Return the deleted lines.
return deletedLines;
}; };
/** /**
* Removes the new line between `row` and the row immediately following it. This method also triggers the `"change"` event. * Removes the new line between `row` and the row immediately following it. This method also triggers the `'change'` event.
* @param {Number} row The row to check * @param {Number} row The row to check
* *
**/ **/
this.removeNewLine = function(row) { this.removeNewLine = function(row) {
if (row < this.getLength() - 1 && row >= 0) { var firstLine = this.getLine(row);
this.applyDelta({ var secondLine = this.getLine(row+1);
start: this.pos(row, this.getLine(row).length),
end: this.pos(row + 1, 0), var range = new Range(row, firstLine.length, row+1, 0);
action: "remove", var line = firstLine + secondLine;
lines: ["", ""]
}); this.$lines.splice(row, 2, line);
}
var delta = {
action: "removeText",
range: range,
text: this.getNewLineCharacter()
};
this._signal("change", { data: delta });
}; };
/** /**
@ -521,9 +525,9 @@ var Document = function(textOrLines) {
* *
**/ **/
this.replace = function(range, text) { this.replace = function(range, text) {
if (!range instanceof Range) if (!(range instanceof Range))
range = Range.fromPoints(range.start, range.end); range = Range.fromPoints(range.start, range.end);
if (text.length === 0 && range.isEmpty()) if (text.length == 0 && range.isEmpty())
return range.start; return range.start;
// Shortcut: If the text we want to insert is the same as it is already // Shortcut: If the text we want to insert is the same as it is already
@ -532,106 +536,55 @@ var Document = function(textOrLines) {
return range.end; return range.end;
this.remove(range); this.remove(range);
var end;
if (text) { if (text) {
end = this.insert(range.start, text); var end = this.insert(range.start, text);
} }
else { else {
end = range.start; end = range.start;
} }
return end; return end;
}; };
/** /**
* Applies all changes in `deltas` to the document. * Applies all the changes previously accumulated. These can be either `'insertText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
* @param {Array} deltas An array of delta objects (can include "insert" and "remove" actions)
**/ **/
this.applyDeltas = function(deltas) { this.applyDeltas = function(deltas) {
for (var i=0; i<deltas.length; i++) { for (var i=0; i<deltas.length; i++) {
this.applyDelta(deltas[i]); var delta = deltas[i];
var range = Range.fromPoints(delta.range.start, delta.range.end);
if (delta.action == "insertLines")
this.insertLines(range.start.row, delta.lines);
else if (delta.action == "insertText")
this.insert(range.start, delta.text);
else if (delta.action == "removeLines")
this._removeLines(range.start.row, range.end.row - 1);
else if (delta.action == "removeText")
this.remove(range);
} }
}; };
/** /**
* Reverts all changes in `deltas` from the document. * Reverts any changes previously applied. These can be either `'insertText'`, `'insertLines'`, `'removeText'`, and `'removeLines'`.
* @param {Array} deltas An array of delta objects (can include "insert" and "remove" actions)
**/ **/
this.revertDeltas = function(deltas) { this.revertDeltas = function(deltas) {
for (var i=deltas.length-1; i>=0; i--) { for (var i=deltas.length-1; i>=0; i--) {
this.revertDelta(deltas[i]); var delta = deltas[i];
var range = Range.fromPoints(delta.range.start, delta.range.end);
if (delta.action == "insertLines")
this._removeLines(range.start.row, range.end.row - 1);
else if (delta.action == "insertText")
this.remove(range);
else if (delta.action == "removeLines")
this._insertLines(range.start.row, delta.lines);
else if (delta.action == "removeText")
this.insert(range.start, delta.text);
} }
}; };
/**
* Applies `delta` to the document.
* @param {Object} delta A delta object (can include "insert" and "remove" actions)
**/
this.applyDelta = function(delta, doNotValidate) {
var isInsert = delta.action == "insert";
// An empty range is a NOOP.
if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
: !Range.comparePoints(delta.start, delta.end)) {
return;
}
if (isInsert && delta.lines.length > 20000)
this.$splitAndapplyLargeDelta(delta, 20000);
// Apply.
applyDelta(this.$lines, delta, doNotValidate);
this._signal("change", delta);
};
this.$splitAndapplyLargeDelta = function(delta, MAX) {
// Split large insert deltas. This is necessary because:
// 1. We need to support splicing delta lines into the document via $lines.splice.apply(...)
// 2. fn.apply() doesn't work for a large number of params. The smallest threshold is on chrome 40 ~42000.
// we use 20000 to leave some space for actual stack
//
// To Do: Ideally we'd be consistent and also split 'delete' deltas. We don't do this now, because delete
// delta handling is too slow. If we make delete delta handling faster we can split all large deltas
// as shown in https://gist.github.com/aldendaniels/8367109#file-document-snippet-js
// If we do this, update validateDelta() to limit the number of lines in a delete delta.
var lines = delta.lines;
var l = lines.length;
var row = delta.start.row;
var column = delta.start.column;
var from = 0, to = 0;
do {
from = to;
to += MAX - 1;
var chunk = lines.slice(from, to);
if (to > l) {
// Update remaining delta.
delta.lines = chunk;
delta.start.row = row + from;
delta.start.column = column;
break;
}
chunk.push("");
this.applyDelta({
start: this.pos(row + from, column),
end: this.pos(row + to, column = 0),
action: delta.action,
lines: chunk
}, true);
} while(true);
};
/**
* Reverts `delta` from the document.
* @param {Object} delta A delta object (can include "insert" and "remove" actions)
**/
this.revertDelta = function(delta) {
this.applyDelta({
start: this.clonePos(delta.start),
end: this.clonePos(delta.end),
action: (delta.action == "insert" ? "remove" : "insert"),
lines: delta.lines.slice()
});
};
/** /**
* Converts an index position in a document to a `{row, column}` object. * Converts an index position in a document to a `{row, column}` object.
* *

View file

@ -46,7 +46,7 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insert({row: 0, column: 1}, "juhu"); doc.insert({row: 0, column: 1}, "juhu");
assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n")); assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n"));
@ -63,9 +63,9 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insertMergedLines({row: 0, column: 1}, ['', '']); doc.insertNewLine({row: 0, column: 1});
assert.equal(doc.getValue(), ["1", "2", "34"].join("\n")); assert.equal(doc.getValue(), ["1", "2", "34"].join("\n"));
var d = deltas.concat(); var d = deltas.concat();
@ -80,9 +80,9 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insertFullLines(0, ["aa", "bb"]); doc.insertLines(0, ["aa", "bb"]);
assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n")); assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n"));
var d = deltas.concat(); var d = deltas.concat();
@ -97,9 +97,9 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insertFullLines(2, ["aa", "bb"]); doc.insertLines(2, ["aa", "bb"]);
assert.equal(doc.getValue(), ["12", "34", "aa", "bb"].join("\n")); assert.equal(doc.getValue(), ["12", "34", "aa", "bb"].join("\n"));
}, },
@ -107,9 +107,9 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insertFullLines(1, ["aa", "bb"]); doc.insertLines(1, ["aa", "bb"]);
assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n")); assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n"));
var d = deltas.concat(); var d = deltas.concat();
@ -124,7 +124,7 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insert({row: 0, column: 0}, "aa\nbb\ncc"); doc.insert({row: 0, column: 0}, "aa\nbb\ncc");
assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n")); assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n"));
@ -141,9 +141,9 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insert({row: 1, column: 2}, "aa\nbb\ncc"); doc.insert({row: 2, column: 0}, "aa\nbb\ncc");
assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n")); assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n"));
var d = deltas.concat(); var d = deltas.concat();
@ -158,7 +158,7 @@ module.exports = {
var doc = new Document(["12", "34"]); var doc = new Document(["12", "34"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.insert({row: 0, column: 1}, "aa\nbb\ncc"); doc.insert({row: 0, column: 1}, "aa\nbb\ncc");
assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n")); assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n"));
@ -175,7 +175,7 @@ module.exports = {
var doc = new Document(["1234", "5678"]); var doc = new Document(["1234", "5678"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.remove(new Range(0, 1, 0, 3)); doc.remove(new Range(0, 1, 0, 3));
assert.equal(doc.getValue(), ["14", "5678"].join("\n")); assert.equal(doc.getValue(), ["14", "5678"].join("\n"));
@ -192,7 +192,7 @@ module.exports = {
var doc = new Document(["1234", "5678"]); var doc = new Document(["1234", "5678"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.remove(new Range(0, 4, 1, 0)); doc.remove(new Range(0, 4, 1, 0));
assert.equal(doc.getValue(), ["12345678"].join("\n")); assert.equal(doc.getValue(), ["12345678"].join("\n"));
@ -209,7 +209,7 @@ module.exports = {
var doc = new Document(["1234", "5678", "abcd"]); var doc = new Document(["1234", "5678", "abcd"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.remove(new Range(0, 2, 2, 2)); doc.remove(new Range(0, 2, 2, 2));
assert.equal(doc.getValue(), ["12cd"].join("\n")); assert.equal(doc.getValue(), ["12cd"].join("\n"));
@ -226,7 +226,7 @@ module.exports = {
var doc = new Document(["1234", "5678", "abcd"]); var doc = new Document(["1234", "5678", "abcd"]);
var deltas = []; var deltas = [];
doc.on("change", function(e) { deltas.push(e); }); doc.on("change", function(e) { deltas.push(e.data); });
doc.remove(new Range(1, 0, 3, 0)); doc.remove(new Range(1, 0, 3, 0));
assert.equal(doc.getValue(), ["1234", ""].join("\n")); assert.equal(doc.getValue(), ["1234", ""].join("\n"));
@ -235,7 +235,7 @@ module.exports = {
"test: remove lines should return the removed lines" : function() { "test: remove lines should return the removed lines" : function() {
var doc = new Document(["1234", "5678", "abcd"]); var doc = new Document(["1234", "5678", "abcd"]);
var removed = doc.removeFullLines(1, 2); var removed = doc.removeLines(1, 2);
assert.equal(removed.join("\n"), ["5678", "abcd"].join("\n")); assert.equal(removed.join("\n"), ["5678", "abcd"].join("\n"));
}, },
@ -296,35 +296,6 @@ module.exports = {
"test: empty document has to contain one line": function() { "test: empty document has to contain one line": function() {
var doc = new Document(""); var doc = new Document("");
assert.equal(doc.$lines.length, 1); assert.equal(doc.$lines.length, 1);
},
"test: ignore empty delta": function() {
var doc = new Document("");
doc.on("change", function() {
throw "should ignore empty delta";
})
doc.insert({row: 0, column: 0}, "");
doc.insert({row: 1, column: 1}, "");
doc.remove({start: {row: 1, column: 1}, end: {row: 1, column: 1}});
},
"test: inserting huge delta": function() {
var doc = new Document("");
var val = "";
var MAX = 0xF000;
for (var i = 0; i < 10 * MAX; i++) {
val += i + "\n"
}
doc.setValue(val);
assert.equal(doc.getValue(), val);
for (var i = 3 * MAX + 2; i >= 3 * MAX - 2; i--) {
val = doc.getLines(0, i).join("\n");
doc.setValue("\nab");
assert.equal(doc.getValue(), "\nab");
doc.insert({row: 1, column: 1}, val);
assert.equal(doc.getValue(), "\na" + val + "b");
}
} }
}; };

View file

@ -151,7 +151,7 @@ var EditSession = function(text, mode) {
this.$foldData = []; this.$foldData = [];
this.$foldData.toString = function() { this.$foldData.toString = function() {
return this.join("\n"); return this.join("\n");
}; }
this.on("changeFold", this.onChangeFold.bind(this)); this.on("changeFold", this.onChangeFold.bind(this));
this.$onChange = this.onChange.bind(this); this.$onChange = this.onChange.bind(this);
@ -249,12 +249,13 @@ var EditSession = function(text, mode) {
this.$resetRowCache(fold.start.row); this.$resetRowCache(fold.start.row);
}; };
this.onChange = function(delta) { this.onChange = function(e) {
var delta = e.data;
this.$modified = true; this.$modified = true;
this.$resetRowCache(delta.start.row); this.$resetRowCache(delta.range.start.row);
var removedFolds = this.$updateInternalDataOnChange(delta); var removedFolds = this.$updateInternalDataOnChange(e);
if (!this.$fromUndo && this.$undoManager && !delta.ignore) { if (!this.$fromUndo && this.$undoManager && !delta.ignore) {
this.$deltasDoc.push(delta); this.$deltasDoc.push(delta);
if (removedFolds && removedFolds.length != 0) { if (removedFolds && removedFolds.length != 0) {
@ -268,7 +269,7 @@ var EditSession = function(text, mode) {
} }
this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta); this.bgTokenizer && this.bgTokenizer.$updateOnChange(delta);
this._signal("change", delta); this._signal("change", e);
}; };
/** /**
@ -678,10 +679,10 @@ var EditSession = function(text, mode) {
}; };
/** /**
* Returns an object containing all of the markers, either front or back. * Returns an array containing the IDs of all the markers, either front or back.
* @param {Boolean} inFront If `true`, indicates you only want front markers; `false` indicates only back markers * @param {Boolean} inFront If `true`, indicates you only want front markers; `false` indicates only back markers
* *
* @returns {Object} * @returns {Array}
**/ **/
this.getMarkers = function(inFront) { this.getMarkers = function(inFront) {
return inFront ? this.$frontMarkers : this.$backMarkers; return inFront ? this.$frontMarkers : this.$backMarkers;
@ -892,17 +893,17 @@ var EditSession = function(text, mode) {
config.loadModule(["mode", path], function(m) { config.loadModule(["mode", path], function(m) {
if (this.$modeId !== path) if (this.$modeId !== path)
return cb && cb(); return cb && cb();
if (this.$modes[path] && !options) { if (this.$modes[path] && !options)
this.$onChangeMode(this.$modes[path]); return this.$onChangeMode(this.$modes[path]);
} else if (m && m.Mode) { if (m && m.Mode) {
m = new m.Mode(options); m = new m.Mode(options);
if (!options) { if (!options) {
this.$modes[path] = m; this.$modes[path] = m;
m.$id = path; m.$id = path;
} }
this.$onChangeMode(m); this.$onChangeMode(m);
cb && cb();
} }
cb && cb();
}.bind(this)); }.bind(this));
// set mode to text until loading is finished // set mode to text until loading is finished
@ -1145,19 +1146,6 @@ var EditSession = function(text, mode) {
this.remove = function(range) { this.remove = function(range) {
return this.doc.remove(range); return this.doc.remove(range);
}; };
/**
* Removes a range of full lines. This method also triggers the `'change'` event.
* @param {Number} firstRow The first row to be removed
* @param {Number} lastRow The last row to be removed
* @returns {[String]} Returns all the removed lines.
*
* @related Document.removeFullLines
*
**/
this.removeFullLines = function(firstRow, lastRow){
return this.doc.removeFullLines(firstRow, lastRow);
};
/** /**
* Reverts previous changes to your document. * Reverts previous changes to your document.
@ -1234,36 +1222,39 @@ var EditSession = function(text, mode) {
this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) { this.$getUndoSelection = function(deltas, isUndo, lastUndoRange) {
function isInsert(delta) { function isInsert(delta) {
return isUndo ? delta.action !== "insert" : delta.action === "insert"; var insert =
delta.action === "insertText" || delta.action === "insertLines";
return isUndo ? !insert : insert;
} }
var delta = deltas[0]; var delta = deltas[0];
var range, point; var range, point;
var lastDeltaIsInsert = false; var lastDeltaIsInsert = false;
if (isInsert(delta)) { if (isInsert(delta)) {
range = Range.fromPoints(delta.start, delta.end); range = Range.fromPoints(delta.range.start, delta.range.end);
lastDeltaIsInsert = true; lastDeltaIsInsert = true;
} else { } else {
range = Range.fromPoints(delta.start, delta.start); range = Range.fromPoints(delta.range.start, delta.range.start);
lastDeltaIsInsert = false; lastDeltaIsInsert = false;
} }
for (var i = 1; i < deltas.length; i++) { for (var i = 1; i < deltas.length; i++) {
delta = deltas[i]; delta = deltas[i];
if (isInsert(delta)) { if (isInsert(delta)) {
point = delta.start; point = delta.range.start;
if (range.compare(point.row, point.column) == -1) { if (range.compare(point.row, point.column) == -1) {
range.setStart(point); range.setStart(delta.range.start);
} }
point = delta.end; point = delta.range.end;
if (range.compare(point.row, point.column) == 1) { if (range.compare(point.row, point.column) == 1) {
range.setEnd(point); range.setEnd(delta.range.end);
} }
lastDeltaIsInsert = true; lastDeltaIsInsert = true;
} else { } else {
point = delta.start; point = delta.range.start;
if (range.compare(point.row, point.column) == -1) { if (range.compare(point.row, point.column) == -1) {
range = Range.fromPoints(delta.start, delta.start); range =
Range.fromPoints(delta.range.start, delta.range.start);
} }
lastDeltaIsInsert = false; lastDeltaIsInsert = false;
} }
@ -1377,7 +1368,7 @@ var EditSession = function(text, mode) {
this.indentRows = function(startRow, endRow, indentString) { this.indentRows = function(startRow, endRow, indentString) {
indentString = indentString.replace(/\t/g, this.getTabString()); indentString = indentString.replace(/\t/g, this.getTabString());
for (var row=startRow; row<=endRow; row++) for (var row=startRow; row<=endRow; row++)
this.doc.insertInLine({row: row, column: 0}, indentString); this.insert({row: row, column:0}, indentString);
}; };
/** /**
@ -1434,11 +1425,11 @@ var EditSession = function(text, mode) {
x.end.row += diff; x.end.row += diff;
return x; return x;
}); });
var lines = dir == 0 var lines = dir == 0
? this.doc.getLines(firstRow, lastRow) ? this.doc.getLines(firstRow, lastRow)
: this.doc.removeFullLines(firstRow, lastRow); : this.doc.removeLines(firstRow, lastRow);
this.doc.insertFullLines(firstRow+diff, lines); this.doc.insertLines(firstRow+diff, lines);
folds.length && this.addFolds(folds); folds.length && this.addFolds(folds);
return diff; return diff;
}; };
@ -1448,6 +1439,8 @@ var EditSession = function(text, mode) {
* @param {Number} lastRow The final row to move up * @param {Number} lastRow The final row to move up
* @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1. * @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1.
* *
* @related Document.insertLines
*
**/ **/
this.moveLinesUp = function(firstRow, lastRow) { this.moveLinesUp = function(firstRow, lastRow) {
return this.$moveLines(firstRow, lastRow, -1); return this.$moveLines(firstRow, lastRow, -1);
@ -1458,6 +1451,8 @@ var EditSession = function(text, mode) {
* @param {Number} firstRow The starting row to move down * @param {Number} firstRow The starting row to move down
* @param {Number} lastRow The final row to move down * @param {Number} lastRow The final row to move down
* @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1. * @returns {Number} If `firstRow` is less-than or equal to 0, this function returns 0. Otherwise, on success, it returns -1.
*
* @related Document.insertLines
**/ **/
this.moveLinesDown = function(firstRow, lastRow) { this.moveLinesDown = function(firstRow, lastRow) {
return this.$moveLines(firstRow, lastRow, 1); return this.$moveLines(firstRow, lastRow, 1);
@ -1585,11 +1580,13 @@ var EditSession = function(text, mode) {
**/ **/
this.setWrapLimitRange = function(min, max) { this.setWrapLimitRange = function(min, max) {
if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) { if (this.$wrapLimitRange.min !== min || this.$wrapLimitRange.max !== max) {
this.$wrapLimitRange = { min: min, max: max }; this.$wrapLimitRange = {
min: min,
max: max
};
this.$modified = true; this.$modified = true;
// This will force a recalculation of the wrap limit // This will force a recalculation of the wrap limit
if (this.$useWrapMode) this._signal("changeWrapMode");
this._signal("changeWrapMode");
} }
}; };
@ -1661,23 +1658,34 @@ var EditSession = function(text, mode) {
}; };
}; };
this.$updateInternalDataOnChange = function(delta) { this.$updateInternalDataOnChange = function(e) {
var useWrapMode = this.$useWrapMode; var useWrapMode = this.$useWrapMode;
var action = delta.action; var len;
var start = delta.start; var action = e.data.action;
var end = delta.end; var firstRow = e.data.range.start.row;
var firstRow = start.row; var lastRow = e.data.range.end.row;
var lastRow = end.row; var start = e.data.range.start;
var len = lastRow - firstRow; var end = e.data.range.end;
var removedFolds = null; var removedFolds = null;
if (action.indexOf("Lines") != -1) {
if (action == "insertLines") {
lastRow = firstRow + (e.data.lines.length);
} else {
lastRow = firstRow;
}
len = e.data.lines ? e.data.lines.length : lastRow - firstRow;
} else {
len = lastRow - firstRow;
}
this.$updating = true; this.$updating = true;
if (len != 0) { if (len != 0) {
if (action === "remove") { if (action.indexOf("remove") != -1) {
this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len); this[useWrapMode ? "$wrapData" : "$rowLengthCache"].splice(firstRow, len);
var foldLines = this.$foldData; var foldLines = this.$foldData;
removedFolds = this.getFoldsInRange(delta); removedFolds = this.getFoldsInRange(e.data.range);
this.removeFolds(removedFolds); this.removeFolds(removedFolds);
var foldLine = this.getFoldLine(end.row); var foldLine = this.getFoldLine(end.row);
@ -1742,10 +1750,10 @@ var EditSession = function(text, mode) {
} else { } else {
// Realign folds. E.g. if you add some new chars before a fold, the // Realign folds. E.g. if you add some new chars before a fold, the
// fold should "move" to the right. // fold should "move" to the right.
len = Math.abs(delta.start.column - delta.end.column); len = Math.abs(e.data.range.start.column - e.data.range.end.column);
if (action === "remove") { if (action.indexOf("remove") != -1) {
// Get all the folds in the change range and remove them. // Get all the folds in the change range and remove them.
removedFolds = this.getFoldsInRange(delta); removedFolds = this.getFoldsInRange(e.data.range);
this.removeFolds(removedFolds); this.removeFolds(removedFolds);
len = -len; len = -len;
@ -1829,7 +1837,7 @@ var EditSession = function(text, mode) {
TAB_SPACE = 12; TAB_SPACE = 12;
this.$computeWrapSplits = function(tokens, wrapLimit, tabSize) { this.$computeWrapSplits = function(tokens, wrapLimit) {
if (tokens.length == 0) { if (tokens.length == 0) {
return []; return [];
} }
@ -1840,31 +1848,6 @@ var EditSession = function(text, mode) {
var isCode = this.$wrapAsCode; var isCode = this.$wrapAsCode;
var indentedSoftWrap = this.$indentedSoftWrap;
var maxIndent = wrapLimit <= Math.max(2 * tabSize, 8)
|| indentedSoftWrap === false ? 0 : Math.floor(wrapLimit / 2);
function getWrapIndent() {
var indentation = 0;
if (maxIndent === 0)
return indentation;
if (indentedSoftWrap) {
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
if (token == SPACE)
indentation += 1;
else if (token == TAB)
indentation += tabSize;
else if (token == TAB_SPACE)
continue;
else
break;
}
}
if (isCode && indentedSoftWrap !== false)
indentation += tabSize;
return Math.min(indentation, maxIndent);
}
function addSplit(screenPos) { function addSplit(screenPos) {
var displayed = tokens.slice(lastSplit, screenPos); var displayed = tokens.slice(lastSplit, screenPos);
@ -1881,18 +1864,14 @@ var EditSession = function(text, mode) {
len -= 1; len -= 1;
}); });
if (!splits.length) {
indent = getWrapIndent();
splits.indent = indent;
}
lastDocSplit += len; lastDocSplit += len;
splits.push(lastDocSplit); splits.push(lastDocSplit);
lastSplit = screenPos; lastSplit = screenPos;
} }
var indent = 0;
while (displayLength - lastSplit > wrapLimit - indent) { while (displayLength - lastSplit > wrapLimit) {
// This is, where the split should be. // This is, where the split should be.
var split = lastSplit + wrapLimit - indent; var split = lastSplit + wrapLimit;
// If there is a space or tab at this split position, then making // If there is a space or tab at this split position, then making
// a split is simple. // a split is simple.
@ -1952,7 +1931,7 @@ var EditSession = function(text, mode) {
// === ELSE === // === ELSE ===
// Search for the first non space/tab/placeholder/punctuation token backwards. // Search for the first non space/tab/placeholder/punctuation token backwards.
var minSplit = Math.max(split - (wrapLimit -(wrapLimit>>2)), lastSplit - 1); var minSplit = Math.max(split - (isCode ? 10 : wrapLimit-(wrapLimit>>2)), lastSplit - 1);
while (split > minSplit && tokens[split] < PLACEHOLDER_START) { while (split > minSplit && tokens[split] < PLACEHOLDER_START) {
split --; split --;
} }
@ -1980,7 +1959,7 @@ var EditSession = function(text, mode) {
// around -> force a split. // around -> force a split.
if (tokens[split] == CHAR_EXT) if (tokens[split] == CHAR_EXT)
split--; split--;
addSplit(split - indent); addSplit(split);
} }
return splits; return splits;
}; };
@ -2087,16 +2066,6 @@ var EditSession = function(text, mode) {
} }
}; };
this.getRowWrapIndent = function(screenRow) {
if (this.$useWrapMode) {
var pos = this.screenToDocumentPosition(screenRow, Number.MAX_VALUE);
var splits = this.$wrapData[pos.row];
return splits.length && splits[0] < pos.column ? splits.indent : 0;
} else {
return 0;
}
}
/** /**
* Returns the position (on screen) for the last character in the provided screen row. * Returns the position (on screen) for the last character in the provided screen row.
* @param {Number} screenRow The screen row to check * @param {Number} screenRow The screen row to check
@ -2234,21 +2203,20 @@ var EditSession = function(text, mode) {
line = this.getLine(docRow); line = this.getLine(docRow);
foldLine = null; foldLine = null;
} }
var wrapIndent = 0;
if (this.$useWrapMode) { if (this.$useWrapMode) {
var splits = this.$wrapData[docRow]; var splits = this.$wrapData[docRow];
if (splits) { if (splits) {
var splitIndex = Math.floor(screenRow - row); var splitIndex = Math.floor(screenRow - row);
column = splits[splitIndex]; column = splits[splitIndex];
if(splitIndex > 0 && splits.length) { if(splitIndex > 0 && splits.length) {
wrapIndent = splits.indent;
docColumn = splits[splitIndex - 1] || splits[splits.length - 1]; docColumn = splits[splitIndex - 1] || splits[splits.length - 1];
line = line.substring(docColumn); line = line.substring(docColumn);
} }
} }
} }
docColumn += this.$getStringScreenWidth(line, screenColumn - wrapIndent)[1]; docColumn += this.$getStringScreenWidth(line, screenColumn)[1];
// We remove one character at the end so that the docColumn // We remove one character at the end so that the docColumn
// position returned is not associated to the next row on the screen. // position returned is not associated to the next row on the screen.
@ -2340,7 +2308,6 @@ var EditSession = function(text, mode) {
textLine = this.getLine(docRow).substring(0, docColumn); textLine = this.getLine(docRow).substring(0, docColumn);
foldStartRow = docRow; foldStartRow = docRow;
} }
var wrapIndent = 0;
// Clamp textLine if in wrapMode. // Clamp textLine if in wrapMode.
if (this.$useWrapMode) { if (this.$useWrapMode) {
var wrapRow = this.$wrapData[foldStartRow]; var wrapRow = this.$wrapData[foldStartRow];
@ -2353,13 +2320,12 @@ var EditSession = function(text, mode) {
textLine = textLine.substring( textLine = textLine.substring(
wrapRow[screenRowOffset - 1] || 0, textLine.length wrapRow[screenRowOffset - 1] || 0, textLine.length
); );
wrapIndent = screenRowOffset > 0 ? wrapRow.indent : 0;
} }
} }
return { return {
row: screenRow, row: screenRow,
column: wrapIndent + this.$getStringScreenWidth(textLine)[0] column: this.$getStringScreenWidth(textLine)[0]
}; };
}; };
@ -2501,7 +2467,6 @@ config.defineOptions(EditSession.prototype, "session", {
if (this.$wrap == value) if (this.$wrap == value)
return; return;
this.$wrap = value;
if (!value) { if (!value) {
this.setUseWrapMode(false); this.setUseWrapMode(false);
} else { } else {
@ -2509,6 +2474,7 @@ config.defineOptions(EditSession.prototype, "session", {
this.setWrapLimitRange(col, col); this.setWrapLimitRange(col, col);
this.setUseWrapMode(true); this.setUseWrapMode(true);
} }
this.$wrap = value;
}, },
get: function() { get: function() {
if (this.getUseWrapMode()) { if (this.getUseWrapMode()) {
@ -2539,7 +2505,6 @@ config.defineOptions(EditSession.prototype, "session", {
}, },
initialValue: "auto" initialValue: "auto"
}, },
indentedSoftWrap: { initialValue: true },
firstLineNumber: { firstLineNumber: {
set: function() {this._signal("changeBreakpoint");}, set: function() {this._signal("changeBreakpoint");},
initialValue: 1 initialValue: 1

View file

@ -117,7 +117,7 @@ function BracketMatch() {
typeRe = new RegExp( typeRe = new RegExp(
"(\\.?" + "(\\.?" +
token.type.replace(".", "\\.").replace("rparen", ".paren") token.type.replace(".", "\\.").replace("rparen", ".paren")
.replace(/\b(?:end)\b/, "(?:start|begin|end)") .replace(/\b(?:end|start|begin)\b/, "")
+ ")+" + ")+"
); );
} }
@ -174,7 +174,7 @@ function BracketMatch() {
typeRe = new RegExp( typeRe = new RegExp(
"(\\.?" + "(\\.?" +
token.type.replace(".", "\\.").replace("lparen", ".paren") token.type.replace(".", "\\.").replace("lparen", ".paren")
.replace(/\b(?:start|begin)\b/, "(?:start|begin|end)") .replace(/\b(?:end|start|begin)\b/, "")
+ ")+" + ")+"
); );
} }

View file

@ -794,7 +794,7 @@ function Folding() {
this.foldAll(startRow, endRow, options.all ? 10000 : 0); this.foldAll(startRow, endRow, options.all ? 10000 : 0);
} else if (options.children) { } else if (options.children) {
endRow = range ? range.end.row : this.getLength(); endRow = range ? range.end.row : this.getLength();
this.foldAll(row + 1, endRow, options.all ? 10000 : 0); this.foldAll(row + 1, range.end.row, options.all ? 10000 : 0);
} else if (range) { } else if (range) {
if (options.all) if (options.all)
range.collapseChildren = 10000; range.collapseChildren = 10000;
@ -829,13 +829,15 @@ function Folding() {
} }
}; };
this.updateFoldWidgets = function(delta) { this.updateFoldWidgets = function(e) {
var firstRow = delta.start.row; var delta = e.data;
var len = delta.end.row - firstRow; var range = delta.range;
var firstRow = range.start.row;
var len = range.end.row - firstRow;
if (len === 0) { if (len === 0) {
this.foldWidgets[firstRow] = null; this.foldWidgets[firstRow] = null;
} else if (delta.action == 'remove') { } else if (delta.action == "removeText" || delta.action == "removeLines") {
this.foldWidgets.splice(firstRow, len + 1, null); this.foldWidgets.splice(firstRow, len + 1, null);
} else { } else {
var args = Array(len + 1); var args = Array(len + 1);

View file

@ -280,7 +280,7 @@ module.exports = {
session.setUseWrapMode(true); session.setUseWrapMode(true);
session.setWrapLimitRange(12, 12); session.setWrapLimitRange(12, 12);
session.adjustWrapLimit(80); session.adjustWrapLimit(80);
session.setOption("wrapMethod", "text");
assert.position(session.documentToScreenPosition(0, 11), 0, 11); assert.position(session.documentToScreenPosition(0, 11), 0, 11);
assert.position(session.documentToScreenPosition(0, 12), 1, 0); assert.position(session.documentToScreenPosition(0, 12), 1, 0);
}, },
@ -380,8 +380,7 @@ module.exports = {
line = lang.stringTrimRight(line); line = lang.stringTrimRight(line);
var tokens = EditSession.prototype.$getDisplayTokens(line); var tokens = EditSession.prototype.$getDisplayTokens(line);
var splits = EditSession.prototype.$computeWrapSplits(tokens, wrapLimit, tabSize); var splits = EditSession.prototype.$computeWrapSplits(tokens, wrapLimit, tabSize);
console.log("String:", line, "Result:", splits, "Expected:", assertEqual); // console.log("String:", line, "Result:", splits, "Expected:", assertEqual);
assert.ok(splits.length == assertEqual.length); assert.ok(splits.length == assertEqual.length);
for (var i = 0; i < splits.length; i++) { for (var i = 0; i < splits.length; i++) {
assert.ok(splits[i] == assertEqual[i]); assert.ok(splits[i] == assertEqual[i]);
@ -389,7 +388,6 @@ module.exports = {
} }
EditSession.prototype.$wrapAsCode = true; EditSession.prototype.$wrapAsCode = true;
EditSession.prototype.$indentedSoftWrap = false;
// Basic splitting. // Basic splitting.
computeAndAssert("foo bar foo bar", [ 12 ]); computeAndAssert("foo bar foo bar", [ 12 ]);
computeAndAssert("foo bar f bar", [ 12 ]); computeAndAssert("foo bar f bar", [ 12 ]);
@ -415,26 +413,16 @@ module.exports = {
computeAndAssert("ぁぁ", [1], 2); computeAndAssert("ぁぁ", [1], 2);
computeAndAssert(" ぁぁ", [1, 2], 2); computeAndAssert(" ぁぁ", [1, 2], 2);
computeAndAssert(" ぁ\tぁ", [1, 3], 2); computeAndAssert(" ぁ\tぁ", [1, 3], 2);
computeAndAssert(" ぁぁ\tぁ", [2, 4], 4); computeAndAssert(" ぁぁ\tぁ", [1, 4], 4);
computeAndAssert("ぁぁ ぁぁ\tぁ", [3, 6], 6);
// Test wrapping for punctuation. // Test wrapping for punctuation.
computeAndAssert(" ab.c;ef++", [2, 4, 6, 8], 2); computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2);
computeAndAssert(" ab.c;ef++", [3, 5, 8], 3);
computeAndAssert(" a.b", [1, 2, 3], 1); computeAndAssert(" a.b", [1, 2, 3], 1);
computeAndAssert("#>>", [1, 2], 1); computeAndAssert("#>>", [1, 2], 1);
// Test wrapping for punctuation in // Test wrapping for punctuation in
EditSession.prototype.$wrapAsCode = false; EditSession.prototype.$wrapAsCode = false;
computeAndAssert("ab cde, Juhu kinners", [3, 8, 13, 19], 6); computeAndAssert("ab cde, Juhu kinners", [3, 8, 13, 19], 6);
// test indented wrapping
EditSession.prototype.$indentedSoftWrap = true;
computeAndAssert("foo bar foo bar foo bara foo", [12, 25]);
computeAndAssert("fooooooooooooooooooooooooooo", [12, 24]);
computeAndAssert("\t\tfoo bar fooooooooooobooooooo", [6, 10, 16, 22, 28]);
computeAndAssert("\t\t\tfoo bar fooooooooooobooooooo", [3, 7, 11, 17, 23, 29]);
computeAndAssert("\tfoo \t \t \t \t bar", [6, 12]); // 14
}, },
"test get longest line" : function() { "test get longest line" : function() {
@ -442,12 +430,12 @@ module.exports = {
session.setTabSize(4); session.setTabSize(4);
assert.equal(session.getScreenWidth(), 2); assert.equal(session.getScreenWidth(), 2);
session.doc.insertMergedLines({row: 0, column: Infinity}, ['', '']); session.doc.insertNewLine({row: 0, column: Infinity});
session.doc.insertFullLines(1, ["123"]); session.doc.insertLines(1, ["123"]);
assert.equal(session.getScreenWidth(), 3); assert.equal(session.getScreenWidth(), 3);
session.doc.insertMergedLines({row: 0, column: Infinity}, ['', '']); session.doc.insertNewLine({row: 0, column: Infinity});
session.doc.insertFullLines(1, ["\t\t"]); session.doc.insertLines(1, ["\t\t"]);
assert.equal(session.getScreenWidth(), 8); assert.equal(session.getScreenWidth(), 8);
@ -471,9 +459,9 @@ module.exports = {
session.setUseWrapMode(true); session.setUseWrapMode(true);
document.insertFullLines(0, ["a", "b"]); document.insertLines(0, ["a", "b"]);
document.insertFullLines(2, ["c", "d"]); document.insertLines(2, ["c", "d"]);
document.removeFullLines(1, 2); document.removeLines(1, 2);
}, },
"test wrapMode init has to create wrapData array": function() { "test wrapMode init has to create wrapData array": function() {

View file

@ -150,8 +150,9 @@ var Editor = function(renderer, session) {
args: commadEvent.args, args: commadEvent.args,
scrollTop: this.renderer.scrollTop scrollTop: this.renderer.scrollTop
}; };
if (this.curOp.command.name && this.curOp.command.scrollIntoView !== undefined) if (this.curOp.command.name)
this.$blockScrolling++; this.$blockScrolling++;
// this.selections.push(this.selection.toJSON());
}; };
this.endOperation = function(e) { this.endOperation = function(e) {
@ -160,14 +161,10 @@ var Editor = function(renderer, session) {
return this.curOp = null; return this.curOp = null;
this._signal("beforeEndOperation"); this._signal("beforeEndOperation");
var command = this.curOp.command; var command = this.curOp.command;
if (command.name && this.$blockScrolling > 0) if (command.name && this.$blockScrolling)
this.$blockScrolling--; this.$blockScrolling--;
var scrollIntoView = command && command.scrollIntoView; if (command && command.scrollIntoView) {
if (scrollIntoView) { switch (command.scrollIntoView) {
switch (scrollIntoView) {
case "center-animate":
scrollIntoView = "animate";
/* fall through */
case "center": case "center":
this.renderer.scrollCursorIntoView(null, 0.5); this.renderer.scrollCursorIntoView(null, 0.5);
break; break;
@ -185,7 +182,7 @@ var Editor = function(renderer, session) {
default: default:
break; break;
} }
if (scrollIntoView == "animate") if (command.scrollIntoView == "animate")
this.renderer.animateScrolling(this.curOp.scrollTop); this.renderer.animateScrolling(this.curOp.scrollTop);
} }
@ -278,10 +275,6 @@ var Editor = function(renderer, session) {
this.setSession = function(session) { this.setSession = function(session) {
if (this.session == session) if (this.session == session)
return; return;
// make sure operationEnd events are not emitted to wrong session
if (this.curOp) this.endOperation();
this.curOp = {};
var oldSession = this.session; var oldSession = this.session;
if (oldSession) { if (oldSession) {
@ -381,8 +374,6 @@ var Editor = function(renderer, session) {
oldSession: oldSession oldSession: oldSession
}); });
this.curOp = null;
oldSession && oldSession._signal("changeEditor", {oldEditor: this}); oldSession && oldSession._signal("changeEditor", {oldEditor: this});
session && session._signal("changeEditor", {editor: this}); session && session._signal("changeEditor", {editor: this});
}; };
@ -554,12 +545,9 @@ var Editor = function(renderer, session) {
return; return;
} }
if (token.type.indexOf("tag-open") != -1) { if (token.type.indexOf("tag-open") != -1)
token = iterator.stepForward(); token = iterator.stepForward();
if (!token)
return;
}
var tag = token.value; var tag = token.value;
var depth = 0; var depth = 0;
var prevToken = iterator.stepBackward(); var prevToken = iterator.stepBackward();
@ -692,15 +680,20 @@ var Editor = function(renderer, session) {
* *
* *
**/ **/
this.onDocumentChange = function(delta) { this.onDocumentChange = function(e) {
// Rerender and emit "change" event. var delta = e.data;
var wrap = this.session.$useWrapMode; var range = delta.range;
var lastRow = (delta.start.row == delta.end.row ? delta.end.row : Infinity); var lastRow;
this.renderer.updateLines(delta.start.row, lastRow, wrap);
this._signal("change", delta); if (range.start.row == range.end.row && delta.action != "insertLines" && delta.action != "removeLines")
lastRow = range.end.row;
// Update cursor because tab characters can influence the cursor position. else
lastRow = Infinity;
this.renderer.updateLines(range.start.row, lastRow, this.session.$useWrapMode);
this._signal("change", e);
// update cursor because tab characters can influence the cursor position
this.$cursorChange(); this.$cursorChange();
this.$updateHighlightActiveLine(); this.$updateHighlightActiveLine();
}; };
@ -915,16 +908,14 @@ var Editor = function(renderer, session) {
* *
* *
**/ **/
this.onPaste = function(text, event) { this.onPaste = function(text) {
var e = {text: text, event: event}; // todo this should change when paste becomes a command
this.commands.exec("paste", this, e); if (this.$readOnly)
}; return;
this.$handlePaste = function(e) { var e = {text: text};
if (typeof e == "string")
e = {text: e};
this._signal("paste", e); this._signal("paste", e);
var text = e.text; text = e.text;
if (!this.inMultiSelectMode || this.inVirtualSelectionMode) { if (!this.inMultiSelectMode || this.inVirtualSelectionMode) {
this.insert(text); this.insert(text);
} else { } else {
@ -942,6 +933,7 @@ var Editor = function(renderer, session) {
this.session.insert(range.start, lines[i]); this.session.insert(range.start, lines[i]);
} }
} }
this.renderer.scrollCursorIntoView();
}; };
this.execCommand = function(command, args) { this.execCommand = function(command, args) {
@ -1297,7 +1289,7 @@ var Editor = function(renderer, session) {
}; };
/** /**
* Removes the current selection or one character. * Removes words of text from the editor. A "word" is defined as a string of characters bookended by whitespace.
* @param {String} dir The direction of the deletion to occur, either "left" or "right" * @param {String} dir The direction of the deletion to occur, either "left" or "right"
* *
**/ **/
@ -1629,7 +1621,15 @@ var Editor = function(renderer, session) {
**/ **/
this.removeLines = function() { this.removeLines = function() {
var rows = this.$getSelectedRows(); var rows = this.$getSelectedRows();
this.session.removeFullLines(rows.first, rows.last); var range;
if (rows.first === 0 || rows.last+1 < this.session.getLength())
range = new Range(rows.first, 0, rows.last+1, 0);
else
range = new Range(
rows.first-1, this.session.getLine(rows.first-1).length,
rows.last, this.session.getLine(rows.last).length
);
this.session.remove(range);
this.clearSelection(); this.clearSelection();
}; };
@ -2682,7 +2682,6 @@ config.defineOptions(Editor.prototype, "editor", {
useSoftTabs: "session", useSoftTabs: "session",
tabSize: "session", tabSize: "session",
wrap: "session", wrap: "session",
indentedSoftWrap: "session",
foldStyle: "session", foldStyle: "session",
mode: "session" mode: "session"
}); });

View file

@ -578,14 +578,15 @@ var onSelectionChange = function(evt) {
* and deleting text. * and deleting text.
* @param {!Event} evt The event. * @param {!Event} evt The event.
*/ */
var onChange = function(delta) { var onChange = function(evt) {
var data = evt.data;
switch (data.action) { switch (data.action) {
case 'remove': case 'removeText':
cvox.Api.speak(data.text, 0, DELETED_PROP); cvox.Api.speak(data.text, 0, DELETED_PROP);
/* Let the future cursor change event know it's from text change. */ /* Let the future cursor change event know it's from text change. */
changed = true; changed = true;
break; break;
case 'insert': case 'insertText':
cvox.Api.speak(data.text, 0); cvox.Api.speak(data.text, 0);
/* Let the future cursor change event know it's from text change. */ /* Let the future cursor change event know it's from text change. */
changed = true; changed = true;

View file

@ -44,12 +44,13 @@ var ElasticTabstopsLite = function(editor) {
this.onExec = function() { this.onExec = function() {
recordChanges = true; recordChanges = true;
}; };
this.onChange = function(delta) { this.onChange = function(e) {
var range = e.data.range
if (recordChanges) { if (recordChanges) {
if (changedRows.indexOf(delta.start.row) == -1) if (changedRows.indexOf(range.start.row) == -1)
changedRows.push(delta.start.row); changedRows.push(range.start.row);
if (delta.end.row != delta.start.row) if (range.end.row != range.start.row)
changedRows.push(delta.end.row); changedRows.push(range.end.row);
} }
}; };
}; };

View file

@ -393,7 +393,7 @@ exports.updateCommands = function(editor, enabled) {
}; };
exports.isSupportedMode = function(modeId) { exports.isSupportedMode = function(modeId) {
return modeId && /css|less|scss|sass|stylus|html|php|twig|ejs|handlebars/.test(modeId); return modeId && /css|less|scss|sass|stylus|html|php|twig|ejs/.test(modeId);
}; };
var onChangeMode = function(e, target) { var onChangeMode = function(e, target) {

View file

@ -62,7 +62,7 @@ function findAnnotations(session, row, dir) {
if (i < 0) if (i < 0)
i = -i - 1; i = -i - 1;
if (i >= annotations.length) if (i >= annotations.length - 1)
i = dir > 0 ? 0 : annotations.length - 1; i = dir > 0 ? 0 : annotations.length - 1;
else if (i === 0 && dir < 0) else if (i === 0 && dir < 0)
i = annotations.length - 1; i = annotations.length - 1;

View file

@ -140,7 +140,7 @@ var loadSnippetFile = function(id) {
function getCompletionPrefix(editor) { function getCompletionPrefix(editor) {
var pos = editor.getCursorPosition(); var pos = editor.getCursorPosition();
var line = editor.session.getLine(pos.row); var line = editor.session.getLine(pos.row);
var prefix; var prefix = util.retrievePrecedingIdentifier(line, pos.column);
// Try to find custom prefixes on the completers // Try to find custom prefixes on the completers
editor.completers.forEach(function(completer) { editor.completers.forEach(function(completer) {
if (completer.identifierRegexps) { if (completer.identifierRegexps) {
@ -150,13 +150,16 @@ function getCompletionPrefix(editor) {
}); });
} }
}); });
return prefix || util.retrievePrecedingIdentifier(line, pos.column); return prefix;
} }
var doLiveAutocomplete = function(e) { var doLiveAutocomplete = function(e) {
var editor = e.editor; var editor = e.editor;
var text = e.args || "";
var hasCompleter = editor.completer && editor.completer.activated; var hasCompleter = editor.completer && editor.completer.activated;
// We don't want to autocomplete with no prefix // We don't want to autocomplete with no prefix
if (e.command.name === "backspace") { if (e.command.name === "backspace") {
if (hasCompleter && !getCompletionPrefix(editor)) if (hasCompleter && !getCompletionPrefix(editor))
@ -171,6 +174,7 @@ var doLiveAutocomplete = function(e) {
editor.completer = new Autocomplete(); editor.completer = new Autocomplete();
} }
// Disable autoInsert // Disable autoInsert
editor.completer.autoSelect = false;
editor.completer.autoInsert = false; editor.completer.autoInsert = false;
editor.completer.showPopup(editor); editor.completer.showPopup(editor);
} }

View file

@ -93,7 +93,7 @@ module.exports.generateSettingsMenu = function generateSettingsMenu (editor) {
}); });
var el = topmenu.appendChild(document.createElement('div')); var el = topmenu.appendChild(document.createElement('div'));
var version = "1.1.9"; var version = "1.1.8";
el.style.padding = "1em"; el.style.padding = "1em";
el.textContent = "Ace version " + version; el.textContent = "Ace version " + version;

View file

@ -43,11 +43,10 @@ Mode.prototype.supportsFile = function(filename) {
// todo firstlinematch // todo firstlinematch
var supportedModes = { var supportedModes = {
ABAP: ["abap"], ABAP: ["abap"],
ABC: ["abc"],
ActionScript:["as"], ActionScript:["as"],
ADA: ["ada|adb"], ADA: ["ada|adb"],
Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"], Apache_Conf: ["^htaccess|^htgroups|^htpasswd|^conf|htaccess|htgroups|htpasswd"],
AsciiDoc: ["asciidoc|adoc"], AsciiDoc: ["asciidoc"],
Assembly_x86:["asm"], Assembly_x86:["asm"],
AutoHotKey: ["ahk"], AutoHotKey: ["ahk"],
BatchFile: ["bat|cmd"], BatchFile: ["bat|cmd"],
@ -99,7 +98,6 @@ var supportedModes = {
JSX: ["jsx"], JSX: ["jsx"],
Julia: ["jl"], Julia: ["jl"],
LaTeX: ["tex|latex|ltx|bib"], LaTeX: ["tex|latex|ltx|bib"],
Lean: ["lean|hlean"],
LESS: ["less"], LESS: ["less"],
Liquid: ["liquid"], Liquid: ["liquid"],
Lisp: ["lisp"], Lisp: ["lisp"],
@ -117,13 +115,12 @@ var supportedModes = {
MUSHCode: ["mc|mush"], MUSHCode: ["mc|mush"],
MySQL: ["mysql"], MySQL: ["mysql"],
Nix: ["nix"], Nix: ["nix"],
Nim: ["nim"],
ObjectiveC: ["m|mm"], ObjectiveC: ["m|mm"],
OCaml: ["ml|mli"], OCaml: ["ml|mli"],
Pascal: ["pas|p"], Pascal: ["pas|p"],
Perl: ["pl|pm"], Perl: ["pl|pm"],
pgSQL: ["pgsql"], pgSQL: ["pgsql"],
PHP: ["php|phtml|shtml|php3|php4|php5|phps|phpt|aw|ctp"], PHP: ["php|phtml"],
Powershell: ["ps1"], Powershell: ["ps1"],
Praat: ["praat|praatscript|psc|proc"], Praat: ["praat|praatscript|psc|proc"],
Prolog: ["plg|prolog"], Prolog: ["plg|prolog"],
@ -147,7 +144,6 @@ var supportedModes = {
Soy_Template:["soy"], Soy_Template:["soy"],
Space: ["space"], Space: ["space"],
SQL: ["sql"], SQL: ["sql"],
SQLServer: ["sqlserver"],
Stylus: ["styl|stylus"], Stylus: ["styl|stylus"],
SVG: ["svg"], SVG: ["svg"],
Tcl: ["tcl"], Tcl: ["tcl"],
@ -162,11 +158,9 @@ var supportedModes = {
Velocity: ["vm"], Velocity: ["vm"],
Verilog: ["v|vh|sv|svh"], Verilog: ["v|vh|sv|svh"],
VHDL: ["vhd|vhdl"], VHDL: ["vhd|vhdl"],
XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl|xaml"], XML: ["xml|rdf|rss|wsdl|xslt|atom|mathml|mml|xul|xbl"],
XQuery: ["xq"], XQuery: ["xq"],
YAML: ["yaml|yml"], YAML: ["yaml|yml"]
// Add the missing mode "Django" to ext-modelist
Django: ["html"]
}; };
var nameOverrides = { var nameOverrides = {
@ -195,3 +189,4 @@ module.exports = {
}; };
}); });

View file

@ -1,31 +1,24 @@
.ace_static_highlight { .ace_static_highlight {
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'Droid Sans Mono', monospace; font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'Droid Sans Mono', monospace;
font-size: 12px; font-size: 12px;
white-space: pre-wrap
} }
.ace_static_highlight .ace_gutter { .ace_static_highlight .ace_gutter {
width: 2em; width: 25px !important;
float: left;
text-align: right; text-align: right;
padding: 0 3px 0 0; padding: 0 3px 0 0;
margin-right: 3px; margin-right: 3px;
position: static !important;
} }
.ace_static_highlight.ace_show_gutter .ace_line { .ace_static_highlight .ace_line { clear: both; }
padding-left: 2.6em;
}
.ace_static_highlight .ace_line { position: relative; }
.ace_static_highlight .ace_gutter-cell { .ace_static_highlight .ace_gutter-cell {
-moz-user-select: -moz-none; -moz-user-select: -moz-none;
-khtml-user-select: none; -khtml-user-select: none;
-webkit-user-select: none; -webkit-user-select: none;
user-select: none; user-select: none;
top: 0;
bottom: 0;
left: 0;
position: absolute;
} }

View file

@ -37,10 +37,6 @@ var baseStyles = require("../requirejs/text!./static.css");
var config = require("../config"); var config = require("../config");
var dom = require("../lib/dom"); var dom = require("../lib/dom");
var SimpleTextLayer = function() {
this.config = {};
};
SimpleTextLayer.prototype = TextLayer.prototype;
var highlight = function(el, opts, callback) { var highlight = function(el, opts, callback) {
var m = el.className.match(/lang-(\w+)/); var m = el.className.match(/lang-(\w+)/);
@ -153,8 +149,12 @@ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
session.setUseWorker(false); session.setUseWorker(false);
session.setMode(mode); session.setMode(mode);
var textLayer = new SimpleTextLayer(); var textLayer = new TextLayer(document.createElement("div"));
textLayer.setSession(session); textLayer.setSession(session);
textLayer.config = {
characterWidth: 10,
lineHeight: 20
};
session.setValue(input); session.setValue(input);
@ -171,8 +171,7 @@ highlight.renderSync = function(input, mode, theme, lineStart, disableGutter) {
// let's prepare the whole html // let's prepare the whole html
var html = "<div class='" + theme.cssClass + "'>" + var html = "<div class='" + theme.cssClass + "'>" +
"<div class='ace_static_highlight" + (disableGutter ? "" : " ace_show_gutter") + "<div class='ace_static_highlight' style='counter-reset:ace_line " + (lineStart - 1) + "'>" +
"' style='counter-reset:ace_line " + (lineStart - 1) + "'>" +
stringBuilder.join("") + stringBuilder.join("") +
"</div>" + "</div>" +
"</div>"; "</div>";

View file

@ -28,12 +28,12 @@ module.exports = {
var mode = new JavaScriptMode(); var mode = new JavaScriptMode();
var result = highlighter.render(snippet, mode, theme); var result = highlighter.render(snippet, mode, theme);
assert.equal(result.html, "<div class='ace-tomorrow'><div class='ace_static_highlight ace_show_gutter' style='counter-reset:ace_line 0'>" assert.equal(result.html, "<div class='ace-tomorrow'><div class='ace_static_highlight' style='counter-reset:ace_line 0'>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_comment ace_doc'>/** this is a function</span>\n</div>" + "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_comment ace_doc'>/**\xa0this\xa0is\xa0a\xa0function</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_comment ace_doc'>*</span>\n</div>" + "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_comment ace_doc'>*</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_comment ace_doc'>*/</span>\n</div>" + "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_comment ace_doc'>*/</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_storage ace_type'>function</span> <span class='ace_entity ace_name ace_function'>hello</span> <span class='ace_paren ace_lparen'>(</span><span class='ace_variable ace_parameter'>a</span><span class='ace_punctuation ace_operator'>, </span><span class='ace_variable ace_parameter'>b</span><span class='ace_punctuation ace_operator'>, </span><span class='ace_variable ace_parameter'>c</span><span class='ace_paren ace_rparen'>)</span> <span class='ace_paren ace_lparen'>{</span>\n</div>" + "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_storage ace_type'>function</span>\xa0<span class='ace_entity ace_name ace_function'>hello</span>\xa0<span class='ace_paren ace_lparen'>(</span><span class='ace_variable ace_parameter'>a</span><span class='ace_punctuation ace_operator'>,\xa0</span><span class='ace_variable ace_parameter'>b</span><span class='ace_punctuation ace_operator'>,\xa0</span><span class='ace_variable ace_parameter'>c</span><span class='ace_paren ace_rparen'>)</span>\xa0<span class='ace_paren ace_lparen'>{</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span> <span class='ace_storage ace_type'>console</span><span class='ace_punctuation ace_operator'>.</span><span class='ace_support ace_function ace_firebug'>log</span><span class='ace_paren ace_lparen'>(</span><span class='ace_identifier'>a</span> <span class='ace_keyword ace_operator'>*</span> <span class='ace_identifier'>b</span> <span class='ace_keyword ace_operator'>+</span> <span class='ace_identifier'>c</span> <span class='ace_keyword ace_operator'>+</span> <span class='ace_string'>'sup$'</span><span class='ace_paren ace_rparen'>)</span><span class='ace_punctuation ace_operator'>;</span>\n</div>" + "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span>\xa0\xa0\xa0\xa0<span class='ace_storage ace_type'>console</span><span class='ace_punctuation ace_operator'>.</span><span class='ace_support ace_function ace_firebug'>log</span><span class='ace_paren ace_lparen'>(</span><span class='ace_identifier'>a</span>\xa0<span class='ace_keyword ace_operator'>*</span>\xa0<span class='ace_identifier'>b</span>\xa0<span class='ace_keyword ace_operator'>+</span>\xa0<span class='ace_identifier'>c</span>\xa0<span class='ace_keyword ace_operator'>+</span>\xa0<span class='ace_string'>'sup$'</span><span class='ace_paren ace_rparen'>)</span><span class='ace_punctuation ace_operator'>;</span>\n</div>"
+ "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_paren ace_rparen'>}</span>\n</div>" + "<div class='ace_line'><span class='ace_gutter ace_gutter-cell' unselectable='on'></span><span class='ace_paren ace_rparen'>}</span>\n</div>"
+ "</div></div>"); + "</div></div>");
assert.ok(!!result.css); assert.ok(!!result.css);

View file

@ -51,14 +51,12 @@ var themeData = [
["Dreamweaver" ], ["Dreamweaver" ],
["Eclipse" ], ["Eclipse" ],
["GitHub" ], ["GitHub" ],
["IPlastic" ],
["Solarized Light"], ["Solarized Light"],
["TextMate" ], ["TextMate" ],
["Tomorrow" ], ["Tomorrow" ],
["XCode" ], ["XCode" ],
["Kuroir"], ["Kuroir"],
["KatzenMilch"], ["KatzenMilch"],
["SQL Server" ,"sqlserver" , "light"],
["Ambiance" ,"ambiance" , "dark"], ["Ambiance" ,"ambiance" , "dark"],
["Chaos" ,"chaos" , "dark"], ["Chaos" ,"chaos" , "dark"],
["Clouds Midnight" ,"clouds_midnight" , "dark"], ["Clouds Midnight" ,"clouds_midnight" , "dark"],
@ -73,7 +71,6 @@ var themeData = [
["Solarized Dark" ,"solarized_dark" , "dark"], ["Solarized Dark" ,"solarized_dark" , "dark"],
["Terminal" ,"terminal" , "dark"], ["Terminal" ,"terminal" , "dark"],
["Tomorrow Night" ,"tomorrow_night" , "dark"], ["Tomorrow Night" ,"tomorrow_night" , "dark"],
["The Night After Tomorrow" ,"the_night_after_tomorrow" , "dark"],
["Tomorrow Night Blue" ,"tomorrow_night_blue" , "dark"], ["Tomorrow Night Blue" ,"tomorrow_night_blue" , "dark"],
["Tomorrow Night Bright","tomorrow_night_bright" , "dark"], ["Tomorrow Night Bright","tomorrow_night_bright" , "dark"],
["Tomorrow Night 80s" ,"tomorrow_night_eighties" , "dark"], ["Tomorrow Night 80s" ,"tomorrow_night_eighties" , "dark"],

View file

@ -105,7 +105,7 @@ function objectToRegExp(obj) {
this.$mousedownHandler = ed.addEventListener('mousedown', this.onMouseDown.bind(this)); this.$mousedownHandler = ed.addEventListener('mousedown', this.onMouseDown.bind(this));
this.selectionFix(ed); this.selectionFix(ed);
this.statusMessage(true); this.statusMessage(true);
}; }
this.deactivate = function(reset) { this.deactivate = function(reset) {
this.cancelSearch(reset); this.cancelSearch(reset);
@ -117,7 +117,7 @@ function objectToRegExp(obj) {
} }
ed.onPaste = this.$originalEditorOnPaste; ed.onPaste = this.$originalEditorOnPaste;
this.message(''); this.message('');
}; }
this.selectionFix = function(editor) { this.selectionFix = function(editor) {
// Fix selection bug: When clicked inside the editor // Fix selection bug: When clicked inside the editor
@ -128,7 +128,7 @@ function objectToRegExp(obj) {
if (editor.selection.isEmpty() && !editor.session.$emacsMark) { if (editor.selection.isEmpty() && !editor.session.$emacsMark) {
editor.clearSelection(); editor.clearSelection();
} }
}; }
this.highlight = function(regexp) { this.highlight = function(regexp) {
var sess = this.$editor.session, var sess = this.$editor.session,
@ -136,7 +136,7 @@ function objectToRegExp(obj) {
new SearchHighlight(null, "ace_isearch-result", "text")); new SearchHighlight(null, "ace_isearch-result", "text"));
hl.setRegexp(regexp); hl.setRegexp(regexp);
sess._emit("changeBackMarker"); // force highlight layer redraw sess._emit("changeBackMarker"); // force highlight layer redraw
}; }
this.cancelSearch = function(reset) { this.cancelSearch = function(reset) {
var e = this.$editor; var e = this.$editor;
@ -150,7 +150,7 @@ function objectToRegExp(obj) {
} }
this.highlight(null); this.highlight(null);
return Range.fromPoints(this.$currentPos, this.$currentPos); return Range.fromPoints(this.$currentPos, this.$currentPos);
}; }
this.highlightAndFindWithNeedle = function(moveToNext, needleUpdateFunc) { this.highlightAndFindWithNeedle = function(moveToNext, needleUpdateFunc) {
if (!this.$editor) return null; if (!this.$editor) return null;
@ -163,7 +163,7 @@ function objectToRegExp(obj) {
if (options.needle.length === 0) { if (options.needle.length === 0) {
this.statusMessage(true); this.statusMessage(true);
return this.cancelSearch(true); return this.cancelSearch(true);
} };
// try to find the next occurence and enable highlighting marker // try to find the next occurence and enable highlighting marker
options.start = this.$currentPos; options.start = this.$currentPos;
@ -176,13 +176,13 @@ function objectToRegExp(obj) {
this.$editor.selection.setRange(Range.fromPoints(shouldSelect ? this.$startPos : found.end, found.end)); this.$editor.selection.setRange(Range.fromPoints(shouldSelect ? this.$startPos : found.end, found.end));
if (moveToNext) this.$currentPos = found.end; if (moveToNext) this.$currentPos = found.end;
// highlight after cursor move, so selection works properly // highlight after cursor move, so selection works properly
this.highlight(options.re); this.highlight(options.re)
} }
this.statusMessage(found); this.statusMessage(found);
return found; return found;
}; }
this.addString = function(s) { this.addString = function(s) {
return this.highlightAndFindWithNeedle(false, function(needle) { return this.highlightAndFindWithNeedle(false, function(needle) {
@ -192,7 +192,7 @@ function objectToRegExp(obj) {
reObj.expression += s; reObj.expression += s;
return objectToRegExp(reObj); return objectToRegExp(reObj);
}); });
}; }
this.removeChar = function(c) { this.removeChar = function(c) {
return this.highlightAndFindWithNeedle(false, function(needle) { return this.highlightAndFindWithNeedle(false, function(needle) {
@ -202,7 +202,7 @@ function objectToRegExp(obj) {
reObj.expression = reObj.expression.substring(0, reObj.expression.length-1); reObj.expression = reObj.expression.substring(0, reObj.expression.length-1);
return objectToRegExp(reObj); return objectToRegExp(reObj);
}); });
}; }
this.next = function(options) { this.next = function(options) {
// try to find the next occurence of whatever we have searched for // try to find the next occurence of whatever we have searched for
@ -215,29 +215,29 @@ function objectToRegExp(obj) {
return options.useCurrentOrPrevSearch && needle.length === 0 ? return options.useCurrentOrPrevSearch && needle.length === 0 ?
this.$prevNeedle || '' : needle; this.$prevNeedle || '' : needle;
}); });
}; }
this.onMouseDown = function(evt) { this.onMouseDown = function(evt) {
// when mouse interaction happens then we quit incremental search // when mouse interaction happens then we quit incremental search
this.deactivate(); this.deactivate();
return true; return true;
}; }
this.onPaste = function(text) { this.onPaste = function(text) {
this.addString(text); this.addString(text);
}; }
this.convertNeedleToRegExp = function() { this.convertNeedleToRegExp = function() {
return this.highlightAndFindWithNeedle(false, function(needle) { return this.highlightAndFindWithNeedle(false, function(needle) {
return isRegExp(needle) ? needle : stringToRegExp(needle, 'ig'); return isRegExp(needle) ? needle : stringToRegExp(needle, 'ig');
}); });
}; }
this.convertNeedleToString = function() { this.convertNeedleToString = function() {
return this.highlightAndFindWithNeedle(false, function(needle) { return this.highlightAndFindWithNeedle(false, function(needle) {
return isRegExp(needle) ? regExpToObject(needle).expression : needle; return isRegExp(needle) ? regExpToObject(needle).expression : needle;
}); });
}; }
this.statusMessage = function(found) { this.statusMessage = function(found) {
var options = this.$options, msg = ''; var options = this.$options, msg = '';
@ -245,7 +245,7 @@ function objectToRegExp(obj) {
msg += 'isearch: ' + options.needle; msg += 'isearch: ' + options.needle;
msg += found ? '' : ' (not found)'; msg += found ? '' : ' (not found)';
this.message(msg); this.message(msg);
}; }
this.message = function(msg) { this.message = function(msg) {
if (this.$editor.showCommandLine) { if (this.$editor.showCommandLine) {
@ -254,7 +254,7 @@ function objectToRegExp(obj) {
} else { } else {
console.log(msg); console.log(msg);
} }
}; }
}).call(IncrementalSearch.prototype); }).call(IncrementalSearch.prototype);

View file

@ -428,7 +428,7 @@ exports.emacsKeys = {
"M-;": "togglecomment", "M-;": "togglecomment",
"C-/|C-x u|S-C--|C-z": "undo", "C-/|C-x u|S-C--|C-z": "undo",
"S-C-/|S-C-x u|C--|S-C-z": "redo", // infinite undo? "S-C-/|S-C-x u|C--|S-C-z": "redo", //infinite undo?
// vertical editing // vertical editing
"C-x r": "selectRectangularRegion", "C-x r": "selectRectangularRegion",
"M-x": {command: "focusCommandLine", args: "M-x "} "M-x": {command: "focusCommandLine", args: "M-x "}
@ -483,7 +483,7 @@ exports.handler.addCommands({
// different. Deactivate the mark when setMark is run with active // different. Deactivate the mark when setMark is run with active
// mark // mark
if (transientMarkModeActive && (mark || !hasNoSelection)) { if (transientMarkModeActive && (mark || !hasNoSelection)) {
if (editor.inMultiSelectMode) editor.forEachSelection({exec: editor.clearSelection.bind(editor)}); if (editor.inMultiSelectMode) editor.forEachSelection({exec: editor.clearSelection.bind(editor)})
else editor.clearSelection(); else editor.clearSelection();
if (mark) editor.pushEmacsMark(null); if (mark) editor.pushEmacsMark(null);
return; return;

View file

@ -87,12 +87,9 @@ MultiHashHandler.prototype = HashHandler.prototype;
} }
}; };
this.bindKey = function(key, command, position) { this.bindKey = function(key, command, asDefault) {
if (typeof key == "object") { if (typeof key == "object")
if (position == undefined)
position = key.position;
key = key[this.platform]; key = key[this.platform];
}
if (!key) if (!key)
return; return;
if (typeof command == "function") if (typeof command == "function")
@ -113,15 +110,11 @@ MultiHashHandler.prototype = HashHandler.prototype;
} }
var binding = this.parseKeys(keyPart); var binding = this.parseKeys(keyPart);
var id = KEY_MODS[binding.hashId] + binding.key; var id = KEY_MODS[binding.hashId] + binding.key;
this._addCommandToBinding(chain + id, command, position); this._addCommandToBinding(chain + id, command, asDefault);
}, this); }, this);
}; };
function getPosition(command) { this._addCommandToBinding = function(keyId, command, asDefault) {
return typeof command == "object" && command.bindKey
&& command.bindKey.position || 0;
}
this._addCommandToBinding = function(keyId, command, position) {
var ckb = this.commandKeyBinding, i; var ckb = this.commandKeyBinding, i;
if (!command) { if (!command) {
delete ckb[keyId]; delete ckb[keyId];
@ -133,21 +126,11 @@ MultiHashHandler.prototype = HashHandler.prototype;
} else if ((i = ckb[keyId].indexOf(command)) != -1) { } else if ((i = ckb[keyId].indexOf(command)) != -1) {
ckb[keyId].splice(i, 1); ckb[keyId].splice(i, 1);
} }
if (typeof position != "number") { if (asDefault || command.isDefault)
if (position || command.isDefault) ckb[keyId].unshift(command);
position = -100; else
else ckb[keyId].push(command);
position = getPosition(command);
}
var commands = ckb[keyId];
for (i = 0; i < commands.length; i++) {
var other = commands[i];
var otherPos = getPosition(other);
if (otherPos > position)
break;
}
commands.splice(i, 0, command);
} }
}; };
@ -236,18 +219,10 @@ MultiHashHandler.prototype = HashHandler.prototype;
} }
} }
if (data.$keyChain) { if (data.$keyChain && keyCode > 0)
if ((!hashId || hashId == 4) && keyString.length == 1) data.$keyChain = "";
data.$keyChain = data.$keyChain.slice(0, -key.length - 1); // wait for input
else if (hashId == -1 || keyCode > 0)
data.$keyChain = ""; // reset keyChain
}
return {command: command}; return {command: command};
}; };
this.getStatusText = function(editor, data) {
return data.$keyChain || "";
};
}).call(HashHandler.prototype); }).call(HashHandler.prototype);

View file

@ -51,7 +51,7 @@ var TextInput = function(parentNode, host) {
text.setAttribute("spellcheck", false); text.setAttribute("spellcheck", false);
text.style.opacity = "0"; text.style.opacity = "0";
if (useragent.isOldIE) text.style.top = "-1000px"; if (useragent.isOldIE) text.style.top = "-100px";
parentNode.insertBefore(text, parentNode.firstChild); parentNode.insertBefore(text, parentNode.firstChild);
var PLACEHOLDER = "\x01\x01"; var PLACEHOLDER = "\x01\x01";
@ -76,9 +76,8 @@ var TextInput = function(parentNode, host) {
resetSelection(); resetSelection();
}); });
this.focus = function() { this.focus = function() {
if (tempStyle) return text.focus();
text.style.position = "fixed"; text.style.position = "fixed";
text.style.top = "-1000px"; text.style.top = "-10000000px";
text.focus(); text.focus();
setTimeout(function() { setTimeout(function() {
text.style.position = ""; text.style.position = "";
@ -306,7 +305,7 @@ var TextInput = function(parentNode, host) {
var data = handleClipboardData(e); var data = handleClipboardData(e);
if (typeof data == "string") { if (typeof data == "string") {
if (data) if (data)
host.onPaste(data, e); host.onPaste(data);
if (useragent.isIE) if (useragent.isIE)
setTimeout(resetSelection); setTimeout(resetSelection);
event.preventDefault(e); event.preventDefault(e);

View file

@ -66,25 +66,23 @@ define(function(require, exports, module) {
var d = ""; var d = "";
function format(p) { function format(p) {
if (typeof p != "object") if (typeof p != "object")
return p + ""; return p + ""
if ("line" in p) { if ("line" in p) {
return p.line + ":" + p.ch; return p.line + ":" + p.ch
} }
if ("anchor" in p) { if ("anchor" in p) {
return format(p.anchor) + "->" + format(p.head); return format(p.anchor) + "->" + format(p.head)
} }
if (Array.isArray(p)) if (Array.isArray(p))
return "[" + p.map(function(x) { return "[" + p.map(function(x) {return format(x)})+"]"
return format(x); return JSON.stringify(p)
}) + "]";
return JSON.stringify(p);
} }
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
var p = arguments[i]; var p = arguments[i]
var f = format(p); var f = format(p)
d += f + " "; d+= f+" "
} }
console.log(d); console.log(d)
} }
var Range = require("../range").Range; var Range = require("../range").Range;
var EventEmitter = require("../lib/event_emitter").EventEmitter; var EventEmitter = require("../lib/event_emitter").EventEmitter;
@ -96,7 +94,6 @@ define(function(require, exports, module) {
var useragent = require("../lib/useragent"); var useragent = require("../lib/useragent");
var SearchHighlight = require("../search_highlight").SearchHighlight; var SearchHighlight = require("../search_highlight").SearchHighlight;
var multiSelectCommands = require("../commands/multi_select_commands"); var multiSelectCommands = require("../commands/multi_select_commands");
var TextModeTokenRe = require("../mode/text").Mode.prototype.tokenRe;
require("../multi_select"); require("../multi_select");
var CodeMirror = function(ace) { var CodeMirror = function(ace) {
@ -160,11 +157,6 @@ define(function(require, exports, module) {
CodeMirror.signal = function(o, name, e) { return o._signal(name, e) }; CodeMirror.signal = function(o, name, e) { return o._signal(name, e) };
CodeMirror.on = event.addListener; CodeMirror.on = event.addListener;
CodeMirror.off = event.removeListener; CodeMirror.off = event.removeListener;
CodeMirror.isWordChar = function(ch) {
TextModeTokenRe.lastIndex = 0;
return TextModeTokenRe.test(ch);
};
(function() { (function() {
oop.implement(CodeMirror.prototype, EventEmitter); oop.implement(CodeMirror.prototype, EventEmitter);
@ -178,6 +170,13 @@ define(function(require, exports, module) {
return this.ace.inVirtualSelectionMode && this.ace.selection.index; return this.ace.inVirtualSelectionMode && this.ace.selection.index;
}; };
this.onChange = function(delta) { this.onChange = function(delta) {
var oldDelta = delta.data;
delta = {
start: oldDelta.range.start,
end: oldDelta.range.end,
action: oldDelta.action,
lines: oldDelta.lines || [oldDelta.text]
};// v1.2 api compatibility
if (delta.action[0] == 'i') { if (delta.action[0] == 'i') {
var change = { text: delta.lines }; var change = { text: delta.lines };
var curOp = this.curOp = this.curOp || {}; var curOp = this.curOp = this.curOp || {};
@ -257,7 +256,6 @@ define(function(require, exports, module) {
} }
if (!this.ace.inVirtualSelectionMode) if (!this.ace.inVirtualSelectionMode)
this.ace.exitMultiSelectMode(); this.ace.exitMultiSelectMode();
this.ace.session.unfold({row: line, column: ch});
this.ace.selection.moveTo(line, ch); this.ace.selection.moveTo(line, ch);
}; };
this.getCursor = function(p) { this.getCursor = function(p) {
@ -385,19 +383,13 @@ define(function(require, exports, module) {
sel.moveCursorBy(0, increment); sel.moveCursorBy(0, increment);
} }
}; };
this.findPosV = function(start, amount, unit, goalColumn) { this.findPosV = function(start, amaount, unit, goalColumn) {
if (unit == 'page') {
var renderer = this.ace.renderer;
var config = renderer.layerConfig;
amount = amount * Math.floor(config.height / config.lineHeight);
unit = 'line';
}
if (unit == 'line') { if (unit == 'line') {
var screenPos = this.ace.session.documentToScreenPosition(start.line, start.ch); var screenPos = this.ace.session.documentToScreenPosition(start.line, start.ch);
if (goalColumn != null) if (goalColumn != null)
screenPos.column = goalColumn; screenPos.column = goalColumn;
screenPos.row += amount; screenPos.row += amaount;
// not what codemirror does but vim mode needs only this // not what codemirror does but vim mode needs only it
screenPos.row = Math.min(Math.max(0, screenPos.row), this.ace.session.getScreenLength() - 1); screenPos.row = Math.min(Math.max(0, screenPos.row), this.ace.session.getScreenLength() - 1);
var pos = this.ace.session.screenToDocumentPosition(screenPos.row, screenPos.column); var pos = this.ace.session.screenToDocumentPosition(screenPos.row, screenPos.column);
return toCmPos(pos); return toCmPos(pos);
@ -483,12 +475,8 @@ define(function(require, exports, module) {
}; };
this.scrollInfo = function() { return 0; }; this.scrollInfo = function() { return 0; };
this.scrollIntoView = function(pos, margin) { this.scrollIntoView = function(pos, margin) {
if (pos) { if (pos)
var renderer = this.ace.renderer; this.ace.renderer.scrollCursorIntoView(toAcePos(pos), null, margin);
var viewMargin = { "top": 0, "bottom": margin };
renderer.scrollCursorIntoView(toAcePos(pos),
(renderer.lineHeight * 2) / renderer.$size.scrollerHeight, viewMargin);
}
}; };
this.getLine = function(row) { return this.ace.session.getLine(row) }; this.getLine = function(row) { return this.ace.session.getLine(row) };
this.getRange = function(s, e) { this.getRange = function(s, e) {
@ -571,6 +559,7 @@ define(function(require, exports, module) {
highlight.session = null; highlight.session = null;
}; };
highlight.updateOnChange = function(delta) { highlight.updateOnChange = function(delta) {
delta = delta.data.range;// v1.2 api compatibility
var row = delta.start.row; var row = delta.start.row;
if (row == delta.end.row) highlight.cache[row] = undefined; if (row == delta.end.row) highlight.cache[row] = undefined;
else highlight.cache.splice(row, highlight.cache.length); else highlight.cache.splice(row, highlight.cache.length);
@ -647,9 +636,6 @@ define(function(require, exports, module) {
this.refresh = function() { this.refresh = function() {
return this.ace.resize(true); return this.ace.resize(true);
}; };
this.getMode = function() {
return { name : this.getOption("mode") };
}
}).call(CodeMirror.prototype); }).call(CodeMirror.prototype);
function toAcePos(cmPos) { function toAcePos(cmPos) {
return {row: cmPos.line, column: cmPos.ch}; return {row: cmPos.line, column: cmPos.ch};
@ -730,14 +716,10 @@ CodeMirror.defineExtension = function(name, fn) {
CodeMirror.prototype[name] = fn; CodeMirror.prototype[name] = fn;
}; };
dom.importCssString(".normal-mode .ace_cursor{\ dom.importCssString(".normal-mode .ace_cursor{\
border: 1px solid red;\ border: 0!important;\
background-color: red;\ background-color: red;\
opacity: 0.5;\ opacity: 0.5;\
}\ }.ace_dialog {\
.normal-mode .ace_hidden-cursors .ace_cursor{\
background-color: transparent;\
}\
.ace_dialog {\
position: absolute;\ position: absolute;\
left: 0; right: 0;\ left: 0; right: 0;\
background: white;\ background: white;\
@ -763,6 +745,23 @@ dom.importCssString(".normal-mode .ace_cursor{\
font-family: monospace;\ font-family: monospace;\
}", "vimMode"); }", "vimMode");
(function() { (function() {
function dialogDiv(cm, template, bottom) {
var wrap = cm.ace.container;
var dialog;
dialog = wrap.appendChild(document.createElement("div"));
if (bottom)
dialog.className = "ace_dialog ace_dialog-bottom";
else
dialog.className = "ace_dialog ace_dialog-top";
if (typeof template == "string") {
dialog.innerHTML = template;
} else { // Assuming it's a detached DOM element.
dialog.appendChild(template);
}
return dialog;
}
function closeNotification(cm, newVal) { function closeNotification(cm, newVal) {
if (cm.state.currentNotificationClose) if (cm.state.currentNotificationClose)
cm.state.currentNotificationClose(); cm.state.currentNotificationClose();
@ -794,7 +793,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
if (inp) { if (inp) {
if (options.value) { if (options.value) {
inp.value = options.value; inp.value = options.value;
if (options.select !== false) inp.select(); inp.select();
} }
if (options.onInput) if (options.onInput)
@ -1122,11 +1121,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
var numberRegex = /[\d]/; var numberRegex = /[\d]/;
var wordCharTest = [CodeMirror.isWordChar, function(ch) { var wordRegexp = [(/\w/), (/[^\w\s]/)], bigWordRegexp = [(/\S/)];
return ch && !CodeMirror.isWordChar(ch) && !/\s/.test(ch);
}], bigWordCharTest = [function(ch) {
return /\S/.test(ch);
}];
function makeKeyRange(start, size) { function makeKeyRange(start, size) {
var keys = []; var keys = [];
for (var i = start; i < start + size; i++) { for (var i = start; i < start + size; i++) {
@ -1168,30 +1163,18 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
var options = {}; var options = {};
function defineOption(name, defaultValue, type, aliases, callback) { function defineOption(name, defaultValue, type) {
if (defaultValue === undefined && !callback) { if (defaultValue === undefined) { throw Error('defaultValue is required'); }
throw Error('defaultValue is required unless callback is provided');
}
if (!type) { type = 'string'; } if (!type) { type = 'string'; }
options[name] = { options[name] = {
type: type, type: type,
defaultValue: defaultValue, defaultValue: defaultValue
callback: callback
}; };
if (aliases) { setOption(name, defaultValue);
for (var i = 0; i < aliases.length; i++) {
options[aliases[i]] = options[name];
}
}
if (defaultValue) {
setOption(name, defaultValue);
}
} }
function setOption(name, value, cm, cfg) { function setOption(name, value, cm) {
var option = options[name]; var option = options[name];
cfg = cfg || {};
var scope = cfg.scope;
if (!option) { if (!option) {
throw Error('Unknown option: ' + name); throw Error('Unknown option: ' + name);
} }
@ -1203,60 +1186,17 @@ dom.importCssString(".normal-mode .ace_cursor{\
value = true; value = true;
} }
} }
if (option.callback) { option.value = option.type == 'boolean' ? !!value : value;
if (scope !== 'local') {
option.callback(value, undefined);
}
if (scope !== 'global' && cm) {
option.callback(value, cm);
}
} else {
if (scope !== 'local') {
option.value = option.type == 'boolean' ? !!value : value;
}
if (scope !== 'global' && cm) {
cm.state.vim.options[name] = {value: value};
}
}
} }
function getOption(name, cm, cfg) { function getOption(name) {
var option = options[name]; var option = options[name];
cfg = cfg || {};
var scope = cfg.scope;
if (!option) { if (!option) {
throw Error('Unknown option: ' + name); throw Error('Unknown option: ' + name);
} }
if (option.callback) { return option.value;
var local = cm && option.callback(undefined, cm);
if (scope !== 'global' && local !== undefined) {
return local;
}
if (scope !== 'local') {
return option.callback();
}
return;
} else {
var local = (scope !== 'global') && (cm && cm.state.vim.options[name]);
return (local || (scope !== 'local') && option || {}).value;
}
} }
defineOption('filetype', undefined, 'string', ['ft'], function(name, cm) {
// Option is local. Do nothing for global.
if (cm === undefined) {
return;
}
// The 'filetype' option proxies to the CodeMirror 'mode' option.
if (name === undefined) {
var mode = cm.getMode().name;
return mode == 'null' ? '' : mode;
} else {
var mode = name == '' ? 'null' : name;
cm.setOption('mode', mode);
}
});
var createCircularJumpList = function() { var createCircularJumpList = function() {
var size = 100; var size = 100;
var pointer = -1; var pointer = -1;
@ -1409,9 +1349,8 @@ dom.importCssString(".normal-mode .ace_cursor{\
visualBlock: false, visualBlock: false,
lastSelection: null, lastSelection: null,
lastPastedText: null, lastPastedText: null,
sel: {}, sel: {
// Buffer-local/window-local values of vim options. }
options: {}
}; };
} }
return cm.state.vim; return cm.state.vim;
@ -1462,8 +1401,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
// Testing hook. // Testing hook.
maybeInitVimState_: maybeInitVimState, maybeInitVimState_: maybeInitVimState,
suppressErrorLogging: false,
InsertModeKey: InsertModeKey, InsertModeKey: InsertModeKey,
map: function(lhs, rhs, ctx) { map: function(lhs, rhs, ctx) {
// Add user defined key bindings. // Add user defined key bindings.
@ -1473,8 +1410,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
// remove user defined key bindings. // remove user defined key bindings.
exCommandDispatcher.unmap(lhs, ctx); exCommandDispatcher.unmap(lhs, ctx);
}, },
// TODO: Expose setOption and getOption as instance methods. Need to decide how to namespace
// them, or somehow make them work with the existing CodeMirror setOption/getOption API.
setOption: setOption, setOption: setOption,
getOption: getOption, getOption: getOption,
defineOption: defineOption, defineOption: defineOption,
@ -1616,9 +1551,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
// clear VIM state in case it's in a bad state. // clear VIM state in case it's in a bad state.
cm.state.vim = undefined; cm.state.vim = undefined;
maybeInitVimState(cm); maybeInitVimState(cm);
if (!CodeMirror.Vim.suppressErrorLogging) { console['log'](e);
console['log'](e);
}
throw e; throw e;
} }
return true; return true;
@ -1628,16 +1561,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
}, },
handleEx: function(cm, input) { handleEx: function(cm, input) {
exCommandDispatcher.processCommand(cm, input); exCommandDispatcher.processCommand(cm, input);
}, }
defineMotion: defineMotion,
defineAction: defineAction,
defineOperator: defineOperator,
mapCommand: mapCommand,
_mapCommand: _mapCommand,
exitVisualMode: exitVisualMode,
exitInsertMode: exitInsertMode
}; };
// Represents the current input state. // Represents the current input state.
@ -1887,10 +1811,12 @@ dom.importCssString(".normal-mode .ace_cursor{\
break; break;
case 'search': case 'search':
this.processSearch(cm, vim, command); this.processSearch(cm, vim, command);
clearInputState(cm);
break; break;
case 'ex': case 'ex':
case 'keyToEx': case 'keyToEx':
this.processEx(cm, vim, command); this.processEx(cm, vim, command);
clearInputState(cm);
break; break;
default: default:
break; break;
@ -1983,7 +1909,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
updateSearchQuery(cm, query, ignoreCase, smartCase); updateSearchQuery(cm, query, ignoreCase, smartCase);
} catch (e) { } catch (e) {
showConfirm(cm, 'Invalid regex: ' + query); showConfirm(cm, 'Invalid regex: ' + query);
clearInputState(cm);
return; return;
} }
commandDispatcher.processMotion(cm, vim, { commandDispatcher.processMotion(cm, vim, {
@ -2026,21 +1951,15 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
function onPromptKeyDown(e, query, close) { function onPromptKeyDown(e, query, close) {
var keyName = CodeMirror.keyName(e); var keyName = CodeMirror.keyName(e);
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' || if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[') {
(keyName == 'Backspace' && query == '')) {
vimGlobalState.searchHistoryController.pushInput(query); vimGlobalState.searchHistoryController.pushInput(query);
vimGlobalState.searchHistoryController.reset(); vimGlobalState.searchHistoryController.reset();
updateSearchQuery(cm, originalQuery); updateSearchQuery(cm, originalQuery);
clearSearchHighlight(cm); clearSearchHighlight(cm);
cm.scrollTo(originalScrollPos.left, originalScrollPos.top); cm.scrollTo(originalScrollPos.left, originalScrollPos.top);
CodeMirror.e_stop(e); CodeMirror.e_stop(e);
clearInputState(cm);
close(); close();
cm.focus(); cm.focus();
} else if (keyName == 'Ctrl-U') {
// Ctrl-U clears input.
CodeMirror.e_stop(e);
close('');
} }
} }
switch (command.searchArgs.querySrc) { switch (command.searchArgs.querySrc) {
@ -2101,12 +2020,10 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
function onPromptKeyDown(e, input, close) { function onPromptKeyDown(e, input, close) {
var keyName = CodeMirror.keyName(e), up; var keyName = CodeMirror.keyName(e), up;
if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[' || if (keyName == 'Esc' || keyName == 'Ctrl-C' || keyName == 'Ctrl-[') {
(keyName == 'Backspace' && input == '')) {
vimGlobalState.exCommandHistoryController.pushInput(input); vimGlobalState.exCommandHistoryController.pushInput(input);
vimGlobalState.exCommandHistoryController.reset(); vimGlobalState.exCommandHistoryController.reset();
CodeMirror.e_stop(e); CodeMirror.e_stop(e);
clearInputState(cm);
close(); close();
cm.focus(); cm.focus();
} }
@ -2114,10 +2031,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
up = keyName == 'Up' ? true : false; up = keyName == 'Up' ? true : false;
input = vimGlobalState.exCommandHistoryController.nextMatch(input, up) || ''; input = vimGlobalState.exCommandHistoryController.nextMatch(input, up) || '';
close(input); close(input);
} else if (keyName == 'Ctrl-U') {
// Ctrl-U clears input.
CodeMirror.e_stop(e);
close('');
} else { } else {
if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift') if ( keyName != 'Left' && keyName != 'Right' && keyName != 'Ctrl' && keyName != 'Alt' && keyName != 'Shift')
vimGlobalState.exCommandHistoryController.reset(); vimGlobalState.exCommandHistoryController.reset();
@ -2129,7 +2042,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
} else { } else {
if (vim.visualMode) { if (vim.visualMode) {
showPrompt(cm, { onClose: onPromptClose, prefix: ':', value: '\'<,\'>', showPrompt(cm, { onClose: onPromptClose, prefix: ':', value: '\'<,\'>',
onKeyDown: onPromptKeyDown, select: false}); onKeyDown: onPromptKeyDown});
} else { } else {
showPrompt(cm, { onClose: onPromptClose, prefix: ':', showPrompt(cm, { onClose: onPromptClose, prefix: ':',
onKeyDown: onPromptKeyDown}); onKeyDown: onPromptKeyDown});
@ -2147,8 +2060,8 @@ dom.importCssString(".normal-mode .ace_cursor{\
var registerName = inputState.registerName; var registerName = inputState.registerName;
var sel = vim.sel; var sel = vim.sel;
// TODO: Make sure cm and vim selections are identical outside visual mode. // TODO: Make sure cm and vim selections are identical outside visual mode.
var origHead = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.head): cm.getCursor('head')); var origHead = copyCursor(vim.visualMode ? sel.head: cm.getCursor('head'));
var origAnchor = copyCursor(vim.visualMode ? clipCursorToContent(cm, sel.anchor) : cm.getCursor('anchor')); var origAnchor = copyCursor(vim.visualMode ? sel.anchor : cm.getCursor('anchor'));
var oldHead = copyCursor(origHead); var oldHead = copyCursor(origHead);
var oldAnchor = copyCursor(origAnchor); var oldAnchor = copyCursor(origAnchor);
var newHead, newAnchor; var newHead, newAnchor;
@ -2184,8 +2097,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
return; return;
} }
if (motionArgs.toJumplist) { if (motionArgs.toJumplist) {
if (!operator)
cm.ace.curOp.command.scrollIntoView = "center-animate"; // ace patch
var jumpList = vimGlobalState.jumpList; var jumpList = vimGlobalState.jumpList;
// if the current motion is # or *, use cachedCursor // if the current motion is # or *, use cachedCursor
var cachedCursor = jumpList.cachedCursor; var cachedCursor = jumpList.cachedCursor;
@ -2207,9 +2118,11 @@ dom.importCssString(".normal-mode .ace_cursor{\
newHead = copyCursor(origHead); newHead = copyCursor(origHead);
} }
if (vim.visualMode) { if (vim.visualMode) {
if (!(vim.visualBlock && newHead.ch === Infinity)) {
if (!(vim.visualBlock && motion === "moveToEol")) {
newHead = clipCursorToContent(cm, newHead, vim.visualBlock); newHead = clipCursorToContent(cm, newHead, vim.visualBlock);
} }
if (newAnchor) { if (newAnchor) {
newAnchor = clipCursorToContent(cm, newAnchor, true); newAnchor = clipCursorToContent(cm, newAnchor, true);
} }
@ -2323,7 +2236,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
var operatorMoveTo = operators[operator]( var operatorMoveTo = operators[operator](
cm, operatorArgs, cmSel.ranges, oldAnchor, newHead); cm, operatorArgs, cmSel.ranges, oldAnchor, newHead);
if (vim.visualMode) { if (vim.visualMode) {
exitVisualMode(cm, operatorMoveTo != null); exitVisualMode(cm);
} }
if (operatorMoveTo) { if (operatorMoveTo) {
cm.setCursor(operatorMoveTo); cm.setCursor(operatorMoveTo);
@ -2469,15 +2382,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
(line > last && cur.line == last)) { (line > last && cur.line == last)) {
return; return;
} }
// /ace patch
var fold = cm.ace.session.getFoldAt(line, endCh);
if (fold) {
if (motionArgs.forward)
line = fold.end.row + 1;
else
line = fold.start.row - 1;
}
// /ace patche
if (motionArgs.toFirstChar){ if (motionArgs.toFirstChar){
endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line)); endCh=findFirstNonWhiteSpaceCharacter(cm.getLine(line));
vim.lastHPos = endCh; vim.lastHPos = endCh;
@ -2700,10 +2604,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
}; };
function defineMotion(name, fn) {
motions[name] = fn;
}
function fillArray(val, times) { function fillArray(val, times) {
var arr = []; var arr = [];
for (var i = 0; i < times; i++) { for (var i = 0; i < times; i++) {
@ -2725,11 +2625,10 @@ dom.importCssString(".normal-mode .ace_cursor{\
var anchor = ranges[0].anchor, var anchor = ranges[0].anchor,
head = ranges[0].head; head = ranges[0].head;
text = cm.getRange(anchor, head); text = cm.getRange(anchor, head);
var lastState = vim.lastEditInputState || {}; if (!isWhiteSpaceString(text)) {
if (lastState.motion == "moveByWords" && !isWhiteSpaceString(text)) {
// Exclude trailing whitespace if the range is not all whitespace. // Exclude trailing whitespace if the range is not all whitespace.
var match = (/\s+$/).exec(text); var match = (/\s+$/).exec(text);
if (match && lastState.motionArgs && lastState.motionArgs.forward) { if (match) {
head = offsetCursor(head, 0, - match[0].length); head = offsetCursor(head, 0, - match[0].length);
text = text.slice(0, - match[0].length); text = text.slice(0, - match[0].length);
} }
@ -2787,7 +2686,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
vimGlobalState.registerController.pushText( vimGlobalState.registerController.pushText(
args.registerName, 'delete', text, args.registerName, 'delete', text,
args.linewise, vim.visualBlock); args.linewise, vim.visualBlock);
return clipCursorToContent(cm, finalHead); return finalHead;
}, },
indent: function(cm, args, ranges) { indent: function(cm, args, ranges) {
var vim = cm.state.vim; var vim = cm.state.vim;
@ -2855,10 +2754,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
}; };
function defineOperator(name, fn) {
operators[name] = fn;
}
var actions = { var actions = {
jumpListWalk: function(cm, actionArgs, vim) { jumpListWalk: function(cm, actionArgs, vim) {
if (vim.visualMode) { if (vim.visualMode) {
@ -2872,7 +2767,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
var markPos = mark ? mark.find() : undefined; var markPos = mark ? mark.find() : undefined;
markPos = markPos ? markPos : cm.getCursor(); markPos = markPos ? markPos : cm.getCursor();
cm.setCursor(markPos); cm.setCursor(markPos);
cm.ace.curOp.command.scrollIntoView = "center-animate"; // ace patch
}, },
scroll: function(cm, actionArgs, vim) { scroll: function(cm, actionArgs, vim) {
if (vim.visualMode) { if (vim.visualMode) {
@ -3076,11 +2970,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
if (vim.visualMode) { if (vim.visualMode) {
curStart = cm.getCursor('anchor'); curStart = cm.getCursor('anchor');
curEnd = cm.getCursor('head'); curEnd = cm.getCursor('head');
if (cursorIsBefore(curEnd, curStart)) {
var tmp = curEnd;
curEnd = curStart;
curStart = tmp;
}
curEnd.ch = lineLength(cm, curEnd.line) - 1; curEnd.ch = lineLength(cm, curEnd.line) - 1;
} else { } else {
// Repeat is the number of lines to join. Minimum 2 lines. // Repeat is the number of lines to join. Minimum 2 lines.
@ -3099,10 +2988,10 @@ dom.importCssString(".normal-mode .ace_cursor{\
cm.replaceRange(text, curStart, tmp); cm.replaceRange(text, curStart, tmp);
} }
var curFinalPos = Pos(curStart.line, finalCh); var curFinalPos = Pos(curStart.line, finalCh);
if (vim.visualMode) {
exitVisualMode(cm, false);
}
cm.setCursor(curFinalPos); cm.setCursor(curFinalPos);
if (vim.visualMode) {
exitVisualMode(cm);
}
}, },
newLineAndEnterInsertMode: function(cm, actionArgs, vim) { newLineAndEnterInsertMode: function(cm, actionArgs, vim) {
vim.insertMode = true; vim.insertMode = true;
@ -3265,7 +3154,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
} }
if (vim.visualMode) { if (vim.visualMode) {
exitVisualMode(cm, false); exitVisualMode(cm);
} }
cm.setCursor(curPosFinal); cm.setCursor(curPosFinal);
}, },
@ -3323,7 +3212,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
curStart = cursorIsBefore(selections[0].anchor, selections[0].head) ? curStart = cursorIsBefore(selections[0].anchor, selections[0].head) ?
selections[0].anchor : selections[0].head; selections[0].anchor : selections[0].head;
cm.setCursor(curStart); cm.setCursor(curStart);
exitVisualMode(cm, false); exitVisualMode(cm);
} else { } else {
cm.setCursor(offsetCursor(curEnd, 0, -1)); cm.setCursor(offsetCursor(curEnd, 0, -1));
} }
@ -3371,10 +3260,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
exitInsertMode: exitInsertMode exitInsertMode: exitInsertMode
}; };
function defineAction(name, fn) {
actions[name] = fn;
}
/* /*
* Below are miscellaneous utility functions used by vim.js * Below are miscellaneous utility functions used by vim.js
*/ */
@ -3504,6 +3389,9 @@ dom.importCssString(".normal-mode .ace_cursor{\
function lineLength(cm, lineNum) { function lineLength(cm, lineNum) {
return cm.getLine(lineNum).length; return cm.getLine(lineNum).length;
} }
function reverse(s){
return s.split('').reverse().join('');
}
function trim(s) { function trim(s) {
if (s.trim) { if (s.trim) {
return s.trim(); return s.trim();
@ -3817,38 +3705,59 @@ dom.importCssString(".normal-mode .ace_cursor{\
// Seek to first word or non-whitespace character, depending on if // Seek to first word or non-whitespace character, depending on if
// noSymbol is true. // noSymbol is true.
var test = noSymbol ? wordCharTest[0] : bigWordCharTest [0]; var textAfterIdx = line.substring(idx);
while (!test(line.charAt(idx))) { var firstMatchedChar;
idx++; if (noSymbol) {
if (idx >= line.length) { return null; } firstMatchedChar = textAfterIdx.search(/\w/);
}
if (bigWord) {
test = bigWordCharTest[0];
} else { } else {
test = wordCharTest[0]; firstMatchedChar = textAfterIdx.search(/\S/);
if (!test(line.charAt(idx))) { }
test = wordCharTest[1]; if (firstMatchedChar == -1) {
return null;
}
idx += firstMatchedChar;
textAfterIdx = line.substring(idx);
var textBeforeIdx = line.substring(0, idx);
var matchRegex;
// Greedy matchers for the "word" we are trying to expand.
if (bigWord) {
matchRegex = /^\S+/;
} else {
if ((/\w/).test(line.charAt(idx))) {
matchRegex = /^\w+/;
} else {
matchRegex = /^[^\w\s]+/;
} }
} }
var end = idx, start = idx; var wordAfterRegex = matchRegex.exec(textAfterIdx);
while (test(line.charAt(end)) && end < line.length) { end++; } var wordStart = idx;
while (test(line.charAt(start)) && start >= 0) { start--; } var wordEnd = idx + wordAfterRegex[0].length;
start++; // TODO: Find a better way to do this. It will be slow on very long lines.
var revTextBeforeIdx = reverse(textBeforeIdx);
var wordBeforeRegex = matchRegex.exec(revTextBeforeIdx);
if (wordBeforeRegex) {
wordStart -= wordBeforeRegex[0].length;
}
if (inclusive) { if (inclusive) {
// If present, include all whitespace after word. // If present, trim all whitespace after word.
// Otherwise, include all whitespace before word, except indentation. // Otherwise, trim all whitespace before word.
var wordEnd = end; var textAfterWordEnd = line.substring(wordEnd);
while (/\s/.test(line.charAt(end)) && end < line.length) { end++; } var whitespacesAfterWord = textAfterWordEnd.match(/^\s*/)[0].length;
if (wordEnd == end) { if (whitespacesAfterWord > 0) {
var wordStart = start; wordEnd += whitespacesAfterWord;
while (/\s/.test(line.charAt(start - 1)) && start > 0) { start--; } } else {
if (!start) { start = wordStart; } var revTrim = revTextBeforeIdx.length - wordStart;
var textBeforeWordStart = revTextBeforeIdx.substring(revTrim);
var whitespacesBeforeWord = textBeforeWordStart.match(/^\s*/)[0].length;
wordStart -= whitespacesBeforeWord;
} }
} }
return { start: Pos(cur.line, start), end: Pos(cur.line, end) };
return { start: Pos(cur.line, wordStart),
end: Pos(cur.line, wordEnd) };
} }
function recordJumpPosition(cm, oldCur, newCur) { function recordJumpPosition(cm, oldCur, newCur) {
@ -4006,7 +3915,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
var pos = cur.ch; var pos = cur.ch;
var line = cm.getLine(lineNum); var line = cm.getLine(lineNum);
var dir = forward ? 1 : -1; var dir = forward ? 1 : -1;
var charTests = bigWord ? bigWordCharTest: wordCharTest; var regexps = bigWord ? bigWordRegexp : wordRegexp;
if (emptyLineIsWord && line == '') { if (emptyLineIsWord && line == '') {
lineNum += dir; lineNum += dir;
@ -4026,11 +3935,11 @@ dom.importCssString(".normal-mode .ace_cursor{\
// Find bounds of next word. // Find bounds of next word.
while (pos != stop) { while (pos != stop) {
var foundWord = false; var foundWord = false;
for (var i = 0; i < charTests.length && !foundWord; ++i) { for (var i = 0; i < regexps.length && !foundWord; ++i) {
if (charTests[i](line.charAt(pos))) { if (regexps[i].test(line.charAt(pos))) {
wordStart = pos; wordStart = pos;
// Advance to end of word. // Advance to end of word.
while (pos != stop && charTests[i](line.charAt(pos))) { while (pos != stop && regexps[i].test(line.charAt(pos))) {
pos += dir; pos += dir;
} }
wordEnd = pos; wordEnd = pos;
@ -4178,7 +4087,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
var min = cm.firstLine(); var min = cm.firstLine();
var max = cm.lastLine(); var max = cm.lastLine();
var start, end, i = line; var start, end, i = line;
function isEmpty(i) { return !/\S/.test(cm.getLine(i)); } function isEmpty(i) { return !cm.getLine(i); }
function isBoundary(i, dir, any) { function isBoundary(i, dir, any) {
if (any) { return isEmpty(i) != isEmpty(i + dir); } if (any) { return isEmpty(i) != isEmpty(i + dir); }
return !isEmpty(i) && isEmpty(i + dir); return !isEmpty(i) && isEmpty(i + dir);
@ -4347,12 +4256,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
}, },
setReversed: function(reversed) { setReversed: function(reversed) {
vimGlobalState.isReversed = reversed; vimGlobalState.isReversed = reversed;
},
getScrollbarAnnotate: function() {
return this.annotate;
},
setScrollbarAnnotate: function(annotate) {
this.annotate = annotate;
} }
}; };
function getSearchState(cm) { function getSearchState(cm) {
@ -4362,8 +4265,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
function dialog(cm, template, shortText, onClose, options) { function dialog(cm, template, shortText, onClose, options) {
if (cm.openDialog) { if (cm.openDialog) {
cm.openDialog(template, onClose, { bottom: true, value: options.value, cm.openDialog(template, onClose, { bottom: true, value: options.value,
onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp, onKeyDown: options.onKeyDown, onKeyUp: options.onKeyUp });
selectValueOnOpen: false});
} }
else { else {
onClose(prompt(shortText, '')); onClose(prompt(shortText, ''));
@ -4632,21 +4534,14 @@ dom.importCssString(".normal-mode .ace_cursor{\
}; };
} }
function highlightSearchMatches(cm, query) { function highlightSearchMatches(cm, query) {
var searchState = getSearchState(cm); var overlay = getSearchState(cm).getOverlay();
var overlay = searchState.getOverlay();
if (!overlay || query != overlay.query) { if (!overlay || query != overlay.query) {
if (overlay) { if (overlay) {
cm.removeOverlay(overlay); cm.removeOverlay(overlay);
} }
overlay = searchOverlay(query); overlay = searchOverlay(query);
cm.addOverlay(overlay); cm.addOverlay(overlay);
if (cm.showMatchesOnScrollbar) { getSearchState(cm).setOverlay(overlay);
if (searchState.getScrollbarAnnotate()) {
searchState.getScrollbarAnnotate().clear();
}
searchState.setScrollbarAnnotate(cm.showMatchesOnScrollbar(query));
}
searchState.setOverlay(overlay);
} }
} }
function findNext(cm, prev, query, repeat) { function findNext(cm, prev, query, repeat) {
@ -4671,13 +4566,8 @@ dom.importCssString(".normal-mode .ace_cursor{\
}); });
} }
function clearSearchHighlight(cm) { function clearSearchHighlight(cm) {
var state = getSearchState(cm);
cm.removeOverlay(getSearchState(cm).getOverlay()); cm.removeOverlay(getSearchState(cm).getOverlay());
state.setOverlay(null); getSearchState(cm).setOverlay(null);
if (state.getScrollbarAnnotate()) {
state.getScrollbarAnnotate().clear();
state.setScrollbarAnnotate(null);
}
} }
/** /**
* Check if pos is in the specified range, INCLUSIVE. * Check if pos is in the specified range, INCLUSIVE.
@ -4718,7 +4608,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
// pair of commands that have a shared prefix, at least one of their // pair of commands that have a shared prefix, at least one of their
// shortNames must not match the prefix of the other command. // shortNames must not match the prefix of the other command.
var defaultExCommandMap = [ var defaultExCommandMap = [
{ name: 'colorscheme', shortName: 'colo' },
{ name: 'map' }, { name: 'map' },
{ name: 'imap', shortName: 'im' }, { name: 'imap', shortName: 'im' },
{ name: 'nmap', shortName: 'nm' }, { name: 'nmap', shortName: 'nm' },
@ -4727,10 +4616,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
{ name: 'write', shortName: 'w' }, { name: 'write', shortName: 'w' },
{ name: 'undo', shortName: 'u' }, { name: 'undo', shortName: 'u' },
{ name: 'redo', shortName: 'red' }, { name: 'redo', shortName: 'red' },
{ name: 'set', shortName: 'se' }, { name: 'set', shortName: 'set' },
{ name: 'set', shortName: 'se' },
{ name: 'setlocal', shortName: 'setl' },
{ name: 'setglobal', shortName: 'setg' },
{ name: 'sort', shortName: 'sor' }, { name: 'sort', shortName: 'sor' },
{ name: 'substitute', shortName: 's', possiblyAsync: true }, { name: 'substitute', shortName: 's', possiblyAsync: true },
{ name: 'nohlsearch', shortName: 'noh' }, { name: 'nohlsearch', shortName: 'noh' },
@ -4743,13 +4629,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
}; };
ExCommandDispatcher.prototype = { ExCommandDispatcher.prototype = {
processCommand: function(cm, input, opt_params) { processCommand: function(cm, input, opt_params) {
var that = this;
cm.operation(function () {
cm.curOp.isVimOp = true;
that._processCommand(cm, input, opt_params);
});
},
_processCommand: function(cm, input, opt_params) {
var vim = cm.state.vim; var vim = cm.state.vim;
var commandHistoryRegister = vimGlobalState.registerController.getRegister(':'); var commandHistoryRegister = vimGlobalState.registerController.getRegister(':');
var previousCommand = commandHistoryRegister.toString(); var previousCommand = commandHistoryRegister.toString();
@ -4962,13 +4841,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
}; };
var exCommands = { var exCommands = {
colorscheme: function(cm, params) {
if (!params.args || params.args.length < 1) {
showConfirm(cm, cm.getOption('theme'));
return;
}
cm.setOption('theme', params.args[0]);
},
map: function(cm, params, ctx) { map: function(cm, params, ctx) {
var mapArgs = params.args; var mapArgs = params.args;
if (!mapArgs || mapArgs.length < 2) { if (!mapArgs || mapArgs.length < 2) {
@ -5002,9 +4874,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
}, },
set: function(cm, params) { set: function(cm, params) {
var setArgs = params.args; var setArgs = params.args;
// Options passed through to the setOption/getOption calls. May be passed in by the
// local/global versions of the set command
var setCfg = params.setCfg || {};
if (!setArgs || setArgs.length < 1) { if (!setArgs || setArgs.length < 1) {
if (cm) { if (cm) {
showConfirm(cm, 'Invalid mapping: ' + params.input); showConfirm(cm, 'Invalid mapping: ' + params.input);
@ -5028,35 +4897,24 @@ dom.importCssString(".normal-mode .ace_cursor{\
optionName = optionName.substring(2); optionName = optionName.substring(2);
value = false; value = false;
} }
var optionIsBoolean = options[optionName] && options[optionName].type == 'boolean'; var optionIsBoolean = options[optionName] && options[optionName].type == 'boolean';
if (optionIsBoolean && value == undefined) { if (optionIsBoolean && value == undefined) {
// Calling set with a boolean option sets it to true. // Calling set with a boolean option sets it to true.
value = true; value = true;
} }
// If no value is provided, then we assume this is a get. if (!optionIsBoolean && !value || forceGet) {
if (!optionIsBoolean && value === undefined || forceGet) { var oldValue = getOption(optionName);
var oldValue = getOption(optionName, cm, setCfg); // If no value is provided, then we assume this is a get.
if (oldValue === true || oldValue === false) { if (oldValue === true || oldValue === false) {
showConfirm(cm, ' ' + (oldValue ? '' : 'no') + optionName); showConfirm(cm, ' ' + (oldValue ? '' : 'no') + optionName);
} else { } else {
showConfirm(cm, ' ' + optionName + '=' + oldValue); showConfirm(cm, ' ' + optionName + '=' + oldValue);
} }
} else { } else {
setOption(optionName, value, cm, setCfg); setOption(optionName, value, cm);
} }
}, },
setlocal: function (cm, params) { registers: function(cm,params) {
// setCfg is passed through to setOption
params.setCfg = {scope: 'local'};
this.set(cm, params);
},
setglobal: function (cm, params) {
// setCfg is passed through to setOption
params.setCfg = {scope: 'global'};
this.set(cm, params);
},
registers: function(cm, params) {
var regArgs = params.args; var regArgs = params.args;
var registers = vimGlobalState.registerController.registers; var registers = vimGlobalState.registerController.registers;
var regInfo = '----------Registers----------<br><br>'; var regInfo = '----------Registers----------<br><br>';
@ -5536,19 +5394,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
} }
function _mapCommand(command) {
defaultKeymap.push(command);
}
function mapCommand(keys, type, name, args, extra) {
var command = {keys: keys, type: type};
command[type] = name;
command[type + "Args"] = args;
for (var key in extra)
command[key] = extra[key];
_mapCommand(command);
}
// The timeout in milliseconds for the two-character ESC keymap should be // The timeout in milliseconds for the two-character ESC keymap should be
// adjusted according to your typing speed to prevent false positives. // adjusted according to your typing speed to prevent false positives.
defineOption('insertModeEscKeysTimeout', 200, 'number'); defineOption('insertModeEscKeysTimeout', 200, 'number');
@ -5678,7 +5523,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
function updateFakeCursor(cm) { function updateFakeCursor(cm) {
var vim = cm.state.vim; var vim = cm.state.vim;
var from = clipCursorToContent(cm, copyCursor(vim.sel.head)); var from = copyCursor(vim.sel.head);
var to = offsetCursor(from, 0, 1); var to = offsetCursor(from, 0, 1);
if (vim.fakeCursor) { if (vim.fakeCursor) {
vim.fakeCursor.clear(); vim.fakeCursor.clear();
@ -5689,7 +5534,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
var anchor = cm.getCursor('anchor'); var anchor = cm.getCursor('anchor');
var head = cm.getCursor('head'); var head = cm.getCursor('head');
// Enter or exit visual mode to match mouse selection. // Enter or exit visual mode to match mouse selection.
if (vim.visualMode && !cm.somethingSelected()) { if (vim.visualMode && cursorEqual(head, anchor) && lineLength(cm, head.line) > head.ch) {
exitVisualMode(cm, false); exitVisualMode(cm, false);
} else if (!vim.visualMode && !vim.insertMode && cm.somethingSelected()) { } else if (!vim.visualMode && !vim.insertMode && cm.somethingSelected()) {
vim.visualMode = true; vim.visualMode = true;
@ -5729,7 +5574,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
var macroModeState = vimGlobalState.macroModeState; var macroModeState = vimGlobalState.macroModeState;
var lastChange = macroModeState.lastInsertModeChanges; var lastChange = macroModeState.lastInsertModeChanges;
var keyName = CodeMirror.keyName(e); var keyName = CodeMirror.keyName(e);
if (!keyName) { return; }
function onKeyFound() { function onKeyFound() {
lastChange.changes.push(new InsertModeKey(keyName)); lastChange.changes.push(new InsertModeKey(keyName));
return true; return true;
@ -5923,7 +5767,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
}, true); }, true);
} }
return isHandled; return isHandled;
} };
exports.CodeMirror = CodeMirror; exports.CodeMirror = CodeMirror;
var getVim = Vim.maybeInitVimState_; var getVim = Vim.maybeInitVimState_;
exports.handler = { exports.handler = {
@ -5937,9 +5781,9 @@ dom.importCssString(".normal-mode .ace_cursor{\
if (!vim.insertMode) { if (!vim.insertMode) {
var isbackwards = !sel.cursor var isbackwards = !sel.cursor
? session.selection.isBackwards() || session.selection.isEmpty() ? session.selection.isBackwards() || session.selection.isEmpty()
: Range.comparePoints(sel.cursor, sel.start) <= 0; : Range.comparePoints(sel.cursor, sel.start) <= 0
if (!isbackwards && left > w) if (!isbackwards && left > w)
left -= w; left -= w
} }
if (!vim.insertMode && vim.status) { if (!vim.insertMode && vim.status) {
h = h / 2; h = h / 2;
@ -6100,16 +5944,16 @@ dom.importCssString(".normal-mode .ace_cursor{\
} }
} }
} }
}; }
var renderVirtualNumbers = { var renderVirtualNumbers = {
getText: function(session, row) { getText: function(session, row) {
return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9? "\xb7" : "" ))) + ""; return (Math.abs(session.selection.lead.row - row) || (row + 1 + (row < 9? "\xb7" : "" ))) + ""
}, },
getWidth: function(session, lastLineNumber, config) { getWidth: function(session, lastLineNumber, config) {
return session.getLength().toString().length * config.characterWidth; return session.getLength().toString().length * config.characterWidth;
}, },
update: function(e, editor) { update: function(e, editor) {
editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER); editor.renderer.$loop.schedule(editor.renderer.CHANGE_GUTTER)
}, },
attach: function(editor) { attach: function(editor) {
editor.renderer.$gutterLayer.$renderer = this; editor.renderer.$gutterLayer.$renderer = this;
@ -6127,9 +5971,6 @@ dom.importCssString(".normal-mode .ace_cursor{\
}, },
type: "boolean" type: "boolean"
}, false); }, false);
Vim.defineEx('write', 'w', function() {
console.log(':write is not implemented')
});
defaultKeymap.push( defaultKeymap.push(
{ keys: 'zc', type: 'action', action: 'fold', actionArgs: { open: false } }, { keys: 'zc', type: 'action', action: 'fold', actionArgs: { open: false } },
{ keys: 'zC', type: 'action', action: 'fold', actionArgs: { open: false, all: true } }, { keys: 'zC', type: 'action', action: 'fold', actionArgs: { open: false, all: true } },
@ -6154,7 +5995,7 @@ dom.importCssString(".normal-mode .ace_cursor{\
if (cm.ace.inVirtualSelectionMode) if (cm.ace.inVirtualSelectionMode)
cm.ace.on("beforeEndOperation", delayedExecAceCommand); cm.ace.on("beforeEndOperation", delayedExecAceCommand);
else else
delayedExecAceCommand(null, cm.ace); delayedExecAceCommand(null, cm.ace)
}; };
function delayedExecAceCommand(op, ace) { function delayedExecAceCommand(op, ace) {
ace.off("beforeEndOperation", delayedExecAceCommand); ace.off("beforeEndOperation", delayedExecAceCommand);
@ -6173,5 +6014,5 @@ dom.importCssString(".normal-mode .ace_cursor{\
exports.handler.actions = actions; exports.handler.actions = actions;
exports.Vim = Vim; exports.Vim = Vim;
Vim.map("Y", "yy", "normal"); Vim.map("Y", "yy");
}); });

View file

@ -34,7 +34,6 @@ editor.session.setMode(new JavaScriptMode());
function CodeMirror(place, opts) { function CodeMirror(place, opts) {
if (opts.value != null) if (opts.value != null)
editor.session.setValue(opts.value); editor.session.setValue(opts.value);
editor.setOption("indentedSoftWrap", false);
editor.setOption("wrap", opts.lineWrapping); editor.setOption("wrap", opts.lineWrapping);
editor.setOption("useSoftTabs", !opts.indentWithTabs); editor.setOption("useSoftTabs", !opts.indentWithTabs);
editor.setKeyboardHandler(null); editor.setKeyboardHandler(null);
@ -59,7 +58,6 @@ function CodeMirror(place, opts) {
cm.setSize(500, 300); cm.setSize(500, 300);
return cm; return cm;
} }
CodeMirror.defineMode = function() {}
for (var key in vim.CodeMirror) for (var key in vim.CodeMirror)
CodeMirror[key] = vim.CodeMirror[key]; CodeMirror[key] = vim.CodeMirror[key];
var editor; var editor;
@ -75,9 +73,6 @@ function test(name, fn) {
} }
vim.CodeMirror.Vim.unmap("Y"); vim.CodeMirror.Vim.unmap("Y");
vim.CodeMirror.Vim.defineEx('write', 'w', function(cm) {
CodeMirror.commands.save(cm);
});
@ -597,7 +592,7 @@ testVim('{', function(cm, vim, helpers) {
helpers.doKeys('6', '{'); helpers.doKeys('6', '{');
helpers.assertCursorAt(0, 0); helpers.assertCursorAt(0, 0);
}, { value: 'a\n\nb\nc\n\nd' }); }, { value: 'a\n\nb\nc\n\nd' });
testVim('paragraph_motions', function(cm, vim, helpers) { testVim('paragraph motions', function(cm, vim, helpers) {
cm.setCursor(10, 0); cm.setCursor(10, 0);
helpers.doKeys('{'); helpers.doKeys('{');
helpers.assertCursorAt(4, 0); helpers.assertCursorAt(4, 0);
@ -690,7 +685,7 @@ testVim('dl_eol', function(cm, vim, helpers) {
var register = helpers.getRegisterController().getRegister(); var register = helpers.getRegisterController().getRegister();
eq(' ', register.toString()); eq(' ', register.toString());
is(!register.linewise); is(!register.linewise);
helpers.assertCursorAt(0, 5); helpers.assertCursorAt(0, 6);
}, { value: ' word1 ' }); }, { value: ' word1 ' });
testVim('dl_repeat', function(cm, vim, helpers) { testVim('dl_repeat', function(cm, vim, helpers) {
var curStart = makeCursor(0, 0); var curStart = makeCursor(0, 0);
@ -772,16 +767,6 @@ testVim('dw_word', function(cm, vim, helpers) {
is(!register.linewise); is(!register.linewise);
eqPos(curStart, cm.getCursor()); eqPos(curStart, cm.getCursor());
}, { value: ' word1 word2' }); }, { value: ' word1 word2' });
testVim('dw_unicode_word', function(cm, vim, helpers) {
helpers.doKeys('d', 'w');
eq(cm.getValue().length, 10);
helpers.doKeys('d', 'w');
eq(cm.getValue().length, 6);
helpers.doKeys('d', 'w');
eq(cm.getValue().length, 5);
helpers.doKeys('d', 'e');
eq(cm.getValue().length, 2);
}, { value: ' \u0562\u0561\u0580\u0587\xbbe\xb5g ' });
testVim('dw_only_word', function(cm, vim, helpers) { testVim('dw_only_word', function(cm, vim, helpers) {
// Test that if there is only 1 word left, dw deletes till the end of the // Test that if there is only 1 word left, dw deletes till the end of the
// line. // line.
@ -791,7 +776,7 @@ testVim('dw_only_word', function(cm, vim, helpers) {
var register = helpers.getRegisterController().getRegister(); var register = helpers.getRegisterController().getRegister();
eq('word1 ', register.toString()); eq('word1 ', register.toString());
is(!register.linewise); is(!register.linewise);
helpers.assertCursorAt(0, 0); helpers.assertCursorAt(0, 1);
}, { value: ' word1 ' }); }, { value: ' word1 ' });
testVim('dw_eol', function(cm, vim, helpers) { testVim('dw_eol', function(cm, vim, helpers) {
// Assert that dw does not delete the newline if last word to delete is at end // Assert that dw does not delete the newline if last word to delete is at end
@ -802,7 +787,7 @@ testVim('dw_eol', function(cm, vim, helpers) {
var register = helpers.getRegisterController().getRegister(); var register = helpers.getRegisterController().getRegister();
eq('word1', register.toString()); eq('word1', register.toString());
is(!register.linewise); is(!register.linewise);
helpers.assertCursorAt(0, 0); helpers.assertCursorAt(0, 1);
}, { value: ' word1\nword2' }); }, { value: ' word1\nword2' });
testVim('dw_eol_with_multiple_newlines', function(cm, vim, helpers) { testVim('dw_eol_with_multiple_newlines', function(cm, vim, helpers) {
// Assert that dw does not delete the newline if last word to delete is at end // Assert that dw does not delete the newline if last word to delete is at end
@ -813,7 +798,7 @@ testVim('dw_eol_with_multiple_newlines', function(cm, vim, helpers) {
var register = helpers.getRegisterController().getRegister(); var register = helpers.getRegisterController().getRegister();
eq('word1', register.toString()); eq('word1', register.toString());
is(!register.linewise); is(!register.linewise);
helpers.assertCursorAt(0, 0); helpers.assertCursorAt(0, 1);
}, { value: ' word1\n\nword2' }); }, { value: ' word1\n\nword2' });
testVim('dw_empty_line_followed_by_whitespace', function(cm, vim, helpers) { testVim('dw_empty_line_followed_by_whitespace', function(cm, vim, helpers) {
cm.setCursor(0, 0); cm.setCursor(0, 0);
@ -859,7 +844,7 @@ testVim('dw_repeat', function(cm, vim, helpers) {
var register = helpers.getRegisterController().getRegister(); var register = helpers.getRegisterController().getRegister();
eq('word1\nword2', register.toString()); eq('word1\nword2', register.toString());
is(!register.linewise); is(!register.linewise);
helpers.assertCursorAt(0, 0); helpers.assertCursorAt(0, 1);
}, { value: ' word1\nword2' }); }, { value: ' word1\nword2' });
testVim('de_word_start_and_empty_lines', function(cm, vim, helpers) { testVim('de_word_start_and_empty_lines', function(cm, vim, helpers) {
cm.setCursor(0, 0); cm.setCursor(0, 0);
@ -1077,17 +1062,6 @@ testVim('cc_multiply_repeat', function(cm, vim, helpers) {
is(register.linewise); is(register.linewise);
eq('vim-insert', cm.getOption('keyMap')); eq('vim-insert', cm.getOption('keyMap'));
}); });
testVim('ct', function(cm, vim, helpers) {
cm.setCursor(0, 9);
helpers.doKeys('c', 't', 'w');
eq(' word1 word3', cm.getValue());
helpers.doKeys('<Esc>', 'c', '|');
eq(' word3', cm.getValue());
helpers.assertCursorAt(0, 0);
helpers.doKeys('<Esc>', '2', 'u', 'w', 'h');
helpers.doKeys('c', '2', 'g', 'e');
eq(' wordword3', cm.getValue());
}, { value: ' word1 word2 word3'});
testVim('cc_should_not_append_to_document', function(cm, vim, helpers) { testVim('cc_should_not_append_to_document', function(cm, vim, helpers) {
var expectedLineCount = cm.lineCount(); var expectedLineCount = cm.lineCount();
cm.setCursor(cm.lastLine(), 0); cm.setCursor(cm.lastLine(), 0);
@ -1397,7 +1371,7 @@ testVim('D', function(cm, vim, helpers) {
var register = helpers.getRegisterController().getRegister(); var register = helpers.getRegisterController().getRegister();
eq('rd1', register.toString()); eq('rd1', register.toString());
is(!register.linewise); is(!register.linewise);
helpers.assertCursorAt(0, 2); helpers.assertCursorAt(0, 3);
}, { value: ' word1\nword2\n word3' }); }, { value: ' word1\nword2\n word3' });
testVim('C', function(cm, vim, helpers) { testVim('C', function(cm, vim, helpers) {
var curStart = makeCursor(0, 3); var curStart = makeCursor(0, 3);
@ -1988,11 +1962,8 @@ testVim('visual_block_move_to_eol', function(cm, vim, helpers) {
cm.setCursor(0, 0); cm.setCursor(0, 0);
helpers.doKeys('<C-v>', 'G', '$'); helpers.doKeys('<C-v>', 'G', '$');
var selections = cm.getSelections().join(); var selections = cm.getSelections().join();
eq('123,45,6', selections); console.log(selections);
// Checks that with cursor at Infinity, finding words backwards still works. eq("123,45,6", selections);
helpers.doKeys('2', 'k', 'b');
selections = cm.getSelections().join();
eq('1', selections);
}, {value: '123\n45\n6'}); }, {value: '123\n45\n6'});
testVim('visual_block_different_line_lengths', function(cm, vim, helpers) { testVim('visual_block_different_line_lengths', function(cm, vim, helpers) {
// test the block selection with lines of different length // test the block selection with lines of different length
@ -2082,11 +2053,6 @@ testVim('visual_join', function(cm, vim, helpers) {
eq(' 1 2 3\n 4\n 5', cm.getValue()); eq(' 1 2 3\n 4\n 5', cm.getValue());
is(!vim.visualMode); is(!vim.visualMode);
}, { value: ' 1\n 2\n 3\n 4\n 5' }); }, { value: ' 1\n 2\n 3\n 4\n 5' });
testVim('visual_join_2', function(cm, vim, helpers) {
helpers.doKeys('G', 'V', 'g', 'g', 'J');
eq('1 2 3 4 5 6 ', cm.getValue());
is(!vim.visualMode);
}, { value: '1\n2\n3\n4\n5\n6\n'});
testVim('visual_blank', function(cm, vim, helpers) { testVim('visual_blank', function(cm, vim, helpers) {
helpers.doKeys('v', 'k'); helpers.doKeys('v', 'k');
eq(vim.visualMode, true); eq(vim.visualMode, true);
@ -2294,15 +2260,6 @@ testVim('S_visual', function(cm, vim, helpers) {
eq('\ncc', cm.getValue()); eq('\ncc', cm.getValue());
}, { value: 'aa\nbb\ncc'}); }, { value: 'aa\nbb\ncc'});
testVim('d_/', function(cm, vim, helpers) {
cm.openDialog = helpers.fakeOpenDialog('match');
helpers.doKeys('2', 'd', '/');
helpers.assertCursorAt(0, 0);
eq('match \n next', cm.getValue());
cm.openDialog = helpers.fakeOpenDialog('2');
helpers.doKeys('d', ':');
// TODO eq(' next', cm.getValue());
}, { value: 'text match match \n next' });
testVim('/ and n/N', function(cm, vim, helpers) { testVim('/ and n/N', function(cm, vim, helpers) {
cm.openDialog = helpers.fakeOpenDialog('match'); cm.openDialog = helpers.fakeOpenDialog('match');
helpers.doKeys('/'); helpers.doKeys('/');
@ -2820,44 +2777,6 @@ testVim('exCommand_history', function(cm, vim, helpers) {
onKeyDown({keyCode: keyCodes.Up}, input, close); onKeyDown({keyCode: keyCodes.Up}, input, close);
eq(input, 'sort'); eq(input, 'sort');
}, {value: ''}); }, {value: ''});
testVim('search_clear', function(cm, vim, helpers) {
var onKeyDown;
var input = '';
var keyCodes = {
Ctrl: 17,
u: 85
};
cm.openDialog = function(template, callback, options) {
onKeyDown = options.onKeyDown;
};
var close = function(newVal) {
if (typeof newVal == 'string') input = newVal;
}
helpers.doKeys('/');
input = 'foo';
onKeyDown({keyCode: keyCodes.Ctrl}, input, close);
onKeyDown({keyCode: keyCodes.u, ctrlKey: true}, input, close);
eq(input, '');
});
testVim('exCommand_clear', function(cm, vim, helpers) {
var onKeyDown;
var input = '';
var keyCodes = {
Ctrl: 17,
u: 85
};
cm.openDialog = function(template, callback, options) {
onKeyDown = options.onKeyDown;
};
var close = function(newVal) {
if (typeof newVal == 'string') input = newVal;
}
helpers.doKeys(':');
input = 'foo';
onKeyDown({keyCode: keyCodes.Ctrl}, input, close);
onKeyDown({keyCode: keyCodes.u, ctrlKey: true}, input, close);
eq(input, '');
});
testVim('.', function(cm, vim, helpers) { testVim('.', function(cm, vim, helpers) {
cm.setCursor(0, 0); cm.setCursor(0, 0);
helpers.doKeys('2', 'd', 'w'); helpers.doKeys('2', 'd', 'w');
@ -3285,7 +3204,7 @@ testVim('scrollMotion', function(cm, vim, helpers){
cm.refresh(); //ace! cm.refresh(); //ace!
prevScrollInfo = cm.getScrollInfo(); prevScrollInfo = cm.getScrollInfo();
helpers.doKeys('<C-y>'); helpers.doKeys('<C-y>');
eq(prevCursor.line - 1, cm.getCursor().line, "Y"); eq(prevCursor.line - 1, cm.getCursor().line);
is(prevScrollInfo.top > cm.getScrollInfo().top); is(prevScrollInfo.top > cm.getScrollInfo().top);
}, { value: scrollMotionSandbox}); }, { value: scrollMotionSandbox});
@ -3808,111 +3727,17 @@ testVim('set_string', function(cm, vim, helpers) {
eq('c', CodeMirror.Vim.getOption('testoption')); eq('c', CodeMirror.Vim.getOption('testoption'));
}); });
testVim('ex_set_string', function(cm, vim, helpers) { testVim('ex_set_string', function(cm, vim, helpers) {
CodeMirror.Vim.defineOption('testopt', 'a', 'string'); CodeMirror.Vim.defineOption('testoption', 'a', 'string');
// Test default value is set. // Test default value is set.
eq('a', CodeMirror.Vim.getOption('testopt')); eq('a', CodeMirror.Vim.getOption('testoption'));
try { try {
// Test fail to set 'notestopt' // Test fail to set 'notestoption'
helpers.doEx('set notestopt=b'); helpers.doEx('set notestoption=b');
fail(); fail();
} catch (expected) {}; } catch (expected) {};
// Test setOption // Test setOption
helpers.doEx('set testopt=c') helpers.doEx('set testoption=c')
eq('c', CodeMirror.Vim.getOption('testopt')); eq('c', CodeMirror.Vim.getOption('testoption'));
helpers.doEx('set testopt=c')
eq('c', CodeMirror.Vim.getOption('testopt', cm)); //local || global
eq('c', CodeMirror.Vim.getOption('testopt', cm, {scope: 'local'})); // local
eq('c', CodeMirror.Vim.getOption('testopt', cm, {scope: 'global'})); // global
eq('c', CodeMirror.Vim.getOption('testopt')); // global
// Test setOption global
helpers.doEx('setg testopt=d')
eq('c', CodeMirror.Vim.getOption('testopt', cm));
eq('c', CodeMirror.Vim.getOption('testopt', cm, {scope: 'local'}));
eq('d', CodeMirror.Vim.getOption('testopt', cm, {scope: 'global'}));
eq('d', CodeMirror.Vim.getOption('testopt'));
// Test setOption local
helpers.doEx('setl testopt=e')
eq('e', CodeMirror.Vim.getOption('testopt', cm));
eq('e', CodeMirror.Vim.getOption('testopt', cm, {scope: 'local'}));
eq('d', CodeMirror.Vim.getOption('testopt', cm, {scope: 'global'}));
eq('d', CodeMirror.Vim.getOption('testopt'));
});
testVim('ex_set_callback', function(cm, vim, helpers) {
var global;
function cb(val, cm, cfg) {
if (val === undefined) {
// Getter
if (cm) {
return cm._local;
} else {
return global;
}
} else {
// Setter
if (cm) {
cm._local = val;
} else {
global = val;
}
}
}
CodeMirror.Vim.defineOption('testopt', 'a', 'string', cb);
// Test default value is set.
eq('a', CodeMirror.Vim.getOption('testopt'));
try {
// Test fail to set 'notestopt'
helpers.doEx('set notestopt=b');
fail();
} catch (expected) {};
// Test setOption (Identical to the string tests, but via callback instead)
helpers.doEx('set testopt=c')
eq('c', CodeMirror.Vim.getOption('testopt', cm)); //local || global
eq('c', CodeMirror.Vim.getOption('testopt', cm, {scope: 'local'})); // local
eq('c', CodeMirror.Vim.getOption('testopt', cm, {scope: 'global'})); // global
eq('c', CodeMirror.Vim.getOption('testopt')); // global
// Test setOption global
helpers.doEx('setg testopt=d')
eq('c', CodeMirror.Vim.getOption('testopt', cm));
eq('c', CodeMirror.Vim.getOption('testopt', cm, {scope: 'local'}));
eq('d', CodeMirror.Vim.getOption('testopt', cm, {scope: 'global'}));
eq('d', CodeMirror.Vim.getOption('testopt'));
// Test setOption local
helpers.doEx('setl testopt=e')
eq('e', CodeMirror.Vim.getOption('testopt', cm));
eq('e', CodeMirror.Vim.getOption('testopt', cm, {scope: 'local'}));
eq('d', CodeMirror.Vim.getOption('testopt', cm, {scope: 'global'}));
eq('d', CodeMirror.Vim.getOption('testopt'));
})
testVim('ex_set_filetype', function(cm, vim, helpers) {
CodeMirror.defineMode('test_mode', function() {
return {token: function(stream) {
stream.match(/^\s+|^\S+/);
}};
});
CodeMirror.defineMode('test_mode_2', function() {
return {token: function(stream) {
stream.match(/^\s+|^\S+/);
}};
});
// Test mode is set.
helpers.doEx('set filetype=test_mode');
eq('test_mode', cm.getMode().name);
// Test 'ft' alias also sets mode.
helpers.doEx('set ft=test_mode_2');
eq('test_mode_2', cm.getMode().name);
});
testVim('ex_set_filetype_null', function(cm, vim, helpers) {
CodeMirror.defineMode('test_mode', function() {
return {token: function(stream) {
stream.match(/^\s+|^\S+/);
}};
});
cm.setOption('mode', 'test_mode');
// Test mode is set to null.
helpers.doEx('set filetype=');
eq('null', cm.getMode().name);
}); });
// TODO: Reset key maps after each test. // TODO: Reset key maps after each test.
testVim('ex_map_key2key', function(cm, vim, helpers) { testVim('ex_map_key2key', function(cm, vim, helpers) {

View file

@ -120,9 +120,9 @@ var FontMetrics = exports.FontMetrics = function(parentEl, interval) {
this.setPolling = function(val) { this.setPolling = function(val) {
if (val) { if (val) {
this.$pollSizeChanges(); this.$pollSizeChanges();
} else if (this.$pollSizeChangesTimer) { } else {
clearInterval(this.$pollSizeChangesTimer); if (this.$pollSizeChangesTimer)
this.$pollSizeChangesTimer = 0; this.$pollSizeChangesTimer;
} }
}; };

View file

@ -100,14 +100,16 @@ var Gutter = function(parentEl) {
} }
}; };
this.$updateAnnotations = function (delta) { this.$updateAnnotations = function (e) {
if (!this.$annotations.length) if (!this.$annotations.length)
return; return;
var firstRow = delta.start.row; var delta = e.data;
var len = delta.end.row - firstRow; var range = delta.range;
var firstRow = range.start.row;
var len = range.end.row - firstRow;
if (len === 0) { if (len === 0) {
// do nothing // do nothing
} else if (delta.action == 'remove') { } else if (delta.action == "removeText" || delta.action == "removeLines") {
this.$annotations.splice(firstRow, len + 1, null); this.$annotations.splice(firstRow, len + 1, null);
} else { } else {
var args = new Array(len + 1); var args = new Array(len + 1);

View file

@ -90,7 +90,7 @@ var Marker = function(parentEl) {
else else
this.drawMultiLineMarker(html, range, marker.clazz, config); this.drawMultiLineMarker(html, range, marker.clazz, config);
} else { } else {
this.drawSingleLineMarker(html, range, marker.clazz + " ace_start" + " ace_br15", config); this.drawSingleLineMarker(html, range, marker.clazz + " ace_start", config);
} }
} }
this.element.innerHTML = html.join(""); this.element.innerHTML = html.join("");
@ -100,30 +100,27 @@ var Marker = function(parentEl) {
return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight; return (row - layerConfig.firstRowScreen) * layerConfig.lineHeight;
}; };
function getBorderClass(tl, tr, br, bl) {
return (tl ? 1 : 0) | (tr ? 2 : 0) | (br ? 4 : 0) | (bl ? 8 : 0);
}
// Draws a marker, which spans a range of text on multiple lines // Draws a marker, which spans a range of text on multiple lines
this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) { this.drawTextMarker = function(stringBuilder, range, clazz, layerConfig, extraStyle) {
var session = this.session; // selection start
var start = range.start.row; var row = range.start.row;
var end = range.end.row;
var row = start; var lineRange = new Range(
var prev = 0; row, range.start.column,
var curr = 0; row, this.session.getScreenLastRowColumn(row)
var next = session.getScreenLastRowColumn(row); );
var lineRange = new Range(row, range.start.column, row, curr); this.drawSingleLineMarker(stringBuilder, lineRange, clazz + " ace_start", layerConfig, 1, extraStyle);
for (; row <= end; row++) {
lineRange.start.row = lineRange.end.row = row; // selection end
lineRange.start.column = row == start ? range.start.column : session.getRowWrapIndent(row); row = range.end.row;
lineRange.end.column = next; lineRange = new Range(row, 0, row, range.end.column);
prev = curr; this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 0, extraStyle);
curr = next;
next = row + 1 < end ? session.getScreenLastRowColumn(row + 1) : row == end ? 0 : range.end.column; for (row = range.start.row + 1; row < range.end.row; row++) {
this.drawSingleLineMarker(stringBuilder, lineRange, lineRange.start.row = row;
clazz + (row == start ? " ace_start" : "") + " ace_br" lineRange.end.row = row;
+ getBorderClass(row == start || row == start + 1 && range.start.column, prev < curr, curr > next, row == end), lineRange.end.column = this.session.getScreenLastRowColumn(row);
layerConfig, row == end ? 0 : 1, extraStyle); this.drawSingleLineMarker(stringBuilder, lineRange, clazz, layerConfig, 1, extraStyle);
} }
}; };
@ -137,7 +134,7 @@ var Marker = function(parentEl) {
extraStyle = extraStyle || ""; extraStyle = extraStyle || "";
stringBuilder.push( stringBuilder.push(
"<div class='", clazz, " ace_br1 ace_start' style='", "<div class='", clazz, " ace_start' style='",
"height:", height, "px;", "height:", height, "px;",
"right:0;", "right:0;",
"top:", top, "px;", "top:", top, "px;",
@ -149,7 +146,7 @@ var Marker = function(parentEl) {
var width = range.end.column * config.characterWidth; var width = range.end.column * config.characterWidth;
stringBuilder.push( stringBuilder.push(
"<div class='", clazz, " ace_br12' style='", "<div class='", clazz, "' style='",
"height:", height, "px;", "height:", height, "px;",
"width:", width, "px;", "width:", width, "px;",
"top:", top, "px;", "top:", top, "px;",
@ -158,14 +155,12 @@ var Marker = function(parentEl) {
// all the complete lines // all the complete lines
height = (range.end.row - range.start.row - 1) * config.lineHeight; height = (range.end.row - range.start.row - 1) * config.lineHeight;
if (height <= 0) if (height < 0)
return; return;
top = this.$getTop(range.start.row + 1, config); top = this.$getTop(range.start.row + 1, config);
var radiusClass = (range.start.column ? 1 : 0) | (range.end.column ? 0 : 8);
stringBuilder.push( stringBuilder.push(
"<div class='", clazz, (radiusClass ? " ace_br" + radiusClass : ""), "' style='", "<div class='", clazz, "' style='",
"height:", height, "px;", "height:", height, "px;",
"right:0;", "right:0;",
"top:", top, "px;", "top:", top, "px;",

View file

@ -52,7 +52,7 @@ var Text = function(parentEl) {
this.EOL_CHAR_LF = "\xAC"; this.EOL_CHAR_LF = "\xAC";
this.EOL_CHAR_CRLF = "\xa4"; this.EOL_CHAR_CRLF = "\xa4";
this.EOL_CHAR = this.EOL_CHAR_LF; this.EOL_CHAR = this.EOL_CHAR_LF;
this.TAB_CHAR = "\u2014"; //"\u21E5"; this.TAB_CHAR = "\u2192"; //"\u21E5";
this.SPACE_CHAR = "\xB7"; this.SPACE_CHAR = "\xB7";
this.$padding = 0; this.$padding = 0;
@ -128,10 +128,11 @@ var Text = function(parentEl) {
for (var i = 1; i < tabSize + 1; i++) { for (var i = 1; i < tabSize + 1; i++) {
if (this.showInvisibles) { if (this.showInvisibles) {
tabStr.push("<span class='ace_invisible ace_invisible_tab'>" tabStr.push("<span class='ace_invisible ace_invisible_tab'>"
+ lang.stringRepeat(this.TAB_CHAR, i) + this.TAB_CHAR
+ lang.stringRepeat("\xa0", i - 1)
+ "</span>"); + "</span>");
} else { } else {
tabStr.push(lang.stringRepeat(" ", i)); tabStr.push(lang.stringRepeat("\xa0", i));
} }
} }
if (this.displayIndentGuides) { if (this.displayIndentGuides) {
@ -144,9 +145,9 @@ var Text = function(parentEl) {
spaceClass = " ace_invisible_space"; spaceClass = " ace_invisible_space";
tabClass = " ace_invisible_tab"; tabClass = " ace_invisible_tab";
var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize); var spaceContent = lang.stringRepeat(this.SPACE_CHAR, this.tabSize);
var tabContent = lang.stringRepeat(this.TAB_CHAR, this.tabSize); var tabContent = this.TAB_CHAR + lang.stringRepeat("\xa0", this.tabSize - 1);
} else{ } else{
var spaceContent = lang.stringRepeat(" ", this.tabSize); var spaceContent = lang.stringRepeat("\xa0", this.tabSize);
var tabContent = spaceContent; var tabContent = spaceContent;
} }
@ -324,9 +325,9 @@ var Text = function(parentEl) {
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 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) { var replaceFunc = function(c, a, b, tabIdx, idx4) {
if (a) { if (a) {
return self.showInvisibles return self.showInvisibles ?
? "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>" "<span class='ace_invisible ace_invisible_space'>" + lang.stringRepeat(self.SPACE_CHAR, c.length) + "</span>" :
: c; lang.stringRepeat("\xa0", c.length);
} else if (c == "&") { } else if (c == "&") {
return "&#38;"; return "&#38;";
} else if (c == "<") { } else if (c == "<") {
@ -419,8 +420,6 @@ var Text = function(parentEl) {
); );
} }
stringBuilder.push(lang.stringRepeat("\xa0", splits.indent));
split ++; split ++;
screenColumn = 0; screenColumn = 0;
splitChars = splits[split] || Number.MAX_VALUE; splitChars = splits[split] || Number.MAX_VALUE;

View file

@ -89,9 +89,9 @@ module.exports = {
"test rendering of indent guides" : function() { "test rendering of indent guides" : function() {
var textLayer = this.textLayer var textLayer = this.textLayer
var EOL = "<span class='ace_invisible ace_invisible_eol'>" + textLayer.EOL_CHAR + "</span>"; var EOL = "<span class='ace_invisible ace_invisible_eol'>" + textLayer.EOL_CHAR + "</span>";
var SPACE = function(i) {return Array(i+1).join(" ")} var SPACE = function(i) {return Array(i+1).join("\xa0")}
var DOT = function(i) {return Array(i+1).join(textLayer.SPACE_CHAR)} var DOT = function(i) {return Array(i+1).join(textLayer.SPACE_CHAR)}
var TAB = function(i) {return Array(i+1).join(textLayer.TAB_CHAR)} var TAB = function(i) {return textLayer.TAB_CHAR + SPACE(i-1)}
function testRender(results) { function testRender(results) {
for (var i = results.length; i--; ) { for (var i = results.length; i--; ) {
var stringBuilder = []; var stringBuilder = [];

View file

@ -91,11 +91,6 @@ exports.toggleCssClass = function(el, name) {
return add; return add;
}; };
if (typeof document == "undefined") {
exports.importCssString = function() {};
return;
}
/* /*
* Add or remove a CSS class from the list of classes on the given node * Add or remove a CSS class from the list of classes on the given node
* depending on the value of <tt>include</tt> * depending on the value of <tt>include</tt>
@ -178,6 +173,9 @@ exports.getInnerHeight = function(element) {
}; };
if (typeof document == "undefined")
return;
if (window.pageYOffset !== undefined) { if (window.pageYOffset !== undefined) {
exports.getPageScrollTop = function() { exports.getPageScrollTop = function() {
return window.pageYOffset; return window.pageYOffset;

View file

@ -241,11 +241,12 @@ function normalizeCommandKeys(callback, e, keyCode) {
if (keyCode === 18 || keyCode === 17) { if (keyCode === 18 || keyCode === 17) {
var location = "location" in e ? e.location : e.keyLocation; var location = "location" in e ? e.location : e.keyLocation;
if (keyCode === 17 && location === 1) { if (keyCode === 17 && location === 1) {
if (pressedKeys[keyCode] == 1) ts = e.timeStamp;
ts = e.timeStamp;
} else if (keyCode === 18 && hashId === 3 && location === 2) { } else if (keyCode === 18 && hashId === 3 && location === 2) {
var dt = e.timeStamp - ts; var dt = -ts;
if (dt < 50) ts = e.timeStamp;
dt += ts;
if (dt < 3)
pressedKeys.altGr = true; pressedKeys.altGr = true;
} }
} }
@ -308,7 +309,7 @@ exports.addCommandKeyListener = function(el, callback) {
var lastDefaultPrevented = null; var lastDefaultPrevented = null;
addListener(el, "keydown", function(e) { addListener(el, "keydown", function(e) {
pressedKeys[e.keyCode] = (pressedKeys[e.keyCode] || 0) + 1; pressedKeys[e.keyCode] = true;
var result = normalizeCommandKeys(callback, e, e.keyCode); var result = normalizeCommandKeys(callback, e, e.keyCode);
lastDefaultPrevented = e.defaultPrevented; lastDefaultPrevented = e.defaultPrevented;
return result; return result;
@ -326,14 +327,13 @@ exports.addCommandKeyListener = function(el, callback) {
}); });
if (!pressedKeys) { if (!pressedKeys) {
resetPressedKeys(); pressedKeys = Object.create(null);
addListener(window, "focus", resetPressedKeys); addListener(window, "focus", function(e) {
pressedKeys = Object.create(null);
});
} }
} }
}; };
function resetPressedKeys(e) {
pressedKeys = Object.create(null);
}
if (window.postMessage && !useragent.isOldIE) { if (window.postMessage && !useragent.isOldIE) {
var postMessageId = 1; var postMessageId = 1;

View file

@ -104,8 +104,8 @@ var Keys = (function() {
73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o', 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v', 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.', 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`', 219: '[',
219: '[', 220: '\\',221: ']', 222: '\'' 220: '\\',221: ']', 222: '\''
} }
}; };

View file

@ -81,24 +81,20 @@ exports.copyArray = function(array){
return copy; return copy;
}; };
exports.deepCopy = function deepCopy(obj) { exports.deepCopy = function (obj) {
if (typeof obj !== "object" || !obj) if (typeof obj !== "object" || !obj)
return obj; return obj;
var copy;
if (Array.isArray(obj)) {
copy = [];
for (var key = 0; key < obj.length; key++) {
copy[key] = deepCopy(obj[key]);
}
return copy;
}
var cons = obj.constructor; var cons = obj.constructor;
if (cons === RegExp) if (cons === RegExp)
return obj; return obj;
copy = cons(); var copy = cons();
for (var key in obj) { for (var key in obj) {
copy[key] = deepCopy(obj[key]); if (typeof obj[key] === "object") {
copy[key] = exports.deepCopy(obj[key]);
} else {
copy[key] = obj[key];
}
} }
return copy; return copy;
}; };

View file

@ -113,16 +113,18 @@ function LineWidgets(session) {
}); });
}; };
this.updateOnChange = function(delta) { this.updateOnChange = function(e) {
var lineWidgets = this.session.lineWidgets; var lineWidgets = this.session.lineWidgets;
if (!lineWidgets) return; if (!lineWidgets) return;
var startRow = delta.start.row; var delta = e.data;
var len = delta.end.row - startRow; var range = delta.range;
var startRow = range.start.row;
var len = range.end.row - startRow;
if (len === 0) { if (len === 0) {
// return // return
} else if (delta.action == 'remove') { } else if (delta.action == "removeText" || delta.action == "removeLines") {
var removed = lineWidgets.splice(startRow + 1, len); var removed = lineWidgets.splice(startRow + 1, len);
removed.forEach(function(w) { removed.forEach(function(w) {
w && this.removeLineWidget(w); w && this.removeLineWidget(w);

View file

@ -13,7 +13,7 @@
[1, +1, -1, 12_345, 0.000_1, [1, +1, -1, 12_345, 0.000_1,
_, 3_1, 1_2, 1_.0, 0._1]; _, 3_1, 1_2, 1_.0, 0._1];
{:id => ?", :key => "value", anotherKey: [x, y?]} {:id => 34, :key => "value"}
=begin =begin
=end =end

File diff suppressed because it is too large Load diff

View file

@ -56,34 +56,34 @@
],[ ],[
"start", "start",
["text"," "], ["text"," "],
["comment","|"], ["comment","| "],
["string"," start "], ["string","start "],
["comment","|"], ["comment","| "],
["string"," eat "], ["string","eat "],
["comment","|"], ["comment","| "],
["string"," left "], ["string","left "],
["comment","|"] ["comment","|"]
],[ ],[
"start", "start",
["text"," "], ["text"," "],
["comment","|"], ["comment","| "],
["string"," 12 "], ["string"," 12 "],
["comment","|"], ["comment","| "],
["string"," 5 "], ["string"," 5 "],
["comment","|"], ["comment","| "],
["string"," 7 "], ["string"," 7 "],
["comment","|"] ["comment","|"]
],[ ],[
"start", "start",
["text"," "], ["text"," "],
["comment","|"], ["comment","| "],
["string"," 20 "], ["string"," 20 "],
["comment","|"], ["comment","| "],
["string"," 5 "], ["string"," 5 "],
["comment","|"], ["comment","| "],
["string"," 15 "], ["string"," 15 "],
["comment","|"], ["comment","| "],
["string"," "] ["string"," "]
],[ ],[
"start" "start"
],[ ],[

View file

@ -139,7 +139,7 @@
["text"," "], ["text"," "],
["punctuation.separator.key-value","=>"], ["punctuation.separator.key-value","=>"],
["text"," "], ["text"," "],
["string.character","?\""], ["constant.numeric","34"],
["text",", "], ["text",", "],
["constant.other.symbol.ruby",":key"], ["constant.other.symbol.ruby",":key"],
["text"," "], ["text"," "],
@ -148,15 +148,7 @@
["string.start","\""], ["string.start","\""],
["string","value"], ["string","value"],
["string.end","\""], ["string.end","\""],
["text",", "], ["paren.rparen","}"]
["identifier","anotherKey"],
["text",": "],
["paren.lparen","["],
["identifier","x"],
["text",", "],
["identifier","y"],
["text","?"],
["paren.rparen","]}"]
],[ ],[
"start" "start"
],[ ],[

View file

@ -10,9 +10,10 @@
],[ ],[
"start", "start",
["keyword.source.rust","fn"], ["keyword.source.rust","fn"],
["text"," "], ["meta.function.source.rust"," "],
["entity.name.function.source.rust","main"], ["entity.name.function.source.rust","main"],
["text","() {"] ["meta.function.source.rust","("],
["text",") {"]
],[ ],[
"start", "start",
["text"," "], ["text"," "],
@ -87,14 +88,10 @@
],[ ],[
"start", "start",
["keyword.source.rust","fn"], ["keyword.source.rust","fn"],
["text"," "], ["meta.function.source.rust"," "],
["entity.name.function.source.rust","map"], ["entity.name.function.source.rust","map<T, U>"],
["keyword.operator","<"], ["meta.function.source.rust","("],
["text","T"], ["text","vector: &[T]"],
["keyword.operator",","],
["text"," U"],
["keyword.operator",">"],
["text","(vector: &[T]"],
["keyword.operator",","], ["keyword.operator",","],
["text"," function: &fn(v: &T) "], ["text"," function: &fn(v: &T) "],
["keyword.operator","->"], ["keyword.operator","->"],

View file

@ -199,5 +199,7 @@
["string.quoted.double.asp"," ... updated.\""] ["string.quoted.double.asp"," ... updated.\""]
],[ ],[
"start", "start",
["storage.type.asp","End Sub"] ["support.function.asp","End"],
["text"," "],
["storage.type.asp","Sub"]
]] ]]

View file

@ -126,7 +126,7 @@ var AbapHighlightRules = function() {
{token : "string", regex : "`", next : "start"}, {token : "string", regex : "`", next : "start"},
{defaultToken : "string"} {defaultToken : "string"}
] ]
}; }
}; };
oop.inherits(AbapHighlightRules, TextHighlightRules); oop.inherits(AbapHighlightRules, TextHighlightRules);

View file

@ -1,58 +0,0 @@
/* ***** 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 ***** */
/*
THIS FILE WAS AUTOGENERATED BY mode.tmpl.js
*/
define(function (require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var ABCHighlightRules = require("./abc_highlight_rules").ABCHighlightRules;
// TODO: pick appropriate fold mode
var FoldMode = require("./folding/cstyle").FoldMode;
var Mode = function () {
this.HighlightRules = ABCHighlightRules;
this.foldingRules = new FoldMode();
};
oop.inherits(Mode, TextMode);
(function () {
// this.lineCommentStart = ""%.*"";
// this.blockComment = {start: ""/*"", end: ""*/""};
// Extra logic goes here.
this.$id = "ace/mode/abc"
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -1,114 +0,0 @@
/* This file was partially autogenerated from https://github.com/jimhawkridge/SublimeABC
Modifications
- more classes to express the abc semantic
- added syntax highlighting for Zupfnoter conventions (https://github.com/bwl21/zupfnoter)
- separate note pitch and note duration - even if it looks the same
***********************************************************************************************/
define(function (require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var ABCHighlightRules = function () {
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules = {
start: [
{
token: ['zupfnoter.information.comment.line.percentage', 'information.keyword', 'in formation.keyword.embedded'],
regex: '(%%%%)(hn\\.[a-z]*)(.*)',
comment: 'Instruction Comment'
},
{
token: ['information.comment.line.percentage', 'information.keyword.embedded'],
regex: '(%%)(.*)',
comment: 'Instruction Comment'
},
{
token: 'comment.line.percentage',
regex: '%.*',
comment: 'Comments'
},
{
token: 'barline.keyword.operator',
regex: '[\\[:]*[|:][|\\]:]*(?:\\[?[0-9]+)?|\\[[0-9]+',
comment: 'Bar lines'
},
{
token: ['information.keyword.embedded', 'information.argument.string.unquoted'],
regex: '(\\[[A-Za-z]:)([^\\]]*\\])',
comment: 'embedded Header lines'
},
{
token: ['information.keyword', 'information.argument.string.unquoted'],
regex: '^([A-Za-z]:)([^%\\\\]*)',
comment: 'Header lines'
},
{
token: ['text', 'entity.name.function', 'string.unquoted', 'text'],
regex: '(\\[)([A-Z]:)(.*?)(\\])',
comment: 'Inline fields'
},
{
token: ['accent.constant.language', 'pitch.constant.numeric', 'duration.constant.numeric'],
regex: '([\\^=_]*)([A-Ga-gz][,\']*)([0-9]*/*[><0-9]*)',
comment: 'Notes'
},
{
token: 'zupfnoter.jumptarget.string.quoted',
regex: '[\\"!]\\^\\:.*?[\\"!]',
comment: 'Zupfnoter jumptarget'
}, {
token: 'zupfnoter.goto.string.quoted',
regex: '[\\"!]\\^\\@.*?[\\"!]',
comment: 'Zupfnoter goto'
},
{
token: 'zupfnoter.annotation.string.quoted',
regex: '[\\"!]\\^\\!.*?[\\"!]',
comment: 'Zupfnoter annoation'
},
{
token: 'zupfnoter.annotationref.string.quoted',
regex: '[\\"!]\\^\\#.*?[\\"!]',
comment: 'Zupfnoter annotation reference'
},
{
token: 'chordname.string.quoted',
regex: '[\\"!]\\^.*?[\\"!]',
comment: 'abc chord'
},
{
token: 'string.quoted',
regex: '[\\"!].*?[\\"!]',
comment: 'abc annotation'
}
]
};
// this.embedRules(JsonHighlightRules, "json-")
this.normalizeRules();
};
ABCHighlightRules.metaData = {
fileTypes: ['abc'],
name: 'ABC',
scopeName: 'text.abcnotation'
};
oop.inherits(ABCHighlightRules, TextHighlightRules);
exports.ABCHighlightRules = ABCHighlightRules;
});

View file

@ -30,7 +30,6 @@
if (typeof process !== "undefined") { if (typeof process !== "undefined") {
require("amd-loader"); require("amd-loader");
require("../../test/mockdom");
} }
define(function(require, exports, module) { define(function(require, exports, module) {
@ -43,7 +42,6 @@ var Editor = require("../../editor").Editor;
var EditSession = require("../../edit_session").EditSession; var EditSession = require("../../edit_session").EditSession;
var MockRenderer = require("../../test/mockrenderer").MockRenderer; var MockRenderer = require("../../test/mockrenderer").MockRenderer;
var JavaScriptMode = require("../javascript").Mode; var JavaScriptMode = require("../javascript").Mode;
var XMLMode = require("../xml").Mode;
var editor; var editor;
var exec = function(name, times, args) { var exec = function(name, times, args) {
do { do {
@ -119,9 +117,9 @@ module.exports = {
editor.setValue(""); editor.setValue("");
exec("insertstring", 1, "{"); exec("insertstring", 1, "{");
assert.equal(editor.getValue(), "{"); assert.equal(editor.getValue(), "{")
exec("insertstring", 1, "\n"); exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), "{\n \n}"); assert.equal(editor.getValue(), "{\n \n}")
editor.setValue(""); editor.setValue("");
exec("insertstring", 1, "("); exec("insertstring", 1, "(");
@ -131,44 +129,6 @@ module.exports = {
exec("backspace", 1); exec("backspace", 1);
exec("insertstring", 1, '"'); exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("")'); assert.equal(editor.getValue(), '("")');
editor.setValue("('foo')", 1);
exec("gotoleft", 1);
exec("selectleft", 1);
exec("selectMoreBefore", 1);
exec("insertstring", 1, "'");
assert.equal(editor.getValue(), "('foo')");
exec("selectleft", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("foo")');
exec("selectleft", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '("foo")');
editor.setValue("", 1);
exec("selectleft", 1);
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '""');
exec("insertstring", 1, '\\');
exec("insertstring", 1, 'n');
exec("insertstring", 1, '"');
assert.equal(editor.getValue(), '"\\n"');
},
"test: xml": function() {
editor = new Editor(new MockRenderer());
editor.setValue(["<OuterTag>",
" <SelfClosingTag />"
].join("\n"));
editor.session.setMode(new XMLMode);
exec("gotolinedown", 1);
exec("gotolineend", 1);
exec("insertstring", 1, '\n');
assert.equal(editor.session.getLine(2), " ");
exec("gotolineup", 1);
exec("gotolineend", 1);
exec("insertstring", 1, '\n');
assert.equal(editor.session.getLine(2), " ");
} }
}; };

View file

@ -63,19 +63,6 @@ var initContext = function(editor) {
}; };
}; };
var getWrapped = function(selection, selected, opening, closing) {
var rowDiff = selection.end.row - selection.start.row;
return {
text: opening + selected + closing,
selection: [
0,
selection.start.column + 1,
rowDiff,
selection.end.column + (rowDiff ? 0 : 1)
]
};
};
var CstyleBehaviour = function() { var CstyleBehaviour = function() {
this.add("braces", "insertion", function(state, action, editor, session, text) { this.add("braces", "insertion", function(state, action, editor, session, text) {
var cursor = editor.getCursorPosition(); var cursor = editor.getCursorPosition();
@ -85,7 +72,10 @@ var CstyleBehaviour = function() {
var selection = editor.getSelectionRange(); var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection); var selected = session.doc.getTextRange(selection);
if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) { if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
return getWrapped(selection, selected, '{', '}'); return {
text: '{' + selected + '}',
selection: false
};
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) { if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
CstyleBehaviour.recordAutoInsert(editor, session, "}"); CstyleBehaviour.recordAutoInsert(editor, session, "}");
@ -165,7 +155,10 @@ var CstyleBehaviour = function() {
var selection = editor.getSelectionRange(); var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection); var selected = session.doc.getTextRange(selection);
if (selected !== "" && editor.getWrapBehavioursEnabled()) { if (selected !== "" && editor.getWrapBehavioursEnabled()) {
return getWrapped(selection, selected, '(', ')'); return {
text: '(' + selected + ')',
selection: false
};
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
CstyleBehaviour.recordAutoInsert(editor, session, ")"); CstyleBehaviour.recordAutoInsert(editor, session, ")");
return { return {
@ -210,7 +203,10 @@ var CstyleBehaviour = function() {
var selection = editor.getSelectionRange(); var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection); var selected = session.doc.getTextRange(selection);
if (selected !== "" && editor.getWrapBehavioursEnabled()) { if (selected !== "" && editor.getWrapBehavioursEnabled()) {
return getWrapped(selection, selected, '[', ']'); return {
text: '[' + selected + ']',
selection: false
};
} else if (CstyleBehaviour.isSaneInsertion(editor, session)) { } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
CstyleBehaviour.recordAutoInsert(editor, session, "]"); CstyleBehaviour.recordAutoInsert(editor, session, "]");
return { return {
@ -256,8 +252,11 @@ var CstyleBehaviour = function() {
var selection = editor.getSelectionRange(); var selection = editor.getSelectionRange();
var selected = session.doc.getTextRange(selection); var selected = session.doc.getTextRange(selection);
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) { if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
return getWrapped(selection, selected, quote, quote); return {
} else if (!selected) { text: quote + selected + quote,
selection: false
};
} else {
var cursor = editor.getCursorPosition(); var cursor = editor.getCursorPosition();
var line = session.doc.getLine(cursor.row); var line = session.doc.getLine(cursor.row);
var leftChar = line.substring(cursor.column-1, cursor.column); var leftChar = line.substring(cursor.column-1, cursor.column);
@ -269,8 +268,8 @@ var CstyleBehaviour = function() {
if (leftChar == "\\" && token && /escape/.test(token.type)) if (leftChar == "\\" && token && /escape/.test(token.type))
return null; return null;
var stringBefore = token && /string|escape/.test(token.type); var stringBefore = token && /string/.test(token.type);
var stringAfter = !rightToken || /string|escape/.test(rightToken.type); var stringAfter = !rightToken || /string/.test(rightToken.type);
var pair; var pair;
if (rightChar == quote) { if (rightChar == quote) {
@ -279,7 +278,7 @@ var CstyleBehaviour = function() {
if (stringBefore && !stringAfter) if (stringBefore && !stringAfter)
return null; // wrap string with different quote return null; // wrap string with different quote
if (stringBefore && stringAfter) if (stringBefore && stringAfter)
return null; // do not pair quotes inside strings return null; // do not pair quotes inside strings
var wordRe = session.$mode.tokenRe; var wordRe = session.$mode.tokenRe;
wordRe.lastIndex = 0; wordRe.lastIndex = 0;
var isWordBefore = wordRe.test(leftChar); var isWordBefore = wordRe.test(leftChar);

View file

@ -155,8 +155,6 @@ var XmlBehaviour = function () {
var token = iterator.getCurrentToken(); var token = iterator.getCurrentToken();
if (token && token.type.indexOf("tag-close") !== -1) { if (token && token.type.indexOf("tag-close") !== -1) {
if (token.value == "/>")
return;
//get tag name //get tag name
while (token && token.type.indexOf("tag-name") === -1) { while (token && token.type.indexOf("tag-name") === -1) {
token = iterator.stepBackward(); token = iterator.stepBackward();

View file

@ -18,13 +18,13 @@ var c_cppHighlightRules = function() {
var storageType = ( var storageType = (
"asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" + "asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" +
"_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void|" + "_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void|" +
"class|wchar_t|template|char16_t|char32_t" "class|wchar_t|template"
); );
var storageModifiers = ( var storageModifiers = (
"const|extern|register|restrict|static|volatile|inline|private|" + "const|extern|register|restrict|static|volatile|inline|private|" +
"protected|public|friend|explicit|virtual|export|mutable|typename|" + "protected|public|friend|explicit|virtual|export|mutable|typename|" +
"constexpr|new|delete|alignas|alignof|decltype|noexcept|thread_local" "constexpr|new|delete"
); );
var keywordOperators = ( var keywordOperators = (
@ -33,7 +33,7 @@ var c_cppHighlightRules = function() {
); );
var builtinConstants = ( var builtinConstants = (
"NULL|true|false|TRUE|FALSE|nullptr" "NULL|true|false|TRUE|FALSE"
); );
var keywordMapper = this.$keywords = this.createKeywordMapper({ var keywordMapper = this.$keywords = this.createKeywordMapper({

View file

@ -116,11 +116,11 @@ oop.inherits(Mode, TextMode);
var worker = new WorkerClient(["ace"], "ace/mode/coffee_worker", "Worker"); var worker = new WorkerClient(["ace"], "ace/mode/coffee_worker", "Worker");
worker.attachToDocument(session.getDocument()); worker.attachToDocument(session.getDocument());
worker.on("annotate", function(e) { worker.on("error", function(e) {
session.setAnnotations(e.data); session.setAnnotations([e.data]);
}); });
worker.on("terminate", function() { worker.on("ok", function(e) {
session.clearAnnotations(); session.clearAnnotations();
}); });

View file

@ -49,13 +49,13 @@ oop.inherits(Worker, Mirror);
this.onUpdate = function() { this.onUpdate = function() {
var value = this.doc.getValue(); var value = this.doc.getValue();
var errors = [];
try { try {
coffee.parse(value).compile(); coffee.parse(value).compile();
} catch(e) { } catch(e) {
var loc = e.location; var loc = e.location;
if (loc) { if (loc) {
errors.push({ this.sender.emit("error", {
row: loc.first_line, row: loc.first_line,
column: loc.first_column, column: loc.first_column,
endRow: loc.last_line, endRow: loc.last_line,
@ -64,8 +64,9 @@ oop.inherits(Worker, Mirror);
type: "error" type: "error"
}); });
} }
return;
} }
this.sender.emit("annotate", errors); this.sender.emit("ok");
}; };
}).call(Worker.prototype); }).call(Worker.prototype);

View file

@ -81,7 +81,7 @@ oop.inherits(Mode, TextMode);
var worker = new WorkerClient(["ace"], "ace/mode/css_worker", "Worker"); var worker = new WorkerClient(["ace"], "ace/mode/css_worker", "Worker");
worker.attachToDocument(session.getDocument()); worker.attachToDocument(session.getDocument());
worker.on("annotate", function(e) { worker.on("csslint", function(e) {
session.setAnnotations(e.data); session.setAnnotations(e.data);
}); });

View file

@ -41,7 +41,7 @@ var supportType = exports.supportType = "animation-fill-mode|alignment-adjust|al
var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters"; var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters";
var supportConstant = exports.supportConstant = "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero"; var supportConstant = exports.supportConstant = "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero";
var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow"; var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow";
var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|cursive|fantasy|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace"; var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace";
var numRe = exports.numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))"; var numRe = exports.numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b"; var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b";

View file

@ -80,11 +80,11 @@ oop.inherits(Worker, Mirror);
this.onUpdate = function() { this.onUpdate = function() {
var value = this.doc.getValue(); var value = this.doc.getValue();
if (!value) if (!value)
return this.sender.emit("annotate", []); return this.sender.emit("csslint", []);
var infoRules = this.infoRules; var infoRules = this.infoRules;
var result = CSSLint.verify(value, this.ruleset); var result = CSSLint.verify(value, this.ruleset);
this.sender.emit("annotate", result.messages.map(function(msg) { this.sender.emit("csslint", result.messages.map(function(msg) {
return { return {
row: msg.line - 1, row: msg.line - 1,
column: msg.col - 1, column: msg.col - 1,

View file

@ -53,7 +53,7 @@ oop.inherits(FoldMode, BaseFoldMode);
this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/; this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/; this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/; this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/; this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
//prevent naming conflict with any modes that inherit from cstyle and override this (like csharp) //prevent naming conflict with any modes that inherit from cstyle and override this (like csharp)
this._getFoldWidgetBase = this.getFoldWidget; this._getFoldWidgetBase = this.getFoldWidget;
@ -69,8 +69,6 @@ oop.inherits(FoldMode, BaseFoldMode);
* *
* @example tripleStarFoldingSection * @example tripleStarFoldingSection
* /*** this folds even though 1 line because it has 3 stars ***[/] * /*** this folds even though 1 line because it has 3 stars ***[/]
*
* @note the pound symbol for region tags is optional
*/ */
this.getFoldWidget = function(session, foldStyle, row) { this.getFoldWidget = function(session, foldStyle, row) {
var line = session.getLine(row); var line = session.getLine(row);
@ -160,16 +158,12 @@ oop.inherits(FoldMode, BaseFoldMode);
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length); return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
}; };
/**
* gets comment region block with end region assumed to be start of comment in any cstyle mode or SQL mode (--) which inherits from this.
* There may optionally be a pound symbol before the region/endregion statement
*/
this.getCommentRegionBlock = function(session, line, row) { this.getCommentRegionBlock = function(session, line, row) {
var startColumn = line.search(/\s*$/); var startColumn = line.search(/\s*$/);
var maxRow = session.getLength(); var maxRow = session.getLength();
var startRow = row; var startRow = row;
var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/; var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
var depth = 1; var depth = 1;
while (++row < maxRow) { while (++row < maxRow) {
line = session.getLine(row); line = session.getLine(row);

View file

@ -1,111 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, 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 oop = require("../../lib/oop");
var Range = require("../../range").Range;
var BaseFoldMode = require("./cstyle").FoldMode;
var FoldMode = exports.FoldMode = function() {};
oop.inherits(FoldMode, BaseFoldMode);
(function() {
/**
* Inheriting cstyle folding because it handles the region comment folding
* and special block comment folding appropriately.
*
* Cstyle's getCommentRegionBlock() contains the sql comment characters '--' for end region block.
*/
this.foldingStartMarker = /(\bCASE\b|\bBEGIN\b)|^\s*(\/\*)/i;
// this.foldingStopMarker = /(\bEND\b)|^[\s\*]*(\*\/)/i;
this.startRegionRe = /^\s*(\/\*|--)#?region\b/;
this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
var line = session.getLine(row);
if (this.startRegionRe.test(line)) return this.getCommentRegionBlock(session, line, row);
var match = line.match(this.foldingStartMarker);
if (match) {
var i = match.index;
if (match[1]) return this.getBeginEndBlock(session, row, i, match[1]);
var range = session.getCommentFoldRange(row, i + match[0].length, 1);
if (range && !range.isMultiLine()) {
if (forceMultiline) {
range = this.getSectionRange(session, row);
}
else if (foldStyle != "all") range = null;
}
return range;
}
if (foldStyle === "markbegin") return;
//TODO: add support for end folding markers
return;
};
/**
* @returns {range} folding block for sequence that starts with 'CASE' or 'BEGIN' and ends with 'END'
* @param {string} matchSequence - the sequence of charaters that started the fold widget, which should remain visible when the fold widget is folded
*/
this.getBeginEndBlock = function(session, row, column, matchSequence) {
var start = {
row: row,
column: column + matchSequence.length
};
var maxRow = session.getLength();
var line;
var depth = 1;
var re = /(\bCASE\b|\bBEGIN\b)|(\bEND\b)/i;
while (++row < maxRow) {
line = session.getLine(row);
var m = re.exec(line);
if (!m) continue;
if (m[1]) depth++;
else depth--;
if (!depth) break;
}
var endRow = row;
if (endRow > start.row) {
return new Range(start.row, start.column, endRow, line.length);
}
};
}).call(FoldMode.prototype);
});

View file

@ -36,18 +36,18 @@ var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]
var GherkinHighlightRules = function() { var GherkinHighlightRules = function() {
// need to include constant ints // need to include constant ints
this.$rules = { this.$rules = {
start : [{ start : [{
token: 'constant.numeric', token: 'constant.numeric',
regex: "(?:(?:[1-9]\\d*)|(?:0))" regex: "(?:(?:[1-9]\\d*)|(?:0))"
}, { }, {
token : "comment", token : "comment",
regex : "#.*$" regex : "#.*$"
}, { }, {
token : "keyword", token : "keyword",
regex : "Feature:|Background:|Scenario:|Scenario\ Outline:|Examples:|Given|When|Then|And|But|\\*", regex : "Feature:|Background:|Scenario:|Scenario\ Outline:|Examples:|Given|When|Then|And|But|\\*",
}, { }, {
token : "string", // multi line """ string start token : "string", // multi line """ string start
regex : '"{3}', regex : '"{3}',
next : "qqstring3" next : "qqstring3"
@ -56,22 +56,22 @@ var GherkinHighlightRules = function() {
regex : '"', regex : '"',
next : "qqstring" next : "qqstring"
}, { }, {
token : "comment", token : "comment",
regex : "@[A-Za-z0-9]+", regex : "@[A-Za-z0-9]+",
next : "start" next : "start"
}, { }, {
token : "comment", token : "comment",
regex : "<.+>" regex : "<.+>"
}, { }, {
token : "comment", token : "comment",
regex : "\\|(?=.)", regex : "\\| ",
next : "table-item" next : "table-item"
}, { }, {
token : "comment", token : "comment",
regex : "\\|$", regex : "\\|$",
next : "start" next : "start"
}], }],
"qqstring3" : [ { "qqstring3" : [ {
token : "constant.language.escape", token : "constant.language.escape",
regex : stringEscape regex : stringEscape
}, { }, {
@ -81,7 +81,7 @@ var GherkinHighlightRules = function() {
}, { }, {
defaultToken : "string" defaultToken : "string"
}], }],
"qqstring" : [{ "qqstring" : [{
token : "constant.language.escape", token : "constant.language.escape",
regex : stringEscape regex : stringEscape
}, { }, {
@ -96,19 +96,15 @@ var GherkinHighlightRules = function() {
defaultToken: "string" defaultToken: "string"
}], }],
"table-item" : [{ "table-item" : [{
token : "comment",
regex : /$/,
next : "start"
}, {
token : "comment",
regex : /\|/
}, {
token : "string", token : "string",
regex : /\\./ regex : "[A-Za-z0-9 ]*",
}, { next : "start"
defaultToken : "string" }],
}]
}; };
//new TextHighlightRules().getRules();
} }
oop.inherits(GherkinHighlightRules, TextHighlightRules); oop.inherits(GherkinHighlightRules, TextHighlightRules);

View file

@ -13,6 +13,7 @@ var Mode = function() {
HtmlMode.call(this); HtmlMode.call(this);
this.HighlightRules = HandlebarsHighlightRules; this.HighlightRules = HandlebarsHighlightRules;
this.$behaviour = new HtmlBehaviour(); this.$behaviour = new HtmlBehaviour();
this.foldingRules = new HtmlFoldMode(); this.foldingRules = new HtmlFoldMode();
}; };
@ -20,7 +21,7 @@ var Mode = function() {
oop.inherits(Mode, HtmlMode); oop.inherits(Mode, HtmlMode);
(function() { (function() {
this.blockComment = {start: "{{!--", end: "--}}"}; this.blockComment = {start: "{!--", end: "--}"};
this.$id = "ace/mode/handlebars"; this.$id = "ace/mode/handlebars";
}).call(Mode.prototype); }).call(Mode.prototype);

View file

@ -65,7 +65,7 @@ var HtmlHighlightRules = function() {
include : "tag_whitespace" include : "tag_whitespace"
}, { }, {
token : "entity.other.attribute-name.xml", token : "entity.other.attribute-name.xml",
regex : "[-_a-zA-Z0-9:.]+" regex : "[-_a-zA-Z0-9:]+"
}, { }, {
token : "keyword.operator.attribute-equals.xml", token : "keyword.operator.attribute-equals.xml",
regex : "=", regex : "=",
@ -89,7 +89,7 @@ var HtmlHighlightRules = function() {
return ["meta.tag.punctuation." + (start == "<" ? "" : "end-") + "tag-open.xml", return ["meta.tag.punctuation." + (start == "<" ? "" : "end-") + "tag-open.xml",
"meta.tag" + (group ? "." + group : "") + ".tag-name.xml"]; "meta.tag" + (group ? "." + group : "") + ".tag-name.xml"];
}, },
regex : "(</?)([-_a-zA-Z0-9:.]+)", regex : "(</?)([-_a-zA-Z0-9:]+)",
next: "tag_stuff" next: "tag_stuff"
}], }],
tag_stuff: [ tag_stuff: [

View file

@ -98,7 +98,7 @@ oop.inherits(Mode, TextMode);
var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker"); var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
worker.attachToDocument(session.getDocument()); worker.attachToDocument(session.getDocument());
worker.on("annotate", function(results) { worker.on("jslint", function(results) {
session.setAnnotations(results.data); session.setAnnotations(results.data);
}); });

File diff suppressed because it is too large Load diff

View file

@ -172,7 +172,7 @@ var JavaScriptHighlightRules = function(options) {
regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/ regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
}, { }, {
token : ["punctuation.operator", "support.function.dom"], token : ["punctuation.operator", "support.function.dom"],
regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName|ClassName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/ regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
}, { }, {
token : ["punctuation.operator", "support.constant"], token : ["punctuation.operator", "support.constant"],
regex : /(\.)(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/ regex : /(\.)(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/

View file

@ -116,10 +116,12 @@ oop.inherits(JavaScriptWorker, Mirror);
this.onUpdate = function() { this.onUpdate = function() {
var value = this.doc.getValue(); var value = this.doc.getValue();
value = value.replace(/^#!.*\n/, "\n"); value = value.replace(/^#!.*\n/, "\n");
if (!value) if (!value) {
return this.sender.emit("annotate", []); this.sender.emit("jslint", []);
return;
}
var errors = []; var errors = [];
// jshint reports many false errors // jshint reports many false errors
// report them as error only if code is actually invalid // report them as error only if code is actually invalid
var maxErrorLevel = this.isValidJS(value) ? "warning" : "error"; var maxErrorLevel = this.isValidJS(value) ? "warning" : "error";
@ -177,7 +179,7 @@ oop.inherits(JavaScriptWorker, Mirror);
} }
// console.log("lint time: " + (new Date() - start)); // console.log("lint time: " + (new Date() - start));
this.sender.emit("annotate", errors); this.sender.emit("jslint", errors);
}; };
}).call(JavaScriptWorker.prototype); }).call(JavaScriptWorker.prototype);

View file

@ -74,11 +74,11 @@ oop.inherits(Mode, TextMode);
var worker = new WorkerClient(["ace"], "ace/mode/json_worker", "JsonWorker"); var worker = new WorkerClient(["ace"], "ace/mode/json_worker", "JsonWorker");
worker.attachToDocument(session.getDocument()); worker.attachToDocument(session.getDocument());
worker.on("annotate", function(e) { worker.on("error", function(e) {
session.setAnnotations(e.data); session.setAnnotations([e.data]);
}); });
worker.on("terminate", function() { worker.on("ok", function() {
session.clearAnnotations(); session.clearAnnotations();
}); });

View file

@ -46,20 +46,21 @@ oop.inherits(JsonWorker, Mirror);
this.onUpdate = function() { this.onUpdate = function() {
var value = this.doc.getValue(); var value = this.doc.getValue();
var errors = [];
try { try {
if (value) if (value)
parse(value); parse(value);
} catch (e) { } catch (e) {
var pos = this.doc.indexToPosition(e.at-1); var pos = this.doc.indexToPosition(e.at-1);
errors.push({ this.sender.emit("error", {
row: pos.row, row: pos.row,
column: pos.column, column: pos.column,
text: e.message, text: e.message,
type: "error" type: "error"
}); });
return;
} }
this.sender.emit("annotate", errors); this.sender.emit("ok");
}; };
}).call(JsonWorker.prototype); }).call(JsonWorker.prototype);

View file

@ -58,7 +58,7 @@ module.exports = {
worker.setValue("{}"); worker.setValue("{}");
worker.deferredUpdate.call(); worker.deferredUpdate.call();
assert.equal(this.sender.events[0][1].length, 0); assert.equal(this.sender.events[0][0], "ok");
}, },
"test check for syntax error": function() { "test check for syntax error": function() {
@ -71,12 +71,11 @@ module.exports = {
worker.deferredUpdate.call(); worker.deferredUpdate.call();
var event = this.sender.events[0]; var event = this.sender.events[0];
assert.equal(event[0], "annotate"); assert.equal(event[0], "error");
assert.equal(event[1].length, 1); assert.equal(event[1].type, "error");
assert.equal(event[1][0].type, "error"); assert.equal(event[1].text, "Bad string");
assert.equal(event[1][0].text, "Bad string"); assert.equal(event[1].row, 1);
assert.equal(event[1][0].row, 1); assert.equal(event[1].column, 0);
assert.equal(event[1][0].column, 0);
}, },
@ -86,11 +85,11 @@ module.exports = {
worker.deferredUpdate.call(); worker.deferredUpdate.call();
var event = this.sender.events[0]; var event = this.sender.events[0];
assert.equal(event[0], "annotate"); assert.equal(event[0], "error");
assert.equal(event[1][0].type, "error"); assert.equal(event[1].type, "error");
assert.equal(event[1][0].text, "Unexpected 'x'"); assert.equal(event[1].text, "Unexpected 'x'");
assert.equal(event[1][0].row, 0); assert.equal(event[1].row, 0);
assert.equal(event[1][0].column, 0); assert.equal(event[1].column, 0);
} }
}; };

View file

@ -1,101 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, 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 oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var leanHighlightRules = require("./lean_highlight_rules").leanHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
// TODO(soonhok): figure out behavior and foldmode
// var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
// var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var Mode = function() {
this.HighlightRules = leanHighlightRules;
this.$outdent = new MatchingBraceOutdent();
// this.$behaviour = new CstyleBehaviour();
// this.foldingRules = new CStyleFoldMode();
};
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "--";
this.blockComment = {start: "/-", end: "-/"};
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
var tokens = tokenizedLine.tokens;
var endState = tokenizedLine.state;
if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent;
}
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
}
} else if (state == "doc-start") {
if (endState == "start") {
return "";
}
var match = line.match(/^\s*(\/?)\*/);
if (match) {
if (match[1]) {
indent += " ";
}
indent += "- ";
}
}
return indent;
};
this.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
this.$id = "ace/mode/lean";
}).call(Mode.prototype);
exports.Mode = Mode;
});

View file

@ -1,156 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, 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 oop = require("../lib/oop");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var leanHighlightRules = function() {
var keywordControls = (
[ "add_rewrite", "alias", "as", "assume", "attribute",
"begin", "by", "calc", "calc_refl", "calc_subst", "calc_trans", "check",
"classes", "coercions", "conjecture", "constants", "context",
"corollary", "else", "end", "environment", "eval", "example",
"exists", "exit", "export", "exposing", "extends", "fields", "find_decl",
"forall", "from", "fun", "have", "help", "hiding", "if",
"import", "in", "infix", "infixl", "infixr", "instances",
"let", "local", "match", "namespace", "notation", "obtain", "obtains",
"omit", "opaque", "open", "options", "parameter", "parameters", "postfix",
"precedence", "prefix", "premise", "premises", "print", "private", "proof",
"protected", "qed", "raw", "renaming", "section", "set_option",
"show", "tactic_hint", "take", "then", "universe",
"universes", "using", "variable", "variables", "with"].join("|")
);
var nameProviders = (
["inductive", "structure", "record", "theorem", "axiom",
"axioms", "lemma", "hypothesis", "definition", "constant"].join("|")
);
var storageType = (
["Prop", "Type", "Type'", "Type₊", "Type₁", "Type₂", "Type₃"].join("|")
);
var storageModifiers = (
"\\[(" +
["abbreviations", "all-transparent", "begin-end-hints", "class", "classes", "coercion",
"coercions", "declarations", "decls", "instance", "irreducible",
"multiple-instances", "notation", "notations", "parsing-only", "persistent",
"reduce-hints", "reducible", "tactic-hints", "visible", "wf", "whnf"
].join("|") +
")\\]"
);
var keywordOperators = (
[].join("|")
);
var keywordMapper = this.$keywords = this.createKeywordMapper({
"keyword.control" : keywordControls,
"storage.type" : storageType,
"keyword.operator" : keywordOperators,
"variable.language": "sorry",
}, "identifier");
var identifierRe = "[A-Za-z_\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2100-\u214f][A-Za-z0-9_'\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2070-\u2079\u207f-\u2089\u2090-\u209c\u2100-\u214f]*";
var operatorRe = new RegExp(["#", "@", "->", "", "↔", "/", "==", "=", ":=", "<->",
"/\\", "\\/", "∧", "", "≠", "<", ">", "≤", "≥", "¬",
"<=", ">=", "⁻¹", "⬝", "▸", "\\+", "\\*", "-", "/",
"λ", "→", "∃", "∀", ":="].join("|"));
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules = {
"start" : [
{
token : "comment", // single line comment "--"
regex : "--.*$"
},
DocCommentHighlightRules.getStartRule("doc-start"),
{
token : "comment", // multi line comment "/-"
regex : "\\/-",
next : "comment"
}, {
stateName: "qqstring",
token : "string.start", regex : '"', next : [
{token : "string.end", regex : '"', next : "start"},
{token : "constant.language.escape", regex : /\\[n"\\]/},
{defaultToken: "string"}
]
}, {
token : "keyword.control", regex : nameProviders, next : [
{token : "variable.language", regex : identifierRe, next : "start"} ]
}, {
token : "constant.numeric", // hex
regex : "0[xX][0-9a-fA-F]+(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
}, {
token : "constant.numeric", // float
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
}, {
token : "storage.modifier",
regex : storageModifiers
}, {
token : keywordMapper,
regex : identifierRe
}, {
token : "operator",
regex : operatorRe
}, {
token : "punctuation.operator",
regex : "\\?|\\:|\\,|\\;|\\."
}, {
token : "paren.lparen",
regex : "[[({]"
}, {
token : "paren.rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
],
"comment" : [ {token: "comment", regex: "-/", next: "start"},
{defaultToken: "comment"} ]
};
this.embedRules(DocCommentHighlightRules, "doc-",
[ DocCommentHighlightRules.getEndRule("start") ]);
this.normalizeRules();
};
oop.inherits(leanHighlightRules, TextHighlightRules);
exports.leanHighlightRules = leanHighlightRules;
});

View file

@ -231,7 +231,7 @@ var LessHighlightRules = function() {
regex: "\\.[a-z0-9-_]+" regex: "\\.[a-z0-9-_]+"
}, { }, {
token: "variable.language", token: "variable.language",
regex: ":[a-z_][a-z0-9-_]*" regex: ":[a-z0-9-_]+"
}, { }, {
token: "constant", token: "constant",
regex: "[a-z0-9-_]+" regex: "[a-z0-9-_]+"

Some files were not shown because too many files have changed in this diff Show more