mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Merge remote-tracking branch 'upstream/master'
# Conflicts: # jquery.tooltipster/jquery.tooltipster-tests.ts # jquery.tooltipster/jquery.tooltipster.d.ts
This commit is contained in:
+6
-1
@@ -9,7 +9,6 @@
|
||||
*.cs
|
||||
*.sln
|
||||
*.csproj
|
||||
*.txt
|
||||
*.map
|
||||
*.swp
|
||||
.DS_Store
|
||||
@@ -30,8 +29,14 @@ _infrastructure/tests/build
|
||||
*.iml
|
||||
*.js.map
|
||||
!*.js/
|
||||
!scripts/new-package.js
|
||||
!scripts/not-needed.js
|
||||
!scripts/lint.js
|
||||
|
||||
node_modules
|
||||
|
||||
.sublimets
|
||||
.settings/launch.json
|
||||
|
||||
.vscode
|
||||
yarn.lock
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 4
|
||||
- 6.9.2
|
||||
|
||||
sudo: false
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import packer = require("3d-bin-packing");
|
||||
import samchon = require("samchon-framework");
|
||||
|
||||
function main(): void
|
||||
{
|
||||
///////////////////////////
|
||||
// CONSTRUCT OBJECTS
|
||||
///////////////////////////
|
||||
let wrapperArray: bws.packer.WrapperArray = new packer.WrapperArray();
|
||||
let instanceArray: bws.packer.InstanceArray = new packer.InstanceArray();
|
||||
|
||||
// Wrappers
|
||||
wrapperArray.push
|
||||
(
|
||||
new packer.Wrapper("Large", 1000, 40, 40, 15, 0),
|
||||
new packer.Wrapper("Medium", 700, 20, 20, 10, 0),
|
||||
new packer.Wrapper("Small", 500, 15, 15, 8, 0)
|
||||
);
|
||||
|
||||
///////
|
||||
// Each Instance is repeated #15
|
||||
///////
|
||||
instanceArray.insert(instanceArray.end(), 15, new packer.Product("Eraser", 1, 2, 5));
|
||||
instanceArray.insert(instanceArray.end(), 15, new packer.Product("Book", 15, 30, 3));
|
||||
instanceArray.insert(instanceArray.end(), 15, new packer.Product("Drink", 3, 3, 10));
|
||||
instanceArray.insert(instanceArray.end(), 15, new packer.Product("Umbrella", 5, 5, 20));
|
||||
|
||||
// Wrappers also can be packed into another Wrapper.
|
||||
instanceArray.insert(instanceArray.end(), 15, new packer.Wrapper("Notebook-Box", 2000, 30, 40, 4, 2));
|
||||
instanceArray.insert(instanceArray.end(), 15, new packer.Wrapper("Tablet-Box", 2500, 20, 28, 2, 0));
|
||||
|
||||
///////////////////////////
|
||||
// BEGINS PACKING
|
||||
///////////////////////////
|
||||
// CONSTRUCT PACKER
|
||||
let my_packer: bws.packer.Packer = new packer.Packer(wrapperArray, instanceArray);
|
||||
|
||||
///////
|
||||
// PACK (OPTIMIZE)
|
||||
let result: bws.packer.WrapperArray = my_packer.optimize();
|
||||
///////
|
||||
|
||||
///////////////////////////
|
||||
// TRACE PACKING RESULT
|
||||
///////////////////////////
|
||||
let xml: samchon.library.XML = result.toXML();
|
||||
console.log(xml.toString());
|
||||
}
|
||||
|
||||
main();
|
||||
Vendored
+1501
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"3d-bin-packing-tests.ts"
|
||||
]
|
||||
}
|
||||
+8
-4
@@ -401,6 +401,8 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
|
||||
* [:link:](egg.js/egg.js.d.ts) [Egg.js](https://github.com/mikeflynn/egg.js) by [Markus Peloso](https://github.com/ToastHawaii)
|
||||
* [:link:](ejs-locals/ejs-locals.d.ts) [ejs-locals](https://github.com/randometc/ejs-locals) by [jt000](https://github.com/jt000)
|
||||
* [:link:](ejs/ejs.d.ts) [ejs.js](http://ejs.co) by [Ben Liddicott](https://github.com/benliddicott/DefinitelyTyped)
|
||||
* [:link:](ejson/ejson.d.ts) [ejson](https://www.npmjs.com/package/ejson) by [Shantanu Bhadoria](https://github.com/shantanubhadoria)
|
||||
* [:link:](elasticsearch/elasticsearch.d.ts) [elasticsearch](https://www.elastic.co) by [Casper Skydt](https://github.com/CasperSkydt/DefinitelyTyped), [Blake Smith](https://github.com/bfsmith/DefinitelyTyped)
|
||||
* [:link:](jquery.elang/jquery.elang.d.ts) [eLang](https://github.com/sumegizoltan/ELang) by [Zoltan Sumegi](https://github.com/sumegizoltan)
|
||||
* [:link:](github-electron/github-electron.d.ts) [Electron](http://electron.atom.io) by [jedmao](https://github.com/jedmao), [rhysd](https://rhysd.github.io), [Milan Burda](https://github.com/miniak)
|
||||
* [:link:](electron-builder/electron-builder.d.ts) [electron-builder](https://github.com/loopline-systems/electron-builder) by [Maxime LUCE](https://github.com/SomaticIT)
|
||||
@@ -1123,10 +1125,11 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
|
||||
* [:link:](moment/moment.d.ts) [Moment.js](https://github.com/timrwood/moment) by [Michael Lakerveld](https://github.com/Lakerfield), [Aaron King](https://github.com/kingdango), [Hiroki Horiuchi](https://github.com/horiuchi), [Dick van den Brink](https://github.com/DickvdBrink), [Adi Dahiya](https://github.com/adidahiya), [Matt Brooks](https://github.com/EnableSoftware)
|
||||
* [:link:](moment-range/moment-range.d.ts) [Moment.js](https://github.com/gf3/moment-range) by [Bart van den Burg](https://github.com/Burgov), [Wilgert Velinga](https://github.com/wilgert)
|
||||
* [:link:](mongodb/mongodb.d.ts) [MongoDB](https://github.com/mongodb/node-mongodb-native/tree/2.1) by [Federico Caselli](https://github.com/CaselIT)
|
||||
* [:link:](mongoose/mongoose.d.ts) [Mongoose](http://mongoosejs.com) by [horiuchi](https://github.com/horiuchi)
|
||||
* [:link:](mongoose/mongoose.d.ts) [Mongoose](http://mongoosejs.com) by [simonxca](https://github.com/simonxca), [horiuchi](https://github.com/horiuchi)
|
||||
* [:link:](mongoose-auto-increment/mongoose-auto-increment.d.ts) [mongoose-auto-increment](https://github.com/codetunnel/mongoose-auto-increment) by [Aya Morisawa](https://github.com/AyaMorisawa)
|
||||
* [:link:](mongoose-deep-populate/mongoose-deep-populate.d.ts) [mongoose-deep-populate](https://github.com/buunguyen/mongoose-deep-populate) by [Aya Morisawa](https://github.com/AyaMorisawa)
|
||||
* [:link:](mongoose-mock/mongoose-mock.d.ts) [mongoose-mock](https://github.com/JohanObrink/mongoose-mock) by [jt000](https://github.com/jt000)
|
||||
* [:link:](mongoose-promise/mongoose-promise.d.ts) [mongoose-promise](http://mongoosejs.com/docs/api.html#promise-js) by [simonxca](https://github.com/simonxca)
|
||||
* [:link:](morgan/morgan.d.ts) [morgan](https://github.com/expressjs/morgan) by [James Roland Cabresos](https://github.com/staticfunction)
|
||||
* [:link:](mousetrap/mousetrap-global-bind.d.ts) [Mousetrap 1.4.6's global-bind extension](http://craig.is/killing/mice#extensions.global) by [Andrew Bradley](https://github.com/cspotcode)
|
||||
* [:link:](mousetrap/mousetrap.d.ts) [Mousetrap 1.5.x](http://craig.is/killing/mice) by [Dániel Tar](https://github.com/qcz)
|
||||
@@ -1187,7 +1190,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
|
||||
* [:link:](ng-stomp/ng-stomp.d.ts) [ngStomp](https://github.com/beevelop/ng-stomp) by [Lukasz Potapczuk](https://github.com/lpotapczuk)
|
||||
* [:link:](ngstorage/ngstorage.d.ts) [ngstorage](https://github.com/gsklee/ngStorage) by [Jakub Pistek](https://github.com/kubiq)
|
||||
* [:link:](nightmare/nightmare.d.ts) [Nightmare](https://github.com/segmentio/nightmare) by [horiuchi](https://github.com/horiuchi)
|
||||
* [:link:](noble/noble.d.ts) [noble](https://github.com/sandeepmistry/noble) by [Seon-Wook Park](https://github.com/swook), [Hans Bakker](https://github.com/wind-rider)
|
||||
* [:link:](noble/noble.d.ts) [noble](https://github.com/sandeepmistry/noble) by [Seon-Wook Park](https://github.com/swook), [Hans Bakker](https://github.com/wind-rider), [Shantanu Bhadoria](https://github.com/shantanubhadoria)
|
||||
* [:link:](nock/nock.d.ts) [nock](https://github.com/pgte/nock) by [bonnici](https://github.com/bonnici)
|
||||
* [:link:](node-imap/imap.d.ts) [node imap](https://github.com/mscdex/node-imap) by [Steve Fenton](https://github.com/Steve-Fenton)
|
||||
* [:link:](oauth2-server/oauth2-server.d.ts) [Node OAuth2 Server](https://github.com/thomseddon/node-oauth2-server) by [Robbie Van Gorkom](https://github.com/vangorra)
|
||||
@@ -1662,7 +1665,8 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
|
||||
* [:link:](supertest/supertest.d.ts) [SuperTest](https://github.com/visionmedia/supertest) by [Alex Varju](https://github.com/varju)
|
||||
* [:link:](supertest-as-promised/supertest-as-promised.d.ts) [SuperTest as Promised](https://github.com/WhoopInc/supertest-as-promised) by [Tanguy Krotoff](https://github.com/tkrotoff)
|
||||
* [:link:](svg-injector/svg-injector.d.ts) [SVG Injector](https://github.com/iconic/SVGInjector) by [Patrick Westerhoff](https://github.com/poke)
|
||||
* [:link:](svg-pan-zoom/svg-pan-zoom.d.ts) [svg-pan-zoom](https://github.com/ariutta/svg-pan-zoom) by [Chintan Shah](https://github.com/Promact)
|
||||
* [:link:](svg-pan-zoom/svg-pan-zoom-2.3.9.d.ts) [svg-pan-zoom](https://github.com/ariutta/svg-pan-zoom) by [Chintan Shah](https://github.com/Promact)
|
||||
* [:link:](svg-pan-zoom/svg-pan-zoom.d.ts) [svg-pan-zoom](https://github.com/ariutta/svg-pan-zoom) by [César Vidril](https://github.com/Yimiprod)
|
||||
* [:link:](svg-sprite/svg-sprite.d.ts) [svg-sprite](https://github.com/jkphl/svg-sprite) by [Qubo](https://github.com/tkqubo)
|
||||
* [:link:](svgjs/svgjs.d.ts) [svg.js](http://www.svgjs.com) by [Sean Hess](https://seanhess.github.io)
|
||||
* [:link:](svg2png/svg2png.d.ts) [svg2png node package](https://github.com/domenic/svg2png) by [hans windhoff](https://github.com/hansrwindhoff)
|
||||
@@ -1676,7 +1680,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
|
||||
* [:link:](swig/swig.d.ts) [swig](http://github.com/paularmstrong/swig) by [Peter Harris](https://github.com/CodeAnimal), [Carlos Ballesteros Velasco](https://github.com/soywiz)
|
||||
* [:link:](swig-email-templates/swig-email-templates.d.ts) [swig-email-templates](https://github.com/andrewrk/swig-email-templates) by [Adam Babcock](https://github.com/mrhen)
|
||||
* [:link:](swipe/swipe.d.ts) [Swipe](https://github.com/thebird/Swipe) by [Andrey Kurdyumov](https://github.com/kant2002)
|
||||
* [:link:](swiper/swiper.d.ts) [Swiper](https://github.com/nolimits4web/Swiper) by [Sebastián Galiano](https://github.com/sgaliano)
|
||||
* [:link:](swiper/swiper.d.ts) [Swiper](https://github.com/nolimits4web/Swiper) by [Sebastián Galiano](https://github.com/sgaliano), [Luca Trazzi](https://github.com/lucax88x)
|
||||
* [:link:](swipeview/swipeview.d.ts) [SwipeView](http://cubiq.org/swipeview) by [Boris Yankov](https://github.com/borisyankov)
|
||||
* [:link:](switchery/switchery.d.ts) [switchery](https://github.com/abpetkov/switchery) by [Bruno Grieder](https://github.com/bgrieder), [Clayton Lautier](https://github.com/claylaut)
|
||||
* [:link:](swiz/swiz.d.ts) [swiz](https://github.com/racker/node-swiz) by [Jeff Goddard](https://github.com/jedigo)
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
/// <reference path="DataStream.js.d.ts" />
|
||||
|
||||
var buf = new ArrayBuffer(100);
|
||||
var ds = new DataStream(buf);
|
||||
ds = new DataStream(buf, 10);
|
||||
ds = new DataStream(buf, 10, DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.save('somefile.ext');
|
||||
ds.dynamicSize = true;
|
||||
|
||||
for (var i=0; i<ds.byteLength; i++) {
|
||||
}
|
||||
|
||||
ds.buffer = buf;
|
||||
ds.byteOffset = 10;
|
||||
ds.seek(0);
|
||||
ds.isEof();
|
||||
|
||||
var int32arr: Int32Array;
|
||||
var int16arr: Int16Array;
|
||||
var int8arr: Int8Array;
|
||||
|
||||
var uint32arr: Uint32Array;
|
||||
var uint16arr: Uint16Array;
|
||||
var uint8arr: Uint8Array;
|
||||
|
||||
var float64arr: Float64Array;
|
||||
var float32arr: Float32Array;
|
||||
|
||||
var val: number;
|
||||
var str: string;
|
||||
|
||||
int32arr = ds.mapInt32Array(2);
|
||||
int32arr = ds.mapInt32Array(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
int16arr = ds.mapInt16Array(2);
|
||||
int16arr = ds.mapInt16Array(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
int8arr = ds.mapInt8Array(2);
|
||||
|
||||
uint32arr = ds.mapUint32Array(2);
|
||||
uint32arr = ds.mapUint32Array(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
uint16arr = ds.mapUint16Array(2);
|
||||
uint16arr = ds.mapUint16Array(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
uint8arr = ds.mapUint8Array(2);
|
||||
|
||||
float64arr = ds.mapFloat64Array(2);
|
||||
float64arr = ds.mapFloat64Array(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
float32arr = ds.mapFloat32Array(2);
|
||||
float32arr = ds.mapFloat32Array(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
int32arr = ds.readInt32Array(2);
|
||||
int32arr = ds.readInt32Array(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
int16arr = ds.readInt16Array(2);
|
||||
int16arr = ds.readInt16Array(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
int8arr = ds.readInt8Array(2);
|
||||
|
||||
uint32arr = ds.readUint32Array(2);
|
||||
uint32arr = ds.readUint32Array(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
uint16arr = ds.readUint16Array(2);
|
||||
uint16arr = ds.readUint16Array(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
uint8arr = ds.readUint8Array(2);
|
||||
|
||||
float64arr = ds.readFloat64Array(2);
|
||||
float64arr = ds.readFloat64Array(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
float32arr = ds.readFloat32Array(2);
|
||||
float32arr = ds.readFloat32Array(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeInt32Array(new Int32Array([1,2,3]));
|
||||
ds.writeInt32Array(new Int32Array([1,2,3]), DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeInt16Array(new Int16Array([1,2,3]));
|
||||
ds.writeInt16Array(new Int16Array([1,2,3]), DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeInt8Array(new Int8Array([1,2,3]));
|
||||
|
||||
ds.writeUint32Array(new Uint32Array([1,2,3]));
|
||||
ds.writeUint32Array(new Uint32Array([1,2,3]), DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeUint16Array(new Uint16Array([1,2,3]));
|
||||
ds.writeUint16Array(new Uint16Array([1,2,3]), DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeUint8Array(new Uint8Array([1,2,3]));
|
||||
|
||||
ds.writeFloat64Array(new Float64Array([1,2,3]));
|
||||
ds.writeFloat64Array(new Float64Array([1,2,3]), DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeFloat32Array(new Float32Array([1,2,3]));
|
||||
ds.writeFloat32Array(new Float32Array([1,2,3]), DataStream.BIG_ENDIAN);
|
||||
|
||||
val = ds.readInt32();
|
||||
val = ds.readInt32(DataStream.LITTLE_ENDIAN);
|
||||
|
||||
val = ds.readInt16();
|
||||
val = ds.readInt16(DataStream.BIG_ENDIAN);
|
||||
|
||||
val = ds.readInt8();
|
||||
|
||||
val = ds.readUint32();
|
||||
val = ds.readUint32(DataStream.LITTLE_ENDIAN);
|
||||
|
||||
val = ds.readUint16();
|
||||
val = ds.readUint16(DataStream.BIG_ENDIAN);
|
||||
|
||||
val = ds.readUint8();
|
||||
|
||||
val = ds.readFloat64();
|
||||
val = ds.readFloat64(DataStream.LITTLE_ENDIAN);
|
||||
|
||||
val = ds.readFloat32();
|
||||
val = ds.readFloat32(DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeInt32(1);
|
||||
ds.writeInt32(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeInt16(1);
|
||||
ds.writeInt16(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
ds.writeInt8(1);
|
||||
|
||||
ds.writeUint32(1);
|
||||
ds.writeUint32(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeUint16(1);
|
||||
ds.writeUint16(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
ds.writeUint8(1);
|
||||
|
||||
ds.writeFloat32(1);
|
||||
ds.writeFloat32(2, DataStream.BIG_ENDIAN);
|
||||
|
||||
ds.writeFloat64(1);
|
||||
ds.writeFloat64(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
var embed = [
|
||||
'tag', 'uint32be',
|
||||
'code', 'uint32le',
|
||||
'greet', 'cstring'
|
||||
];
|
||||
|
||||
var def = [
|
||||
'tag', 'cstring:4',
|
||||
'code', 'uint32le',
|
||||
'embed', embed,
|
||||
'length', 'uint16be',
|
||||
'data', ['[]', 'float32be', 'length'],
|
||||
'greet', 'cstring:20',
|
||||
'endNote', 'uint8'
|
||||
];
|
||||
|
||||
var obj = ds.readStruct(def);
|
||||
ds.writeStruct(def, obj);
|
||||
|
||||
str = ds.readUCS2String(2);
|
||||
str = ds.readUCS2String(2, DataStream.LITTLE_ENDIAN);
|
||||
|
||||
ds.writeUCS2String("str");
|
||||
ds.writeUCS2String("str", DataStream.LITTLE_ENDIAN);
|
||||
ds.writeUCS2String("str", DataStream.LITTLE_ENDIAN, 1);
|
||||
|
||||
str = ds.readString(2);
|
||||
str = ds.readString(2, "ASCII");
|
||||
|
||||
ds.writeString("str");
|
||||
ds.writeString("str", "ASCII");
|
||||
ds.writeString("str", "ASCII", 1);
|
||||
|
||||
str = ds.readCString();
|
||||
str = ds.readCString(2);
|
||||
|
||||
ds.writeCString("str");
|
||||
ds.writeCString("str", 1);
|
||||
Vendored
-937
@@ -1,937 +0,0 @@
|
||||
// Type definitions for DataStream.js
|
||||
// Project: https://github.com/kig/DataStream.js
|
||||
// Definitions by: Tat <https://github.com/tatchx/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class DataStream {
|
||||
|
||||
/**
|
||||
Big-endian const to use as default endianness.
|
||||
*/
|
||||
static BIG_ENDIAN: boolean;
|
||||
|
||||
/**
|
||||
Little-endian const to use as default endianness.
|
||||
*/
|
||||
static LITTLE_ENDIAN: boolean;
|
||||
|
||||
/**
|
||||
DataStream reads scalars, arrays and structs of data from an ArrayBuffer.
|
||||
It's like a file-like DataView on steroids.
|
||||
|
||||
@param {ArrayBuffer} arrayBuffer ArrayBuffer to read from.
|
||||
*/
|
||||
constructor(arrayBuffer: ArrayBuffer);
|
||||
|
||||
/**
|
||||
DataStream reads scalars, arrays and structs of data from an ArrayBuffer.
|
||||
It's like a file-like DataView on steroids.
|
||||
|
||||
@param arrayBuffer ArrayBuffer to read from.
|
||||
@param byteOffset Offset from arrayBuffer beginning for the DataStream.
|
||||
*/
|
||||
constructor(arrayBuffer: ArrayBuffer, byteOffset: number);
|
||||
|
||||
/**
|
||||
DataStream reads scalars, arrays and structs of data from an ArrayBuffer.
|
||||
It's like a file-like DataView on steroids.
|
||||
|
||||
@param arrayBuffer ArrayBuffer to read from.
|
||||
@param byteOffset Offset from arrayBuffer beginning for the DataStream.
|
||||
@param endianness DataStream.BIG_ENDIAN or DataStream.LITTLE_ENDIAN (the default).
|
||||
*/
|
||||
constructor(arrayBuffer: ArrayBuffer, byteOffset: number, endianness: boolean);
|
||||
|
||||
/**
|
||||
Saves the DataStream contents to the given filename.
|
||||
Uses Chrome's anchor download property to initiate download.
|
||||
*
|
||||
@param filename Filename to save as.
|
||||
@return nothing
|
||||
*/
|
||||
save(filename: string): void;
|
||||
|
||||
/**
|
||||
Whether to extend DataStream buffer when trying to write beyond its size.
|
||||
If set, the buffer is reallocated to twice its current size until the
|
||||
requested write fits the buffer.
|
||||
*/
|
||||
dynamicSize: boolean;
|
||||
|
||||
/**
|
||||
Returns the byte length of the DataStream object.
|
||||
*/
|
||||
byteLength: number;
|
||||
|
||||
/**
|
||||
Set/get the backing ArrayBuffer of the DataStream object.
|
||||
The setter updates the DataView to point to the new buffer.
|
||||
*/
|
||||
buffer: ArrayBuffer;
|
||||
|
||||
/**
|
||||
Set/get the byteOffset of the DataStream object.
|
||||
The setter updates the DataView to point to the new byteOffset.
|
||||
*/
|
||||
byteOffset: number;
|
||||
|
||||
/**
|
||||
Set/get the backing DataView of the DataStream object.
|
||||
The setter updates the buffer and byteOffset to point to the DataView values.
|
||||
*/
|
||||
dataView: Object;
|
||||
|
||||
/**
|
||||
Sets the DataStream read/write position to given position.
|
||||
Clamps between 0 and DataStream length.
|
||||
*
|
||||
@param pos Position to seek to.
|
||||
@return nothing
|
||||
*/
|
||||
seek(pos: number): void;
|
||||
|
||||
/**
|
||||
Returns true if the DataStream seek pointer is at the end of buffer and
|
||||
there's no more data to read.
|
||||
*
|
||||
@return true if the seek pointer is at the end of the buffer.
|
||||
*/
|
||||
isEof(): boolean;
|
||||
|
||||
/**
|
||||
Maps an Int32Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Int32Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapInt32Array(length: number): Int32Array;
|
||||
|
||||
/**
|
||||
Maps an Int32Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return Int32Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapInt32Array(length: number, e: boolean): Int32Array;
|
||||
|
||||
/**
|
||||
Maps an Int16Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Int16Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapInt16Array(length: number): Int16Array;
|
||||
|
||||
/**
|
||||
Maps an Int16Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return Int16Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapInt16Array(length: number, e: boolean): Int16Array;
|
||||
|
||||
/**
|
||||
Maps an Int8Array into the DataStream buffer.
|
||||
*
|
||||
Nice for quickly reading in data.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Int8Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapInt8Array(length: number): Int8Array;
|
||||
|
||||
/**
|
||||
Maps a Uint32Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Uint32Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapUint32Array(length: number): Uint32Array;
|
||||
|
||||
/**
|
||||
Maps a Uint32Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return Uint32Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapUint32Array(length: number, e: boolean): Uint32Array;
|
||||
|
||||
/**
|
||||
Maps a Uint16Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Uint16Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapUint16Array(length: number): Uint16Array;
|
||||
|
||||
/**
|
||||
Maps a Uint16Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return Uint16Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapUint16Array(length: number, e: boolean): Uint16Array;
|
||||
|
||||
/**
|
||||
Maps a Uint8Array into the DataStream buffer.
|
||||
*
|
||||
Nice for quickly reading in data.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Uint8Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapUint8Array(length: number): Uint8Array;
|
||||
|
||||
/**
|
||||
Maps a Float64Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Float64Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapFloat64Array(length: number): Float64Array;
|
||||
|
||||
/**
|
||||
Maps a Float64Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return Float64Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapFloat64Array(length: number, e: boolean): Float64Array;
|
||||
|
||||
/**
|
||||
Maps a Float32Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return Float32Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapFloat32Array(length: number): Float32Array;
|
||||
|
||||
/**
|
||||
Maps a Float32Array into the DataStream buffer, swizzling it to native
|
||||
endianness in-place. The current offset from the start of the buffer needs to
|
||||
be a multiple of element size, just like with typed array views.
|
||||
*
|
||||
Nice for quickly reading in data. Warning: potentially modifies the buffer
|
||||
contents.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return Float32Array to the DataStream backing buffer.
|
||||
*/
|
||||
mapFloat32Array(length: number, e: boolean): Float32Array;
|
||||
|
||||
/**
|
||||
Reads an Int32Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Int32Array.
|
||||
*/
|
||||
readInt32Array(length: number): Int32Array;
|
||||
|
||||
/**
|
||||
Reads an Int32Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return The read Int32Array.
|
||||
*/
|
||||
readInt32Array(length: number, e: boolean): Int32Array;
|
||||
|
||||
/**
|
||||
Reads an Int16Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Int16Array.
|
||||
*/
|
||||
readInt16Array(length: number): Int16Array;
|
||||
|
||||
/**
|
||||
Reads an Int16Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return The read Int16Array.
|
||||
*/
|
||||
readInt16Array(length: number, e: boolean): Int16Array;
|
||||
|
||||
/**
|
||||
Reads an Int8Array of desired length from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Int8Array.
|
||||
*/
|
||||
readInt8Array(length: number): Int8Array;
|
||||
|
||||
/**
|
||||
Reads an Uint32Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Uint32Array.
|
||||
*/
|
||||
readUint32Array(length: number): Uint32Array;
|
||||
|
||||
/**
|
||||
Reads an Uint32Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return The read Uint32Array.
|
||||
*/
|
||||
readUint32Array(length: number, e: boolean): Uint32Array;
|
||||
|
||||
/**
|
||||
Reads an Uint16Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Uint16Array.
|
||||
*/
|
||||
readUint16Array(length: number): Uint16Array;
|
||||
|
||||
/**
|
||||
Reads an Uint16Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return The read Uint16Array.
|
||||
*/
|
||||
readUint16Array(length: number, e: boolean): Uint16Array;
|
||||
|
||||
/**
|
||||
Reads an Uint8Array of desired length from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Uint8Array.
|
||||
*/
|
||||
readUint8Array(length: number): Uint8Array;
|
||||
|
||||
/**
|
||||
Reads a Float64Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return The read Float64Array.
|
||||
*/
|
||||
readFloat64Array(length: number, e: boolean): Float64Array;
|
||||
|
||||
/**
|
||||
Reads a Float64Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Float64Array.
|
||||
*/
|
||||
readFloat64Array(length: number): Float64Array;
|
||||
|
||||
/**
|
||||
Reads a Float32Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@param e Endianness of the data to read.
|
||||
@return The read Float32Array.
|
||||
*/
|
||||
readFloat32Array(length: number, e: boolean): Float32Array;
|
||||
|
||||
/**
|
||||
Reads a Float32Array of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length Number of elements to map.
|
||||
@return The read Float32Array.
|
||||
*/
|
||||
readFloat32Array(length: number): Float32Array;
|
||||
|
||||
/**
|
||||
Writes an Int32Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
@param e Endianness of the data to write.
|
||||
*/
|
||||
writeInt32Array(arr: Int32Array, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes an Int32Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeInt32Array(arr: Int32Array): void;
|
||||
|
||||
/**
|
||||
Writes an Int16Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
@param e Endianness of the data to write.
|
||||
*/
|
||||
writeInt16Array(arr: Int16Array, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes an Int16Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeInt16Array(arr: Int16Array): void;
|
||||
|
||||
/**
|
||||
Writes an Int8Array to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeInt8Array(arr: Int8Array): void;
|
||||
|
||||
/**
|
||||
Writes an Uint32Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
@param e Endianness of the data to write.
|
||||
*/
|
||||
writeUint32Array(arr: Uint32Array, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes an Uint32Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeUint32Array(arr: Uint32Array): void;
|
||||
|
||||
/**
|
||||
Writes an Uint16Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
@param e Endianness of the data to write.
|
||||
*/
|
||||
writeUint16Array(arr: Uint16Array, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes an Uint16Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeUint16Array(arr: Uint16Array): void;
|
||||
|
||||
/**
|
||||
Writes an Uint8Array to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeUint8Array(arr: Uint8Array): void;
|
||||
|
||||
/**
|
||||
Writes a Float64Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeFloat64Array(arr: Float64Array): void;
|
||||
|
||||
/**
|
||||
Writes a Float64Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
@param e Endianness of the data to write.
|
||||
*/
|
||||
writeFloat64Array(arr: Float64Array, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes a Float32Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
*/
|
||||
writeFloat32Array(arr: Float32Array): void;
|
||||
|
||||
/**
|
||||
Writes a Float32Array of specified endianness to the DataStream.
|
||||
*
|
||||
@param arr The array to write.
|
||||
@param e Endianness of the data to write.
|
||||
*/
|
||||
writeFloat32Array(arr: Float32Array, e: boolean): void;
|
||||
|
||||
/**
|
||||
Reads a 32-bit int from the DataStream with the desired endianness.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readInt32(): number;
|
||||
|
||||
/**
|
||||
Reads a 32-bit int from the DataStream with the desired endianness.
|
||||
*
|
||||
@param e Endianness of the number.
|
||||
@return The read number.
|
||||
*/
|
||||
readInt32(e: boolean): number;
|
||||
|
||||
/**
|
||||
Reads a 16-bit int from the DataStream with the desired endianness.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readInt16(): number;
|
||||
|
||||
/**
|
||||
Reads a 16-bit int from the DataStream with the desired endianness.
|
||||
*
|
||||
@param e Endianness of the number.
|
||||
@return The read number.
|
||||
*/
|
||||
readInt16(e: boolean): number;
|
||||
|
||||
/**
|
||||
Reads an 8-bit int from the DataStream.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readInt8(): number;
|
||||
|
||||
/**
|
||||
Reads a 32-bit unsigned int from the DataStream with the desired endianness.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readUint32(): number;
|
||||
|
||||
/**
|
||||
Reads a 32-bit unsigned int from the DataStream with the desired endianness.
|
||||
*
|
||||
@param e Endianness of the number.
|
||||
@return The read number.
|
||||
*/
|
||||
readUint32(e: boolean): number;
|
||||
|
||||
/**
|
||||
Reads a 16-bit unsigned int from the DataStream with the desired endianness.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readUint16(): number;
|
||||
|
||||
/**
|
||||
Reads a 16-bit unsigned int from the DataStream with the desired endianness.
|
||||
*
|
||||
@param e Endianness of the number.
|
||||
@return The read number.
|
||||
*/
|
||||
readUint16(e: boolean): number;
|
||||
|
||||
/**
|
||||
Reads an 8-bit unsigned intfrom the DataStream.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readUint8(): number;
|
||||
|
||||
/**
|
||||
Reads a 32-bit float from the DataStream with the desired endianness.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readFloat32(): number;
|
||||
|
||||
/**
|
||||
Reads a 32-bit float from the DataStream with the desired endianness.
|
||||
*
|
||||
@param e Endianness of the number.
|
||||
@return The read number.
|
||||
*/
|
||||
readFloat32(e: boolean): number;
|
||||
|
||||
/**
|
||||
Reads a 64-bit float from the DataStream with the desired endianness.
|
||||
*
|
||||
@return The read number.
|
||||
*/
|
||||
readFloat64(): number;
|
||||
|
||||
/**
|
||||
Reads a 64-bit float from the DataStream with the desired endianness.
|
||||
*
|
||||
@param e Endianness of the number.
|
||||
@return The read number.
|
||||
*/
|
||||
readFloat64(e: boolean): number;
|
||||
|
||||
/**
|
||||
Writes a 32-bit int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeInt32(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 32-bit int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
@param e Endianness of the number.
|
||||
*/
|
||||
writeInt32(v: number, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes a 16-bit int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeInt16(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 16-bit int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
@param e Endianness of the number.
|
||||
*/
|
||||
writeInt16(v: number, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes an 8-bit int to the DataStream.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeInt8(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 32-bit undigned int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeUint32(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 32-bit undigned int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
@param e Endianness of the number.
|
||||
*/
|
||||
writeUint32(v: number, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes a 16-bit undigned int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeUint16(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 16-bit undigned int to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
@param e Endianness of the number.
|
||||
*/
|
||||
writeUint16(v: number, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes an 8-bit undigned int to the DataStream.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeUint8(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 32-bit float to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeFloat32(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 32-bit float to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
@param e Endianness of the number.
|
||||
*/
|
||||
writeFloat32(v: number, e: boolean): void;
|
||||
|
||||
/**
|
||||
Writes a 64-bit float to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
*/
|
||||
writeFloat64(v: number): void;
|
||||
|
||||
/**
|
||||
Writes a 64-bit float to the DataStream with the desired endianness.
|
||||
*
|
||||
@param v Number to write.
|
||||
@param e Endianness of the number.
|
||||
*/
|
||||
writeFloat64(v: number, e: boolean): void;
|
||||
|
||||
/**
|
||||
Reads a struct of data from the DataStream. The struct is defined as
|
||||
a flat array of [name, type]-pairs. See the example below:
|
||||
*
|
||||
ds.readStruct([
|
||||
'headerTag', 'uint32', // Uint32 in DataStream endianness.
|
||||
'headerTag2', 'uint32be', // Big-endian Uint32.
|
||||
'headerTag3', 'uint32le', // Little-endian Uint32.
|
||||
'array', ['[]', 'uint32', 16], // Uint32Array of length 16.
|
||||
'array2Length', 'uint32',
|
||||
'array2', ['[]', 'uint32', 'array2Length'] // Uint32Array of length array2Length
|
||||
]);
|
||||
*
|
||||
The possible values for the type are as follows:
|
||||
*
|
||||
// Number types
|
||||
// Unsuffixed number types use DataStream endianness.
|
||||
// To explicitly specify endianness, suffix the type with
|
||||
// 'le' for little-endian or 'be' for big-endian,
|
||||
// e.g. 'int32be' for big-endian int32.
|
||||
'uint8' -- 8-bit unsigned int
|
||||
'uint16' -- 16-bit unsigned int
|
||||
'uint32' -- 32-bit unsigned int
|
||||
'int8' -- 8-bit int
|
||||
'int16' -- 16-bit int
|
||||
'int32' -- 32-bit int
|
||||
'float32' -- 32-bit float
|
||||
'float64' -- 64-bit float
|
||||
*
|
||||
// String types
|
||||
'cstring' -- ASCII string terminated by a zero byte.
|
||||
'string:N' -- ASCII string of length N, where N is a literal integer.
|
||||
'string:variableName' -- ASCII string of length $variableName,
|
||||
where 'variableName' is a previously parsed number in the current struct.
|
||||
'string,CHARSET:N' -- String of byteLength N encoded with given CHARSET.
|
||||
'u16string:N' -- UCS-2 string of length N in DataStream endianness.
|
||||
'u16stringle:N' -- UCS-2 string of length N in little-endian.
|
||||
'u16stringbe:N' -- UCS-2 string of length N in big-endian.
|
||||
*
|
||||
// Complex types
|
||||
[name, type, name_2, type_2, ..., name_N, type_N] -- Struct
|
||||
function(dataStream, struct) {} -- Callback function to read and return data.
|
||||
{get: function(dataStream, struct) {},
|
||||
set: function(dataStream, struct) {}}
|
||||
-- Getter/setter functions to read and return data, handy for using the same
|
||||
struct definition for reading and writing structs.
|
||||
['[]', type, length] -- Array of given type and length. The length can be either
|
||||
a number, a string that references a previously-read
|
||||
field, or a callback function(struct, dataStream, type){}.
|
||||
If length is '*', reads in as many elements as it can.
|
||||
*
|
||||
@param structDefinition Struct definition object.
|
||||
@return The read struct. Null if failed to read struct.
|
||||
*/
|
||||
readStruct(structDefinition: any[]): Object;
|
||||
|
||||
/**
|
||||
Writes a struct to the DataStream. Takes a structDefinition that gives the
|
||||
types and a struct object that gives the values. Refer to readStruct for the
|
||||
structure of structDefinition.
|
||||
*
|
||||
@param structDefinition Type definition of the struct.
|
||||
@param struct The struct data object.
|
||||
*/
|
||||
writeStruct(structDefinition: Object, struct: Object): void;
|
||||
|
||||
/**
|
||||
Read UCS-2 string of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length The length of the string to read.
|
||||
@return The read string.
|
||||
*/
|
||||
readUCS2String(length: number): string;
|
||||
|
||||
/**
|
||||
Read UCS-2 string of desired length and endianness from the DataStream.
|
||||
*
|
||||
@param length The length of the string to read.
|
||||
@param endianness The endianness of the string data in the DataStream.
|
||||
@return The read string.
|
||||
*/
|
||||
readUCS2String(length: number, endianness: boolean): string;
|
||||
|
||||
/**
|
||||
Write a UCS-2 string of desired endianness to the DataStream. The
|
||||
lengthOverride argument lets you define the number of characters to write.
|
||||
If the string is shorter than lengthOverride, the extra space is padded with
|
||||
zeroes.
|
||||
*
|
||||
@param str The string to write.
|
||||
*/
|
||||
writeUCS2String(str: string): void;
|
||||
|
||||
/**
|
||||
Write a UCS-2 string of desired endianness to the DataStream. The
|
||||
lengthOverride argument lets you define the number of characters to write.
|
||||
If the string is shorter than lengthOverride, the extra space is padded with
|
||||
zeroes.
|
||||
*
|
||||
@param str The string to write.
|
||||
@param endianness The endianness to use for the written string data.
|
||||
*/
|
||||
writeUCS2String(str: string, endianness: boolean): void;
|
||||
|
||||
/**
|
||||
Write a UCS-2 string of desired endianness to the DataStream. The
|
||||
lengthOverride argument lets you define the number of characters to write.
|
||||
If the string is shorter than lengthOverride, the extra space is padded with
|
||||
zeroes.
|
||||
*
|
||||
@param str The string to write.
|
||||
@param endianness The endianness to use for the written string data.
|
||||
@param lengthOverride The number of characters to write.
|
||||
*/
|
||||
writeUCS2String(str: string, endianness: boolean, lengthOverride: number): void;
|
||||
|
||||
/**
|
||||
Read a string of desired length and encoding from the DataStream.
|
||||
*
|
||||
@param length The length of the string to read in bytes.
|
||||
@return The read string.
|
||||
*/
|
||||
readString(length: number): string;
|
||||
|
||||
/**
|
||||
Read a string of desired length and encoding from the DataStream.
|
||||
*
|
||||
@param length The length of the string to read in bytes.
|
||||
@param encoding The encoding of the string data in the DataStream. Defaults to ASCII.
|
||||
@return The read string.
|
||||
*/
|
||||
readString(length: number, encoding: string): string;
|
||||
|
||||
/**
|
||||
Writes a string of desired length and encoding to the DataStream.
|
||||
*
|
||||
@param s The string to write.
|
||||
*/
|
||||
writeString(s: string): void;
|
||||
|
||||
/**
|
||||
Writes a string of desired length and encoding to the DataStream.
|
||||
*
|
||||
@param s The string to write.
|
||||
@param encoding The encoding for the written string data. Defaults to ASCII.
|
||||
*/
|
||||
writeString(s: string, encoding: string): void;
|
||||
|
||||
/**
|
||||
Writes a string of desired length and encoding to the DataStream.
|
||||
*
|
||||
@param s The string to write.
|
||||
@param encoding The encoding for the written string data. Defaults to ASCII.
|
||||
@param length The number of characters to write.
|
||||
*/
|
||||
writeString(s: string, encoding: string, length: number): void;
|
||||
|
||||
/**
|
||||
Read null-terminated string of desired length from the DataStream. Truncates
|
||||
the returned string so that the null byte is not a part of it.
|
||||
*
|
||||
@return The read string.
|
||||
*/
|
||||
readCString(): string;
|
||||
|
||||
/**
|
||||
Read null-terminated string of desired length from the DataStream. Truncates
|
||||
the returned string so that the null byte is not a part of it.
|
||||
*
|
||||
@param length The length of the string to read.
|
||||
@return The read string.
|
||||
*/
|
||||
readCString(length: number): string;
|
||||
|
||||
/**
|
||||
Writes a null-terminated string to DataStream and zero-pads it to length
|
||||
bytes. If length is not given, writes the string followed by a zero.
|
||||
If string is longer than length, the written part of the string does not have
|
||||
a trailing zero.
|
||||
*
|
||||
@param s The string to write.
|
||||
*/
|
||||
writeCString(s: string): void;
|
||||
|
||||
/**
|
||||
Writes a null-terminated string to DataStream and zero-pads it to length
|
||||
bytes. If length is not given, writes the string followed by a zero.
|
||||
If string is longer than length, the written part of the string does not have
|
||||
a trailing zero.
|
||||
*
|
||||
@param s The string to write.
|
||||
@param length The number of characters to write.
|
||||
*/
|
||||
writeCString(s: string, length: number): void;
|
||||
|
||||
/**
|
||||
Reads an object of type t from the DataStream, passing struct as the thus-far
|
||||
read struct to possible callbacks that refer to it. Used by readStruct for
|
||||
reading in the values, so the type is one of the readStruct types.
|
||||
*
|
||||
@param t Type of the object to read.
|
||||
@return Returns the object on successful read, null on unsuccessful.
|
||||
*/
|
||||
readType(t: Object): Object;
|
||||
|
||||
/**
|
||||
Reads an object of type t from the DataStream, passing struct as the thus-far
|
||||
read struct to possible callbacks that refer to it. Used by readStruct for
|
||||
reading in the values, so the type is one of the readStruct types.
|
||||
*
|
||||
@param t Type of the object to read.
|
||||
@param struct Struct to refer to when resolving length references and for calling callbacks.
|
||||
@return Returns the object on successful read, null on unsuccessful.
|
||||
*/
|
||||
readType(t: Object, struct: Object): Object;
|
||||
|
||||
/**
|
||||
Writes object v of type t to the DataStream.
|
||||
*
|
||||
@param t Type of data to write.
|
||||
@param v Value of data to write.
|
||||
@param struct Struct to pass to write callback functions.
|
||||
*/
|
||||
writeType(t: Object, v: Object, struct: Object): void;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
/// <reference path="FileSaver.d.ts" />
|
||||
|
||||
/**
|
||||
* @summary Test for "saveAs" function.
|
||||
*/
|
||||
function testSaveAs() {
|
||||
var data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
||||
var filename: string = 'hello world.txt';
|
||||
var disableAutoBOM = true;
|
||||
|
||||
saveAs(data, filename, disableAutoBOM);
|
||||
}
|
||||
Vendored
-33
@@ -1,33 +0,0 @@
|
||||
// Type definitions for FileSaver.js
|
||||
// Project: https://github.com/eligrey/FileSaver.js/
|
||||
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* @summary Interface for "saveAs" function.
|
||||
* @author Cyril Schumacher
|
||||
* @version 1.0
|
||||
*/
|
||||
interface FileSaver {
|
||||
(
|
||||
/**
|
||||
* @summary Data.
|
||||
* @type {Blob}
|
||||
*/
|
||||
data: Blob,
|
||||
|
||||
/**
|
||||
* @summary File name.
|
||||
* @type {DOMString}
|
||||
*/
|
||||
filename: string,
|
||||
|
||||
/**
|
||||
* @summary Disable Unicode text encoding hints or not.
|
||||
* @type {boolean}
|
||||
*/
|
||||
disableAutoBOM?: boolean
|
||||
): void
|
||||
}
|
||||
|
||||
declare var saveAs: FileSaver;
|
||||
@@ -1,368 +0,0 @@
|
||||
/// <reference path="Finch.d.ts" />
|
||||
|
||||
function test_Finch() {
|
||||
|
||||
|
||||
Finch.route("Hello/Route", function() {
|
||||
return console.log("Well hello there! How you doin'?!");
|
||||
});
|
||||
|
||||
Finch.route("Hello/Route/:someId", function(bindings) {
|
||||
return console.log("Hey! Here's Some Id: " + bindings.someId);
|
||||
});
|
||||
|
||||
Finch.route("Hello/Route/:someId", function(bindings, childCallback) {
|
||||
console.log("Hey! Here's Some Id: " + bindings.someId);
|
||||
return childCallback();
|
||||
});
|
||||
|
||||
Finch.route("some/route", {
|
||||
setup: function(bindings) {
|
||||
return console.log("Some Route has been setup! :)");
|
||||
},
|
||||
load: function(bindings) {
|
||||
return console.log("Some Route has been loaed! :D");
|
||||
},
|
||||
unload: function(bindings) {
|
||||
return console.log("Some Route has been loaed! :(");
|
||||
},
|
||||
teardown: function(bindings) {
|
||||
return console.log("Some Route has been torndown! :'(");
|
||||
}
|
||||
});
|
||||
|
||||
Finch.route("some/route", {
|
||||
setup: function(bindings, childCallback) {
|
||||
console.log("Some Route has been setup! :)");
|
||||
return childCallback();
|
||||
},
|
||||
load: function(bindings, childCallback) {
|
||||
console.log("Some Route has been loaed! :D");
|
||||
return childCallback();
|
||||
},
|
||||
unload: function(bindings, childCallback) {
|
||||
console.log("Some Route has been loaed! :(");
|
||||
return childCallback();
|
||||
},
|
||||
teardown: function(bindings, childCallback) {
|
||||
console.log("Some Route has been torndown! :'(");
|
||||
return childCallback();
|
||||
}
|
||||
});
|
||||
|
||||
Finch.call("Some/Route");
|
||||
|
||||
Finch.route("Some/Route", function() {
|
||||
return Finch.observe("hello", "foo", function(hello: any, foo: string) {
|
||||
return console.log("" + hello + " and " + foo);
|
||||
});
|
||||
});
|
||||
|
||||
Finch.route("Some/Route", function() {
|
||||
return Finch.observe(["hello", "foo"], function(hello: any, foo: any) {
|
||||
return console.log("" + hello + " and " + foo);
|
||||
});
|
||||
});
|
||||
|
||||
Finch.route("Some/Route", function(bindings) {
|
||||
return Finch.observe(function(params) {
|
||||
});
|
||||
});
|
||||
|
||||
Finch.navigate("Some/Route");
|
||||
|
||||
Finch.navigate("Some/Route", {
|
||||
hello: 'world',
|
||||
foo: 'bar'
|
||||
});
|
||||
|
||||
Finch.navigate("Some/Route", {
|
||||
foo: 'bar'
|
||||
}, true);
|
||||
|
||||
Finch.navigate("Some/Route", true);
|
||||
|
||||
Finch.navigate({
|
||||
hello: 'world2',
|
||||
wow: 'wee'
|
||||
});
|
||||
|
||||
Finch.navigate({
|
||||
foo: 'bar',
|
||||
wow: 'wee!!!'
|
||||
});
|
||||
|
||||
Finch.navigate({
|
||||
hello: 'world2'
|
||||
}, true);
|
||||
|
||||
Finch.listen();
|
||||
Finch.ignore();
|
||||
Finch.abort();
|
||||
|
||||
|
||||
//test from Finch
|
||||
Finch.call("/foo/bar");
|
||||
Finch.call("/foo/bar/123");
|
||||
Finch.call("/foo/bar/123");
|
||||
Finch.call("/foo/bar/123?x=Hello&y=World");
|
||||
Finch.call("/foo/baz/456");
|
||||
Finch.call("/quux/789?band=Sunn O)))&genre=Post-Progressive Fridgecore");
|
||||
Finch.call("/foo/bar/baz");
|
||||
Finch.call("/foo/bar/quux");
|
||||
Finch.call("/foo");
|
||||
Finch.call("/foo/bar");
|
||||
Finch.call("/foo");
|
||||
Finch.call("/foo");
|
||||
Finch.call("/");
|
||||
Finch.call("/");
|
||||
Finch.call("/foo");
|
||||
Finch.call("/foo/bar");
|
||||
Finch.call("/foo/bar?baz=quux");
|
||||
Finch.call("/foo/bar?baz=xyzzy");
|
||||
|
||||
var cb: any;
|
||||
Finch.route("foo", {
|
||||
setup: cb.setup_foo = this.stub(),
|
||||
load: cb.load_foo = this.stub(),
|
||||
unload: cb.unload_foo = this.stub(),
|
||||
teardown: cb.teardown_foo = this.stub()
|
||||
});
|
||||
Finch.route("[foo]/bar", {
|
||||
setup: cb.setup_foo_bar = this.stub(),
|
||||
load: cb.load_foo_bar = this.stub(),
|
||||
unload: cb.unload_foo_bar = this.stub(),
|
||||
teardown: cb.teardown_foo_bar = this.stub()
|
||||
});
|
||||
Finch.route("[foo/bar]/:id", {
|
||||
setup: cb.setup_foo_bar_id = this.stub(),
|
||||
load: cb.load_foo_bar_id = this.stub(),
|
||||
unload: cb.unload_foo_bar_id = this.stub(),
|
||||
teardown: cb.teardown_foo_bar_id = this.stub()
|
||||
});
|
||||
Finch.route("[foo]/baz", {
|
||||
setup: cb.setup_foo_baz = this.stub(),
|
||||
load: cb.load_foo_baz = this.stub(),
|
||||
unload: cb.unload_foo_baz = this.stub(),
|
||||
teardown: cb.teardown_foo_baz = this.stub()
|
||||
});
|
||||
Finch.route("[foo/baz]/:id", {
|
||||
setup: cb.setup_foo_baz_id = this.stub(),
|
||||
load: cb.load_foo_baz_id = this.stub(),
|
||||
unload: cb.unload_foo_baz_id = this.stub(),
|
||||
teardown: cb.teardown_foo_baz_id = this.stub()
|
||||
});
|
||||
Finch.call("/foo");
|
||||
Finch.call("/foo/bar");
|
||||
Finch.call("/foo");
|
||||
Finch.call("/foo/bar/123?x=abc");
|
||||
Finch.call("/foo/bar/456?x=aaa&y=zzz");
|
||||
Finch.call("/foo/bar/456?x=bbb&y=zzz");
|
||||
Finch.call("/foo/bar/456?y=zzz&x=bbb");
|
||||
Finch.call("/foo/baz/789");
|
||||
Finch.call("/foo/baz/abc?term=Hello");
|
||||
Finch.call("/foo/baz/abc?term=World");
|
||||
Finch.route("bar", this.stub());
|
||||
Finch.call("/foo");
|
||||
Finch.call("/bar");
|
||||
Finch.route("/", function() {
|
||||
});
|
||||
Finch.route("[/]home", function() {
|
||||
});
|
||||
Finch.route("[/home]/news", {
|
||||
setup: function() {
|
||||
},
|
||||
load: function() {
|
||||
},
|
||||
unload: function() {
|
||||
return true;
|
||||
},
|
||||
teardown: function() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
Finch.route("/foo", {
|
||||
setup: function() {
|
||||
return true;
|
||||
},
|
||||
load: function() {
|
||||
return true;
|
||||
},
|
||||
unload: function() {
|
||||
},
|
||||
teardown: function() {
|
||||
}
|
||||
});
|
||||
Finch.route("[/]bar", {
|
||||
setup: function() {
|
||||
},
|
||||
load: function() {
|
||||
},
|
||||
unload: function() {
|
||||
},
|
||||
teardown: function() {
|
||||
}
|
||||
});
|
||||
Finch.call("/bar");
|
||||
Finch.call("/home/news");
|
||||
Finch.call("/foo");
|
||||
Finch.call("/home/news");
|
||||
Finch.call("/bar");
|
||||
Finch.route("baz", this.stub());
|
||||
Finch.call("/foo");
|
||||
Finch.call("/foo/bar");
|
||||
Finch.call("/baz");
|
||||
Finch.route("/home", {
|
||||
setup: function(bindings, next) {
|
||||
return next();
|
||||
},
|
||||
load: function(bindings, next) {
|
||||
return next();
|
||||
},
|
||||
unload: function(bindings, next) {
|
||||
return next();
|
||||
},
|
||||
teardown: function(bindings, next) {
|
||||
return next();
|
||||
}
|
||||
});
|
||||
Finch.route("[/home]/news", {
|
||||
setup: function(bindings, next) {
|
||||
return next();
|
||||
},
|
||||
load: function(bindings, next) {
|
||||
return next();
|
||||
},
|
||||
unload: function(bindings, next) {
|
||||
return next();
|
||||
},
|
||||
teardown: function(bindings, next) {
|
||||
return next();
|
||||
}
|
||||
});
|
||||
Finch.call("/home");
|
||||
Finch.call("/home/news");
|
||||
Finch.call("/foo");
|
||||
|
||||
Finch.route("/", function(bindings) {
|
||||
return Finch.observe(["x"], function(x) {
|
||||
});
|
||||
});
|
||||
Finch.call("/?x=123");
|
||||
Finch.call("/?x=123.456");
|
||||
Finch.call("/?x=true");
|
||||
Finch.call("/?x=false");
|
||||
Finch.call("/?x=stuff");
|
||||
Finch.options({
|
||||
CoerceParameterTypes: true
|
||||
});
|
||||
Finch.call("/?x=123");
|
||||
Finch.call("/?x=123.456");
|
||||
Finch.call("/?x=true");
|
||||
Finch.call("/?x=false");
|
||||
Finch.call("/?x=stuff");
|
||||
Finch.route("/:x", function(_arg) {
|
||||
});
|
||||
Finch.call("/123");
|
||||
Finch.call("/123.456");
|
||||
Finch.call("/true");
|
||||
Finch.call("/false");
|
||||
Finch.call("/stuff");
|
||||
Finch.options({
|
||||
CoerceParameterTypes: true
|
||||
});
|
||||
Finch.call("/123");
|
||||
Finch.call("/123.456");
|
||||
Finch.call("/true");
|
||||
Finch.call("/false");
|
||||
Finch.call("/stuff");
|
||||
|
||||
Finch.navigate("/home");
|
||||
Finch.navigate("/home/news");
|
||||
Finch.navigate("/home");
|
||||
Finch.navigate("/home", {
|
||||
foo: "bar"
|
||||
});
|
||||
Finch.navigate("/home", {
|
||||
hello: "world"
|
||||
});
|
||||
Finch.navigate({
|
||||
foos: "bars"
|
||||
});
|
||||
Finch.navigate({
|
||||
foos: "baz"
|
||||
});
|
||||
Finch.navigate({
|
||||
hello: "world"
|
||||
}, true);
|
||||
Finch.navigate({
|
||||
foos: null
|
||||
}, true);
|
||||
Finch.navigate("/home/news", true);
|
||||
Finch.navigate("/hello world", {});
|
||||
Finch.navigate("/hello world", {
|
||||
foo: "bar bar"
|
||||
});
|
||||
Finch.navigate({
|
||||
foo: "baz baz"
|
||||
});
|
||||
Finch.navigate({
|
||||
hello: 'world world'
|
||||
}, true);
|
||||
Finch.navigate("/home?foo=bar", {
|
||||
hello: "world"
|
||||
});
|
||||
Finch.navigate("/home?foo=bar", {
|
||||
hello: "world",
|
||||
foo: "baz"
|
||||
});
|
||||
Finch.navigate("/home?foo=bar", {
|
||||
hello: "world",
|
||||
free: "bird"
|
||||
});
|
||||
Finch.navigate("#/home", true);
|
||||
Finch.navigate("#/home");
|
||||
Finch.navigate("#/home/news", {
|
||||
free: "birds",
|
||||
hello: "worlds"
|
||||
});
|
||||
Finch.navigate("#/home/news", {
|
||||
foo: "bar"
|
||||
}, true);
|
||||
Finch.navigate("/home/news");
|
||||
Finch.navigate("../");
|
||||
Finch.navigate("./");
|
||||
Finch.navigate("./news");
|
||||
Finch.navigate("/home/news/article");
|
||||
Finch.navigate("../../account");
|
||||
|
||||
Finch.listen();
|
||||
Finch.ignore();
|
||||
Finch.route("/home", function(bindings, continuation) {
|
||||
});
|
||||
Finch.route("/foo", function(bindings, continuation) {
|
||||
});
|
||||
Finch.call("home");
|
||||
Finch.call("foo");
|
||||
Finch.abort();
|
||||
Finch.call("foo");
|
||||
Finch.route("/", {
|
||||
'setup': cb.slash_setup = this.stub(),
|
||||
'load': cb.slash_load = this.stub(),
|
||||
'unload': cb.slash_unload = this.stub(),
|
||||
'teardown': cb.slash_teardown = this.stub()
|
||||
});
|
||||
Finch.route("[/]users/profile", {
|
||||
'setup': cb.profile_setup = this.stub(),
|
||||
'load': cb.profile_load = this.stub(),
|
||||
'unload': cb.profile_unload = this.stub(),
|
||||
'teardown': cb.profile_teardown = this.stub()
|
||||
});
|
||||
Finch.route("[/]:page", {
|
||||
'setup': cb.page_setup = this.stub(),
|
||||
'load': cb.page_load = this.stub(),
|
||||
'unload': cb.page_unload = this.stub(),
|
||||
'teardown': cb.page_teardown = this.stub()
|
||||
});
|
||||
Finch.call("/users");
|
||||
}
|
||||
Vendored
-28
@@ -1,28 +0,0 @@
|
||||
// Type definitions for headroom.js v0.7.0
|
||||
// Project: http://wicky.nillia.ms/headroom.js/
|
||||
// Definitions by: Jakub Olek <https://github.com/hakubo/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
interface HeadroomOptions {
|
||||
offset?: number;
|
||||
tolerance?: any;
|
||||
classes?: {
|
||||
initial?: string;
|
||||
pinned?: string;
|
||||
unpinned?: string;
|
||||
top?: string;
|
||||
notTop?: string;
|
||||
};
|
||||
scroller?: Element;
|
||||
onPin?: () => void;
|
||||
onUnPin?: () => void;
|
||||
onTop?: () => void;
|
||||
onNotTop?: () => void;
|
||||
|
||||
}
|
||||
|
||||
declare class Headroom {
|
||||
constructor(element: Node, options?: HeadroomOptions);
|
||||
constructor(element: Element, options?: HeadroomOptions);
|
||||
init: () => void;
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/// <reference path="HubSpot-pace.d.ts" />
|
||||
|
||||
pace.start({
|
||||
document: false
|
||||
});
|
||||
|
||||
pace.start();
|
||||
|
||||
pace.restart();
|
||||
|
||||
pace.stop();
|
||||
|
||||
var paceOptions: HubSpotPaceInterfaces.PaceOptions;
|
||||
|
||||
paceOptions = {
|
||||
// Disable the 'elements' source
|
||||
elements: false,
|
||||
|
||||
// Only show the progress on regular and ajax-y page navigation,
|
||||
// not every request
|
||||
restartOnRequestAfter: false
|
||||
}
|
||||
|
||||
paceOptions = {
|
||||
ajax: false, // disabled
|
||||
document: false, // disabled
|
||||
eventLag: false, // disabled
|
||||
elements: {
|
||||
selectors: ['.my-page']
|
||||
}
|
||||
};
|
||||
|
||||
paceOptions = {
|
||||
elements: {
|
||||
selectors: ['.timeline,.timeline-error', '.user-profile,.profile-error']
|
||||
}
|
||||
}
|
||||
|
||||
paceOptions = {
|
||||
restartOnPushState: false
|
||||
}
|
||||
|
||||
paceOptions = {
|
||||
restartOnRequestAfter: false
|
||||
}
|
||||
|
||||
pace.options = {
|
||||
restartOnRequestAfter: false
|
||||
}
|
||||
|
||||
pace.ignore(function(){
|
||||
});
|
||||
|
||||
pace.track(function(){
|
||||
});
|
||||
|
||||
pace.options = {
|
||||
ajax: {
|
||||
ignoreURLs: ['some-substring', /some-regexp/]
|
||||
}
|
||||
};
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
- [ ] I tried using the latest `xxxx/xxxx.d.ts` file in this repo and had problems.
|
||||
- [ ] I tried using the `@types/xxxx` package and had problems.
|
||||
- [ ] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
|
||||
- [ ] I have a question that is inappropriate for [StackOverflow](https://stackoverflow.com/). (Please ask any appropriate questions there).
|
||||
- [ ] I want to talk about `xxxx/xxxx.d.ts`.
|
||||
- The authors of that type definition are cc/ @....
|
||||
- [ ] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see `Definitions by:` in `index.d.ts`) so they can respond.
|
||||
- Authors: @....
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/// <reference path="JSONStream.d.ts" />
|
||||
|
||||
import json = require('JSONStream');
|
||||
|
||||
var read: NodeJS.ReadableStream;
|
||||
var write: NodeJS.WritableStream;
|
||||
|
||||
read = read.pipe(json.parse('*'));
|
||||
read = read.pipe(json.parse(['foo/*', 'bar/*']));
|
||||
|
||||
read = json.stringify();
|
||||
read = json.stringify('{', ',', '}');
|
||||
|
||||
read = json.stringifyObject();
|
||||
read = json.stringifyObject('{', ',', '}');
|
||||
Vendored
-22
@@ -1,22 +0,0 @@
|
||||
// Type definitions for JSONStream v0.8.0
|
||||
// Project: http://github.com/dominictarr/JSONStream
|
||||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
declare module 'JSONStream' {
|
||||
|
||||
export interface Options {
|
||||
recurse: boolean;
|
||||
}
|
||||
|
||||
export function parse(pattern: any): NodeJS.ReadWriteStream;
|
||||
export function parse(patterns: any[]): NodeJS.ReadWriteStream;
|
||||
|
||||
export function stringify(): NodeJS.ReadWriteStream;
|
||||
export function stringify(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
|
||||
|
||||
export function stringifyObject(): NodeJS.ReadWriteStream;
|
||||
export function stringifyObject(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
|
||||
}
|
||||
Vendored
-912
@@ -1,912 +0,0 @@
|
||||
// Type definitions for OpenJsCad.js
|
||||
// Project: https://github.com/joostn/OpenJsCad
|
||||
// Definitions by: Dan Marshall <https://github.com/danmarshall>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference path="../threejs/three.d.ts" />
|
||||
|
||||
declare namespace THREE {
|
||||
var CSG: {
|
||||
fromCSG: (csg: CSG, defaultColor: any) => {
|
||||
colorMesh: Mesh;
|
||||
wireframe: Mesh;
|
||||
boundLen: number;
|
||||
};
|
||||
getGeometryVertex: (geometry: any, vertex_position: any) => number;
|
||||
};
|
||||
function OrbitControls(object: any, domElement: any): void;
|
||||
function SpriteCanvasMaterial(parameters?: any): void;
|
||||
interface ICanvasRendererOptions {
|
||||
canvas?: HTMLCanvasElement;
|
||||
alpha?: boolean;
|
||||
}
|
||||
class CanvasRenderer implements Renderer {
|
||||
domElement: HTMLCanvasElement;
|
||||
private pixelRatio;
|
||||
private autoClear;
|
||||
private sortObjects;
|
||||
private sortElements;
|
||||
private info;
|
||||
private _projector;
|
||||
private _renderData;
|
||||
private _elements;
|
||||
private _lights;
|
||||
private _canvas;
|
||||
private _canvasWidth;
|
||||
private _canvasHeight;
|
||||
private _canvasWidthHalf;
|
||||
private _canvasHeightHalf;
|
||||
private _viewportX;
|
||||
private _viewportY;
|
||||
private _viewportWidth;
|
||||
private _viewportHeight;
|
||||
private _context;
|
||||
private _clearColor;
|
||||
private _clearAlpha;
|
||||
private _contextGlobalAlpha;
|
||||
private _contextGlobalCompositeOperation;
|
||||
private _contextStrokeStyle;
|
||||
private _camera;
|
||||
private _contextFillStyle;
|
||||
private _contextLineWidth;
|
||||
private _contextLineCap;
|
||||
private _contextLineJoin;
|
||||
private _contextLineDash;
|
||||
private _v1;
|
||||
private _v2;
|
||||
private _v3;
|
||||
private _v4;
|
||||
private _v5;
|
||||
private _v6;
|
||||
private _v1x;
|
||||
private _v1y;
|
||||
private _v2x;
|
||||
private _v2y;
|
||||
private _v3x;
|
||||
private _v3y;
|
||||
private _v4x;
|
||||
private _v4y;
|
||||
private _v5x;
|
||||
private _v5y;
|
||||
private _v6x;
|
||||
private _v6y;
|
||||
private _color;
|
||||
private _color1;
|
||||
private _color2;
|
||||
private _color3;
|
||||
private _color4;
|
||||
private _diffuseColor;
|
||||
private _emissiveColor;
|
||||
private _lightColor;
|
||||
private _patterns;
|
||||
private _image;
|
||||
private _uvs;
|
||||
private _uv1x;
|
||||
private _uv1y;
|
||||
private _uv2x;
|
||||
private _uv2y;
|
||||
private _uv3x;
|
||||
private _uv3y;
|
||||
private _clipBox;
|
||||
private _clearBox;
|
||||
private _elemBox;
|
||||
private _ambientLight;
|
||||
private _directionalLights;
|
||||
private _pointLights;
|
||||
private _vector3;
|
||||
private _centroid;
|
||||
private _normal;
|
||||
private _normalViewMatrix;
|
||||
constructor(parameters: ICanvasRendererOptions);
|
||||
supportsVertexTextures(): void;
|
||||
setFaceCulling: () => void;
|
||||
getPixelRatio(): number;
|
||||
setPixelRatio(value: any): void;
|
||||
setSize(width: any, height: any, updateStyle: any): void;
|
||||
setViewport(x: any, y: any, width: any, height: any): void;
|
||||
setScissor(): void;
|
||||
enableScissorTest(): void;
|
||||
setClearColor(color: any, alpha: any): void;
|
||||
setClearColorHex(hex: any, alpha: any): void;
|
||||
getClearColor(): Color;
|
||||
getClearAlpha(): number;
|
||||
getMaxAnisotropy(): number;
|
||||
clear(): void;
|
||||
clearColor(): void;
|
||||
clearDepth(): void;
|
||||
clearStencil(): void;
|
||||
render(scene: Scene, camera: Camera, renderTarget?: RenderTarget, forceClear?: boolean): void;
|
||||
calculateLights(): void;
|
||||
calculateLight(position: any, normal: any, color: any): void;
|
||||
renderSprite(v1: any, element: any, material: any): void;
|
||||
renderLine(v1: any, v2: any, element: any, material: any): void;
|
||||
renderFace3(v1: any, v2: any, v3: any, uv1: any, uv2: any, uv3: any, element: any, material: any): void;
|
||||
drawTriangle(x0: any, y0: any, x1: any, y1: any, x2: any, y2: any): void;
|
||||
strokePath(color: any, linewidth: any, linecap: any, linejoin: any): void;
|
||||
fillPath(color: any): void;
|
||||
onTextureUpdate(event: any): void;
|
||||
textureToPattern(texture: any): void;
|
||||
patternPath(x0: any, y0: any, x1: any, y1: any, x2: any, y2: any, u0: any, v0: any, u1: any, v1: any, u2: any, v2: any, texture: any): void;
|
||||
clipImage(x0: any, y0: any, x1: any, y1: any, x2: any, y2: any, u0: any, v0: any, u1: any, v1: any, u2: any, v2: any, image: any): void;
|
||||
expand(v1: any, v2: any, pixels: any): void;
|
||||
setOpacity(value: any): void;
|
||||
setBlending(value: any): void;
|
||||
setLineWidth(value: any): void;
|
||||
setLineCap(value: any): void;
|
||||
setLineJoin(value: any): void;
|
||||
setStrokeStyle(value: any): void;
|
||||
setFillStyle(value: any): void;
|
||||
setLineDash(value: any): void;
|
||||
}
|
||||
function RenderableObject(): void;
|
||||
function RenderableFace(): void;
|
||||
function RenderableVertex(): void;
|
||||
function RenderableLine(): void;
|
||||
function RenderableSprite(): void;
|
||||
function Projector(): void;
|
||||
}
|
||||
declare namespace OpenJsCad {
|
||||
interface ILog {
|
||||
(x: string): void;
|
||||
prevLogTime?: number;
|
||||
}
|
||||
var log: ILog;
|
||||
interface IViewerOptions {
|
||||
drawLines?: boolean;
|
||||
drawFaces?: boolean;
|
||||
color?: number[];
|
||||
bgColor?: number;
|
||||
noWebGL?: boolean;
|
||||
}
|
||||
interface ProcessorOptions extends IViewerOptions {
|
||||
verbose?: boolean;
|
||||
viewerwidth?: number;
|
||||
viewerheight?: number;
|
||||
viewerheightratio?: number;
|
||||
}
|
||||
class Viewer {
|
||||
private perspective;
|
||||
private drawOptions;
|
||||
private size;
|
||||
private defaultColor_;
|
||||
private bgColor_;
|
||||
private containerElm_;
|
||||
private scene_;
|
||||
private camera_;
|
||||
private controls_;
|
||||
private renderer_;
|
||||
private canvas;
|
||||
private pauseRender_;
|
||||
private requestID_;
|
||||
constructor(containerElm: any, size: any, options: IViewerOptions);
|
||||
createScene(drawAxes: any, axLen: any): void;
|
||||
createCamera(): void;
|
||||
createControls(canvas: any): void;
|
||||
webGLAvailable(): boolean;
|
||||
createRenderer(bool_noWebGL: any): void;
|
||||
render(): void;
|
||||
animate(): void;
|
||||
cancelAnimate(): void;
|
||||
refreshRenderer(bool_noWebGL: any): void;
|
||||
drawAxes(axLen: any): void;
|
||||
setCsg(csg: any, resetZoom: any): void;
|
||||
applyDrawOptions(): void;
|
||||
clear(): void;
|
||||
getUserMeshes(str?: any): THREE.Object3D[];
|
||||
resetZoom(r: any): void;
|
||||
parseSizeParams(): void;
|
||||
handleResize(): void;
|
||||
}
|
||||
function makeAbsoluteUrl(url: any, baseurl: any): any;
|
||||
function isChrome(): boolean;
|
||||
function runMainInWorker(mainParameters: any): void;
|
||||
function expandResultObjectArray(result: any): any;
|
||||
function checkResult(result: any): void;
|
||||
function resultToCompactBinary(resultin: any): any;
|
||||
function resultFromCompactBinary(resultin: any): any;
|
||||
function parseJsCadScriptSync(script: any, mainParameters: any, debugging: any): any;
|
||||
function parseJsCadScriptASync(script: any, mainParameters: any, options: any, callback: any): Worker;
|
||||
function getWindowURL(): URL;
|
||||
function textToBlobUrl(txt: any): string;
|
||||
function revokeBlobUrl(url: any): void;
|
||||
function FileSystemApiErrorHandler(fileError: any, operation: any): void;
|
||||
function AlertUserOfUncaughtExceptions(): void;
|
||||
function getParamDefinitions(script: any): any[];
|
||||
interface EventHandler {
|
||||
(ev?: Event): any;
|
||||
}
|
||||
/**
|
||||
* options parameter:
|
||||
* - drawLines: display wireframe lines
|
||||
* - drawFaces: display surfaces
|
||||
* - bgColor: canvas background color
|
||||
* - color: object color
|
||||
* - viewerwidth, viewerheight: set rendering size. Works with any css unit.
|
||||
* viewerheight can also be specified as a ratio to width, ie number e (0, 1]
|
||||
* - noWebGL: force render without webGL
|
||||
* - verbose: show additional info (currently only time used for rendering)
|
||||
*/
|
||||
interface ViewerSize {
|
||||
widthDefault: string;
|
||||
heightDefault: string;
|
||||
width: number;
|
||||
height: number;
|
||||
heightratio: number;
|
||||
}
|
||||
class Processor {
|
||||
private containerdiv;
|
||||
private options;
|
||||
private onchange;
|
||||
private static widthDefault;
|
||||
private static heightDefault;
|
||||
private viewerdiv;
|
||||
private viewer;
|
||||
private viewerSize;
|
||||
private processing;
|
||||
private currentObject;
|
||||
private hasValidCurrentObject;
|
||||
private hasOutputFile;
|
||||
private worker;
|
||||
private paramDefinitions;
|
||||
private paramControls;
|
||||
private script;
|
||||
private hasError;
|
||||
private debugging;
|
||||
private errordiv;
|
||||
private errorpre;
|
||||
private statusdiv;
|
||||
private controldiv;
|
||||
private statusspan;
|
||||
private statusbuttons;
|
||||
private abortbutton;
|
||||
private renderedElementDropdown;
|
||||
private formatDropdown;
|
||||
private generateOutputFileButton;
|
||||
private downloadOutputFileLink;
|
||||
private parametersdiv;
|
||||
private parameterstable;
|
||||
private currentFormat;
|
||||
private filename;
|
||||
private currentObjects;
|
||||
private currentObjectIndex;
|
||||
private isFirstRender_;
|
||||
private outputFileDirEntry;
|
||||
private outputFileBlobUrl;
|
||||
constructor(containerdiv: HTMLDivElement, options?: ProcessorOptions, onchange?: EventHandler);
|
||||
static convertToSolid(obj: any): any;
|
||||
cleanOption(option: any, deflt: any): any;
|
||||
toggleDrawOption(str: any): boolean;
|
||||
setDrawOption(str: any, bool: any): void;
|
||||
handleResize(): void;
|
||||
createElements(): void;
|
||||
getFilenameForRenderedObject(): string;
|
||||
setRenderedObjects(obj: any): void;
|
||||
setSelectedObjectIndex(index: number): void;
|
||||
selectedFormat(): any;
|
||||
selectedFormatInfo(): any;
|
||||
updateDownloadLink(): void;
|
||||
clearViewer(): void;
|
||||
abort(): void;
|
||||
enableItems(): void;
|
||||
setOpenJsCadPath(path: string): void;
|
||||
addLibrary(lib: any): void;
|
||||
setError(txt: string): void;
|
||||
setDebugging(debugging: boolean): void;
|
||||
setJsCad(script: string, filename?: string): void;
|
||||
getParamValues(): {};
|
||||
rebuildSolid(): void;
|
||||
hasSolid(): boolean;
|
||||
isProcessing(): boolean;
|
||||
clearOutputFile(): void;
|
||||
generateOutputFile(): void;
|
||||
currentObjectToBlob(): any;
|
||||
supportedFormatsForCurrentObject(): string[];
|
||||
formatInfo(format: any): any;
|
||||
downloadLinkTextForCurrentObject(): string;
|
||||
generateOutputFileBlobUrl(): void;
|
||||
generateOutputFileFileSystem(): void;
|
||||
createParamControls(): void;
|
||||
}
|
||||
}
|
||||
interface Window {
|
||||
Worker: Worker;
|
||||
// URL: URL;
|
||||
webkitURL: URL;
|
||||
requestFileSystem: any;
|
||||
webkitRequestFileSystem: any;
|
||||
}
|
||||
interface IAMFStringOptions {
|
||||
unit: string;
|
||||
}
|
||||
declare class CxG {
|
||||
toStlString(): string;
|
||||
toStlBinary(): void;
|
||||
toAMFString(AMFStringOptions?: IAMFStringOptions): void;
|
||||
getBounds(): CxG[];
|
||||
transform(matrix4x4: CSG.Matrix4x4): CxG;
|
||||
mirrored(plane: CSG.Plane): CxG;
|
||||
mirroredX(): CxG;
|
||||
mirroredY(): CxG;
|
||||
mirroredZ(): CxG;
|
||||
translate(v: number[]): CxG;
|
||||
translate(v: CSG.Vector3D): CxG;
|
||||
scale(f: CSG.Vector3D): CxG;
|
||||
rotateX(deg: number): CxG;
|
||||
rotateY(deg: number): CxG;
|
||||
rotateZ(deg: number): CxG;
|
||||
rotate(rotationCenter: CSG.Vector3D, rotationAxis: CSG.Vector3D, degrees: number): CxG;
|
||||
rotateEulerAngles(alpha: number, beta: number, gamma: number, position: number[]): CxG;
|
||||
}
|
||||
interface ICenter {
|
||||
center(cAxes: string[]): CxG;
|
||||
}
|
||||
declare class CSG extends CxG implements ICenter {
|
||||
polygons: CSG.Polygon[];
|
||||
properties: CSG.Properties;
|
||||
isCanonicalized: boolean;
|
||||
isRetesselated: boolean;
|
||||
cachedBoundingBox: CSG.Vector3D[];
|
||||
static defaultResolution2D: number;
|
||||
static defaultResolution3D: number;
|
||||
static fromPolygons(polygons: CSG.Polygon[]): CSG;
|
||||
static fromSlices(options: any): CSG;
|
||||
static fromObject(obj: any): CSG;
|
||||
static fromCompactBinary(bin: any): CSG;
|
||||
toPolygons(): CSG.Polygon[];
|
||||
union(csg: CSG[]): CSG;
|
||||
union(csg: CSG): CSG;
|
||||
unionSub(csg: CSG, retesselate?: boolean, canonicalize?: boolean): CSG;
|
||||
unionForNonIntersecting(csg: CSG): CSG;
|
||||
subtract(csg: CSG[]): CSG;
|
||||
subtract(csg: CSG): CSG;
|
||||
subtractSub(csg: CSG, retesselate: boolean, canonicalize: boolean): CSG;
|
||||
intersect(csg: CSG[]): CSG;
|
||||
intersect(csg: CSG): CSG;
|
||||
intersectSub(csg: CSG, retesselate?: boolean, canonicalize?: boolean): CSG;
|
||||
invert(): CSG;
|
||||
transform1(matrix4x4: CSG.Matrix4x4): CSG;
|
||||
transform(matrix4x4: CSG.Matrix4x4): CSG;
|
||||
toString(): string;
|
||||
expand(radius: number, resolution: number): CSG;
|
||||
contract(radius: number, resolution: number): CSG;
|
||||
stretchAtPlane(normal: number[], point: number[], length: number): CSG;
|
||||
expandedShell(radius: number, resolution: number, unionWithThis: boolean): CSG;
|
||||
canonicalized(): CSG;
|
||||
reTesselated(): CSG;
|
||||
getBounds(): CSG.Vector3D[];
|
||||
mayOverlap(csg: CSG): boolean;
|
||||
cutByPlane(plane: CSG.Plane): CSG;
|
||||
connectTo(myConnector: CSG.Connector, otherConnector: CSG.Connector, mirror: boolean, normalrotation: number): CSG;
|
||||
setShared(shared: CSG.Polygon.Shared): CSG;
|
||||
setColor(args: any): CSG;
|
||||
toCompactBinary(): {
|
||||
"class": string;
|
||||
numPolygons: number;
|
||||
numVerticesPerPolygon: Uint32Array;
|
||||
polygonPlaneIndexes: Uint32Array;
|
||||
polygonSharedIndexes: Uint32Array;
|
||||
polygonVertices: Uint32Array;
|
||||
vertexData: Float64Array;
|
||||
planeData: Float64Array;
|
||||
shared: CSG.Polygon.Shared[];
|
||||
};
|
||||
toPointCloud(cuberadius: any): CSG;
|
||||
getTransformationAndInverseTransformationToFlatLying(): any;
|
||||
getTransformationToFlatLying(): any;
|
||||
lieFlat(): CSG;
|
||||
projectToOrthoNormalBasis(orthobasis: CSG.OrthoNormalBasis): CAG;
|
||||
sectionCut(orthobasis: CSG.OrthoNormalBasis): CAG;
|
||||
fixTJunctions(): CSG;
|
||||
toTriangles(): any[];
|
||||
getFeatures(features: any): any;
|
||||
center(cAxes: string[]): CxG;
|
||||
toX3D(): Blob;
|
||||
toStlBinary(): Blob;
|
||||
toStlString(): string;
|
||||
toAMFString(m: IAMFStringOptions): Blob;
|
||||
}
|
||||
declare namespace CSG {
|
||||
function fnNumberSort(a: any, b: any): number;
|
||||
function parseOption(options: any, optionname: any, defaultvalue: any): any;
|
||||
function parseOptionAs3DVector(options: any, optionname: any, defaultvalue: any): Vector3D;
|
||||
function parseOptionAs3DVectorList(options: any, optionname: any, defaultvalue: any): any;
|
||||
function parseOptionAs2DVector(options: any, optionname: any, defaultvalue: any): any;
|
||||
function parseOptionAsFloat(options: any, optionname: any, defaultvalue: any): any;
|
||||
function parseOptionAsInt(options: any, optionname: any, defaultvalue: any): any;
|
||||
function parseOptionAsBool(options: any, optionname: any, defaultvalue: any): any;
|
||||
function cube(options: any): CSG;
|
||||
function sphere(options: any): CSG;
|
||||
function cylinder(options: any): CSG;
|
||||
function roundedCylinder(options: any): CSG;
|
||||
function roundedCube(options: any): CSG;
|
||||
/**
|
||||
* polyhedron accepts openscad style arguments. I.e. define face vertices clockwise looking from outside
|
||||
*/
|
||||
function polyhedron(options: any): CSG;
|
||||
function IsFloat(n: any): boolean;
|
||||
function solve2Linear(a: any, b: any, c: any, d: any, u: any, v: any): number[];
|
||||
class Vector3D extends CxG {
|
||||
x: number;
|
||||
y: number;
|
||||
z: number;
|
||||
constructor(v3: Vector3D);
|
||||
constructor(v2: Vector2D);
|
||||
constructor(v2: number[]);
|
||||
constructor(x: number, y: number);
|
||||
constructor(x: number, y: number, z: number);
|
||||
static Create(x: number, y: number, z: number): Vector3D;
|
||||
clone(): Vector3D;
|
||||
negated(): Vector3D;
|
||||
abs(): Vector3D;
|
||||
plus(a: Vector3D): Vector3D;
|
||||
minus(a: Vector3D): Vector3D;
|
||||
times(a: number): Vector3D;
|
||||
dividedBy(a: number): Vector3D;
|
||||
dot(a: Vector3D): number;
|
||||
lerp(a: Vector3D, t: number): Vector3D;
|
||||
lengthSquared(): number;
|
||||
length(): number;
|
||||
unit(): Vector3D;
|
||||
cross(a: Vector3D): Vector3D;
|
||||
distanceTo(a: Vector3D): number;
|
||||
distanceToSquared(a: Vector3D): number;
|
||||
equals(a: Vector3D): boolean;
|
||||
multiply4x4(matrix4x4: Matrix4x4): Vector3D;
|
||||
transform(matrix4x4: Matrix4x4): Vector3D;
|
||||
toString(): string;
|
||||
randomNonParallelVector(): Vector3D;
|
||||
min(p: Vector3D): Vector3D;
|
||||
max(p: Vector3D): Vector3D;
|
||||
toStlString(): string;
|
||||
toAMFString(): string;
|
||||
}
|
||||
class Vertex extends CxG {
|
||||
pos: Vector3D;
|
||||
tag: number;
|
||||
constructor(pos: Vector3D);
|
||||
static fromObject(obj: any): Vertex;
|
||||
flipped(): Vertex;
|
||||
getTag(): number;
|
||||
interpolate(other: Vertex, t: number): Vertex;
|
||||
transform(matrix4x4: Matrix4x4): Vertex;
|
||||
toString(): string;
|
||||
toStlString(): string;
|
||||
toAMFString(): string;
|
||||
}
|
||||
class Plane extends CxG {
|
||||
normal: Vector3D;
|
||||
w: number;
|
||||
tag: number;
|
||||
constructor(normal: Vector3D, w: number);
|
||||
static fromObject(obj: any): Plane;
|
||||
static EPSILON: number;
|
||||
static fromVector3Ds(a: Vector3D, b: Vector3D, c: Vector3D): Plane;
|
||||
static anyPlaneFromVector3Ds(a: Vector3D, b: Vector3D, c: Vector3D): Plane;
|
||||
static fromPoints(a: Vector3D, b: Vector3D, c: Vector3D): Plane;
|
||||
static fromNormalAndPoint(normal: Vector3D, point: Vector3D): Plane;
|
||||
static fromNormalAndPoint(normal: number[], point: number[]): Plane;
|
||||
flipped(): Plane;
|
||||
getTag(): number;
|
||||
equals(n: Plane): boolean;
|
||||
transform(matrix4x4: Matrix4x4): Plane;
|
||||
splitPolygon(polygon: Polygon): {
|
||||
type: any;
|
||||
front: any;
|
||||
back: any;
|
||||
};
|
||||
splitLineBetweenPoints(p1: Vector3D, p2: Vector3D): Vector3D;
|
||||
intersectWithLine(line3d: Line3D): Vector3D;
|
||||
intersectWithPlane(plane: Plane): Line3D;
|
||||
signedDistanceToPoint(point: Vector3D): number;
|
||||
toString(): string;
|
||||
mirrorPoint(point3d: Vector3D): Vector3D;
|
||||
}
|
||||
class Polygon extends CxG {
|
||||
vertices: Vertex[];
|
||||
shared: Polygon.Shared;
|
||||
plane: Plane;
|
||||
cachedBoundingSphere: any;
|
||||
cachedBoundingBox: Vector3D[];
|
||||
static defaultShared: CSG.Polygon.Shared;
|
||||
constructor(vertices: Vector3D, shared?: Polygon.Shared, plane?: Plane);
|
||||
constructor(vertices: Vertex[], shared?: Polygon.Shared, plane?: Plane);
|
||||
static fromObject(obj: any): Polygon;
|
||||
checkIfConvex(): void;
|
||||
setColor(args: any): Polygon;
|
||||
getSignedVolume(): number;
|
||||
getArea(): number;
|
||||
getTetraFeatures(features: any): any[];
|
||||
extrude(offsetvector: any): CSG;
|
||||
boundingSphere(): any;
|
||||
boundingBox(): Vector3D[];
|
||||
flipped(): Polygon;
|
||||
transform(matrix4x4: Matrix4x4): Polygon;
|
||||
toString(): string;
|
||||
projectToOrthoNormalBasis(orthobasis: OrthoNormalBasis): CAG;
|
||||
/**
|
||||
* Creates solid from slices (CSG.Polygon) by generating walls
|
||||
* @param {Object} options Solid generating options
|
||||
* - numslices {Number} Number of slices to be generated
|
||||
* - callback(t, slice) {Function} Callback function generating slices.
|
||||
* arguments: t = [0..1], slice = [0..numslices - 1]
|
||||
* return: CSG.Polygon or null to skip
|
||||
* - loop {Boolean} no flats, only walls, it's used to generate solids like a tor
|
||||
*/
|
||||
solidFromSlices(options: any): CSG;
|
||||
/**
|
||||
*
|
||||
* @param walls Array of wall polygons
|
||||
* @param bottom Bottom polygon
|
||||
* @param top Top polygon
|
||||
*/
|
||||
private _addWalls(walls, bottom, top, bFlipped);
|
||||
static verticesConvex(vertices: Vertex[], planenormal: any): boolean;
|
||||
static createFromPoints(points: number[][], shared?: CSG.Polygon.Shared, plane?: Plane): Polygon;
|
||||
static isConvexPoint(prevpoint: any, point: any, nextpoint: any, normal: any): boolean;
|
||||
static isStrictlyConvexPoint(prevpoint: any, point: any, nextpoint: any, normal: any): boolean;
|
||||
toStlString(): string;
|
||||
}
|
||||
}
|
||||
declare namespace CSG.Polygon {
|
||||
class Shared {
|
||||
color: any;
|
||||
tag: any;
|
||||
constructor(color: any);
|
||||
static fromObject(obj: any): Shared;
|
||||
static fromColor(args: any): Shared;
|
||||
getTag(): any;
|
||||
getHash(): any;
|
||||
}
|
||||
}
|
||||
declare namespace CSG {
|
||||
class PolygonTreeNode {
|
||||
parent: any;
|
||||
children: any;
|
||||
polygon: Polygon;
|
||||
removed: boolean;
|
||||
constructor();
|
||||
addPolygons(polygons: any): void;
|
||||
remove(): void;
|
||||
isRemoved(): boolean;
|
||||
isRootNode(): boolean;
|
||||
invert(): void;
|
||||
getPolygon(): Polygon;
|
||||
getPolygons(result: Polygon[]): void;
|
||||
splitByPlane(plane: any, coplanarfrontnodes: any, coplanarbacknodes: any, frontnodes: any, backnodes: any): void;
|
||||
_splitByPlane(plane: any, coplanarfrontnodes: any, coplanarbacknodes: any, frontnodes: any, backnodes: any): void;
|
||||
addChild(polygon: Polygon): PolygonTreeNode;
|
||||
invertSub(): void;
|
||||
recursivelyInvalidatePolygon(): void;
|
||||
}
|
||||
class Tree {
|
||||
polygonTree: PolygonTreeNode;
|
||||
rootnode: Node;
|
||||
constructor(polygons: Polygon[]);
|
||||
invert(): void;
|
||||
clipTo(tree: Tree, alsoRemovecoplanarFront?: boolean): void;
|
||||
allPolygons(): Polygon[];
|
||||
addPolygons(polygons: Polygon[]): void;
|
||||
}
|
||||
class Node {
|
||||
parent: Node;
|
||||
plane: Plane;
|
||||
front: any;
|
||||
back: any;
|
||||
polygontreenodes: PolygonTreeNode[];
|
||||
constructor(parent: Node);
|
||||
invert(): void;
|
||||
clipPolygons(polygontreenodes: PolygonTreeNode[], alsoRemovecoplanarFront: boolean): void;
|
||||
clipTo(tree: Tree, alsoRemovecoplanarFront: boolean): void;
|
||||
addPolygonTreeNodes(polygontreenodes: PolygonTreeNode[]): void;
|
||||
getParentPlaneNormals(normals: Vector3D[], maxdepth: number): void;
|
||||
}
|
||||
class Matrix4x4 {
|
||||
elements: number[];
|
||||
constructor(elements?: number[]);
|
||||
plus(m: Matrix4x4): Matrix4x4;
|
||||
minus(m: Matrix4x4): Matrix4x4;
|
||||
multiply(m: Matrix4x4): Matrix4x4;
|
||||
clone(): Matrix4x4;
|
||||
rightMultiply1x3Vector(v: Vector3D): Vector3D;
|
||||
leftMultiply1x3Vector(v: Vector3D): Vector3D;
|
||||
rightMultiply1x2Vector(v: Vector2D): Vector2D;
|
||||
leftMultiply1x2Vector(v: Vector2D): Vector2D;
|
||||
isMirroring(): boolean;
|
||||
static unity(): Matrix4x4;
|
||||
static rotationX(degrees: number): Matrix4x4;
|
||||
static rotationY(degrees: number): Matrix4x4;
|
||||
static rotationZ(degrees: number): Matrix4x4;
|
||||
static rotation(rotationCenter: CSG.Vector3D, rotationAxis: CSG.Vector3D, degrees: number): Matrix4x4;
|
||||
static translation(v: number[]): Matrix4x4;
|
||||
static translation(v: Vector3D): Matrix4x4;
|
||||
static mirroring(plane: Plane): Matrix4x4;
|
||||
static scaling(v: number[]): Matrix4x4;
|
||||
static scaling(v: Vector3D): Matrix4x4;
|
||||
}
|
||||
class Vector2D extends CxG {
|
||||
x: number;
|
||||
y: number;
|
||||
constructor(x: number, y: number);
|
||||
constructor(x: number[]);
|
||||
constructor(x: Vector2D);
|
||||
static fromAngle(radians: number): Vector2D;
|
||||
static fromAngleDegrees(degrees: number): Vector2D;
|
||||
static fromAngleRadians(radians: number): Vector2D;
|
||||
static Create(x: number, y: number): Vector2D;
|
||||
toVector3D(z: number): Vector3D;
|
||||
equals(a: Vector2D): boolean;
|
||||
clone(): Vector2D;
|
||||
negated(): Vector2D;
|
||||
plus(a: Vector2D): Vector2D;
|
||||
minus(a: Vector2D): Vector2D;
|
||||
times(a: number): Vector2D;
|
||||
dividedBy(a: number): Vector2D;
|
||||
dot(a: Vector2D): number;
|
||||
lerp(a: Vector2D, t: number): Vector2D;
|
||||
length(): number;
|
||||
distanceTo(a: Vector2D): number;
|
||||
distanceToSquared(a: Vector2D): number;
|
||||
lengthSquared(): number;
|
||||
unit(): Vector2D;
|
||||
cross(a: Vector2D): number;
|
||||
normal(): Vector2D;
|
||||
multiply4x4(matrix4x4: Matrix4x4): Vector2D;
|
||||
transform(matrix4x4: Matrix4x4): Vector2D;
|
||||
angle(): number;
|
||||
angleDegrees(): number;
|
||||
angleRadians(): number;
|
||||
min(p: Vector2D): Vector2D;
|
||||
max(p: Vector2D): Vector2D;
|
||||
toString(): string;
|
||||
abs(): Vector2D;
|
||||
}
|
||||
class Line2D extends CxG {
|
||||
normal: Vector2D;
|
||||
w: number;
|
||||
constructor(normal: Vector2D, w: number);
|
||||
static fromPoints(p1: Vector2D, p2: Vector2D): Line2D;
|
||||
reverse(): Line2D;
|
||||
equals(l: Line2D): boolean;
|
||||
origin(): Vector2D;
|
||||
direction(): Vector2D;
|
||||
xAtY(y: number): number;
|
||||
absDistanceToPoint(point: Vector2D): number;
|
||||
intersectWithLine(line2d: Line2D): Vector2D;
|
||||
transform(matrix4x4: Matrix4x4): Line2D;
|
||||
}
|
||||
class Line3D extends CxG {
|
||||
point: Vector3D;
|
||||
direction: Vector3D;
|
||||
constructor(point: Vector3D, direction: Vector3D);
|
||||
static fromPoints(p1: Vector3D, p2: Vector3D): Line3D;
|
||||
static fromPlanes(p1: Plane, p2: Plane): Line3D;
|
||||
intersectWithPlane(plane: Plane): Vector3D;
|
||||
clone(): Line3D;
|
||||
reverse(): Line3D;
|
||||
transform(matrix4x4: Matrix4x4): Line3D;
|
||||
closestPointOnLine(point: Vector3D): Vector3D;
|
||||
distanceToPoint(point: Vector3D): number;
|
||||
equals(line3d: Line3D): boolean;
|
||||
}
|
||||
class OrthoNormalBasis extends CxG {
|
||||
v: Vector3D;
|
||||
u: Vector3D;
|
||||
plane: Plane;
|
||||
planeorigin: Vector3D;
|
||||
constructor(plane: Plane, rightvector?: Vector3D);
|
||||
static GetCartesian(xaxisid: string, yaxisid: string): OrthoNormalBasis;
|
||||
static Z0Plane(): OrthoNormalBasis;
|
||||
getProjectionMatrix(): Matrix4x4;
|
||||
getInverseProjectionMatrix(): Matrix4x4;
|
||||
to2D(vec3: Vector3D): Vector2D;
|
||||
to3D(vec2: Vector2D): Vector3D;
|
||||
line3Dto2D(line3d: Line3D): Line2D;
|
||||
line2Dto3D(line2d: Line2D): Line3D;
|
||||
transform(matrix4x4: Matrix4x4): OrthoNormalBasis;
|
||||
}
|
||||
function interpolateBetween2DPointsForY(point1: Vector2D, point2: Vector2D, y: number): number;
|
||||
function reTesselateCoplanarPolygons(sourcepolygons: CSG.Polygon[], destpolygons: CSG.Polygon[]): void;
|
||||
class fuzzyFactory {
|
||||
multiplier: number;
|
||||
lookuptable: any;
|
||||
constructor(numdimensions: number, tolerance: number);
|
||||
lookupOrCreate(els: any, creatorCallback: any): any;
|
||||
}
|
||||
class fuzzyCSGFactory {
|
||||
vertexfactory: fuzzyFactory;
|
||||
planefactory: fuzzyFactory;
|
||||
polygonsharedfactory: any;
|
||||
constructor();
|
||||
getPolygonShared(sourceshared: Polygon.Shared): Polygon.Shared;
|
||||
getVertex(sourcevertex: Vertex): Vertex;
|
||||
getPlane(sourceplane: Plane): Plane;
|
||||
getPolygon(sourcepolygon: Polygon): Polygon;
|
||||
getCSG(sourcecsg: CSG): CSG;
|
||||
}
|
||||
var staticTag: number;
|
||||
function getTag(): number;
|
||||
class Properties {
|
||||
cube: Properties;
|
||||
center: any;
|
||||
facecenters: any[];
|
||||
roundedCube: Properties;
|
||||
cylinder: Properties;
|
||||
start: any;
|
||||
end: any;
|
||||
facepointH: any;
|
||||
facepointH90: any;
|
||||
sphere: Properties;
|
||||
facepoint: any;
|
||||
roundedCylinder: any;
|
||||
_transform(matrix4x4: Matrix4x4): Properties;
|
||||
_merge(otherproperties: Properties): Properties;
|
||||
static transformObj(source: any, result: any, matrix4x4: Matrix4x4): void;
|
||||
static cloneObj(source: any, result: any): void;
|
||||
static addFrom(result: any, otherproperties: Properties): void;
|
||||
}
|
||||
class Connector extends CxG {
|
||||
point: Vector3D;
|
||||
axisvector: Vector3D;
|
||||
normalvector: Vector3D;
|
||||
constructor(point: number[], axisvector: Vector3D, normalvector: number[]);
|
||||
constructor(point: number[], axisvector: number[], normalvector: number[]);
|
||||
constructor(point: number[], axisvector: number[], normalvector: Vector3D);
|
||||
constructor(point: Vector3D, axisvector: number[], normalvector: Vector3D);
|
||||
constructor(point: Vector3D, axisvector: number[], normalvector: number[]);
|
||||
constructor(point: Vector3D, axisvector: Vector3D, normalvector: Vector3D);
|
||||
normalized(): Connector;
|
||||
transform(matrix4x4: Matrix4x4): Connector;
|
||||
getTransformationTo(other: Connector, mirror: boolean, normalrotation: number): Matrix4x4;
|
||||
axisLine(): Line3D;
|
||||
extend(distance: number): Connector;
|
||||
}
|
||||
class ConnectorList {
|
||||
connectors_: Connector[];
|
||||
closed: boolean;
|
||||
constructor(connectors: Connector[]);
|
||||
static defaultNormal: number[];
|
||||
static fromPath2D(path2D: CSG.Path2D, arg1: any, arg2: any): ConnectorList;
|
||||
static _fromPath2DTangents(path2D: any, start: any, end: any): ConnectorList;
|
||||
static _fromPath2DExplicit(path2D: any, angleIsh: any): ConnectorList;
|
||||
setClosed(bool: boolean): void;
|
||||
appendConnector(conn: Connector): void;
|
||||
followWith(cagish: any): CSG;
|
||||
verify(): void;
|
||||
}
|
||||
interface IRadiusOptions {
|
||||
radius?: number;
|
||||
resolution?: number;
|
||||
}
|
||||
interface ICircleOptions extends IRadiusOptions {
|
||||
center?: Vector2D | number[];
|
||||
}
|
||||
interface IArcOptions extends ICircleOptions {
|
||||
startangle?: number;
|
||||
endangle?: number;
|
||||
maketangent?: boolean;
|
||||
}
|
||||
interface IEllpiticalArcOptions extends IRadiusOptions {
|
||||
clockwise?: boolean;
|
||||
large?: boolean;
|
||||
xaxisrotation?: number;
|
||||
xradius?: number;
|
||||
yradius?: number;
|
||||
}
|
||||
interface IRectangleOptions {
|
||||
center?: Vector2D;
|
||||
corner1?: Vector2D;
|
||||
corner2?: Vector2D;
|
||||
radius?: Vector2D;
|
||||
}
|
||||
interface IRoundRectangleOptions {
|
||||
roundradius: number;
|
||||
resolution?: number;
|
||||
}
|
||||
class Path2D extends CxG {
|
||||
closed: boolean;
|
||||
points: Vector2D[];
|
||||
lastBezierControlPoint: Vector2D;
|
||||
constructor(points: number[], closed?: boolean);
|
||||
constructor(points: Vector2D[], closed?: boolean);
|
||||
static arc(options: IArcOptions): Path2D;
|
||||
concat(otherpath: Path2D): Path2D;
|
||||
appendPoint(point: Vector2D): Path2D;
|
||||
appendPoints(points: Vector2D[]): Path2D;
|
||||
close(): Path2D;
|
||||
rectangularExtrude(width: number, height: number, resolution: number): CSG;
|
||||
expandToCAG(pathradius: number, resolution: number): CAG;
|
||||
innerToCAG(): CAG;
|
||||
transform(matrix4x4: Matrix4x4): Path2D;
|
||||
appendBezier(controlpoints: any, options: any): Path2D;
|
||||
appendArc(endpoint: Vector2D, options: IEllpiticalArcOptions): Path2D;
|
||||
}
|
||||
}
|
||||
declare class CAG extends CxG implements ICenter {
|
||||
sides: CAG.Side[];
|
||||
isCanonicalized: boolean;
|
||||
constructor();
|
||||
static fromSides(sides: CAG.Side[]): CAG;
|
||||
static fromPoints(points: CSG.Vector2D[]): CAG;
|
||||
static fromPointsNoCheck(points: CSG.Vector2D[]): CAG;
|
||||
static fromFakeCSG(csg: CSG): CAG;
|
||||
static linesIntersect(p0start: CSG.Vector2D, p0end: CSG.Vector2D, p1start: CSG.Vector2D, p1end: CSG.Vector2D): boolean;
|
||||
static circle(options: CSG.ICircleOptions): CAG;
|
||||
static rectangle(options: CSG.IRectangleOptions): CAG;
|
||||
static roundedRectangle(options: any): CAG;
|
||||
static fromCompactBinary(bin: any): CAG;
|
||||
toString(): string;
|
||||
_toCSGWall(z0: any, z1: any): CSG;
|
||||
_toVector3DPairs(m: CSG.Matrix4x4): CSG.Vector3D[][];
|
||||
_toPlanePolygons(options: any): CSG.Polygon[];
|
||||
_toWallPolygons(options: any): any[];
|
||||
union(cag: CAG[]): CAG;
|
||||
union(cag: CAG): CAG;
|
||||
subtract(cag: CAG[]): CAG;
|
||||
subtract(cag: CAG): CAG;
|
||||
intersect(cag: CAG[]): CAG;
|
||||
intersect(cag: CAG): CAG;
|
||||
transform(matrix4x4: CSG.Matrix4x4): CAG;
|
||||
area(): number;
|
||||
flipped(): CAG;
|
||||
getBounds(): CSG.Vector2D[];
|
||||
isSelfIntersecting(): boolean;
|
||||
expandedShell(radius: number, resolution: number): CAG;
|
||||
expand(radius: number, resolution: number): CAG;
|
||||
contract(radius: number, resolution: number): CAG;
|
||||
extrudeInOrthonormalBasis(orthonormalbasis: CSG.OrthoNormalBasis, depth: number, options?: any): CSG;
|
||||
extrudeInPlane(axis1: any, axis2: any, depth: any, options: any): CSG;
|
||||
extrude(options: CAG_extrude_options): CSG;
|
||||
rotateExtrude(options: any): CSG;
|
||||
check(): void;
|
||||
canonicalized(): CAG;
|
||||
toCompactBinary(): {
|
||||
'class': string;
|
||||
sideVertexIndices: Uint32Array;
|
||||
vertexData: Float64Array;
|
||||
};
|
||||
getOutlinePaths(): CSG.Path2D[];
|
||||
overCutInsideCorners(cutterradius: any): CAG;
|
||||
center(cAxes: string[]): CxG;
|
||||
toDxf(): Blob;
|
||||
static PathsToDxf(paths: CSG.Path2D[]): Blob;
|
||||
}
|
||||
declare namespace CAG {
|
||||
class Vertex {
|
||||
pos: CSG.Vector2D;
|
||||
tag: number;
|
||||
constructor(pos: CSG.Vector2D);
|
||||
toString(): string;
|
||||
getTag(): number;
|
||||
}
|
||||
class Side extends CxG {
|
||||
vertex0: Vertex;
|
||||
vertex1: Vertex;
|
||||
tag: number;
|
||||
constructor(vertex0: Vertex, vertex1: Vertex);
|
||||
static _fromFakePolygon(polygon: CSG.Polygon): Side;
|
||||
toString(): string;
|
||||
toPolygon3D(z0: any, z1: any): CSG.Polygon;
|
||||
transform(matrix4x4: CSG.Matrix4x4): Side;
|
||||
flipped(): Side;
|
||||
direction(): CSG.Vector2D;
|
||||
getTag(): number;
|
||||
lengthSquared(): number;
|
||||
length(): number;
|
||||
}
|
||||
class fuzzyCAGFactory {
|
||||
vertexfactory: CSG.fuzzyFactory;
|
||||
constructor();
|
||||
getVertex(sourcevertex: Vertex): Vertex;
|
||||
getSide(sourceside: Side): Side;
|
||||
getCAG(sourcecag: CAG): CAG;
|
||||
}
|
||||
}
|
||||
interface CAG_extrude_options {
|
||||
offset?: number[];
|
||||
twistangle?: number;
|
||||
twiststeps?: number;
|
||||
}
|
||||
declare namespace CSG {
|
||||
class Polygon2D extends CAG {
|
||||
constructor(points: Vector2D[]);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,27 @@
|
||||
case 1. Add a new type definition.
|
||||
- [ ] checked compilation succeeds with `--target es6` and `--noImplicitAny` options.
|
||||
- [ ] has correct [naming convention](http://definitelytyped.org/guides/contributing.html#naming-the-file)
|
||||
- [ ] has a [test file](http://definitelytyped.org/guides/contributing.html#tests) with the suffix of `-tests.ts` or `-tests.tsx`.
|
||||
Please fill in this template.
|
||||
|
||||
case 2. Improvement to existing type definition.
|
||||
- documentation or source code reference which provides context for the suggested changes. url http://api.jquery.com/html .
|
||||
- it has been reviewed by a DefinitelyTyped member.
|
||||
- [ ] Make your PR against the `master` branch.
|
||||
- [ ] Use a meaningful title for the pull request. Include the name of the package modified.
|
||||
- [ ] Test the change in your own code. (Compile and run.)
|
||||
- [ ] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#make-a-pull-request).
|
||||
- [ ] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/README.md#common-mistakes).
|
||||
- [ ] Run `tsc` without errors.
|
||||
- [ ] Run `npm run lint package-name` if a `tslint.json` is present.
|
||||
|
||||
Select one of these and delete the others:
|
||||
|
||||
If adding a new definition:
|
||||
- [ ] The package does not provide its own types, and you can not add them.
|
||||
- [ ] If this is for an NPM package, match the name. If not, do not conflict with the name of an NPM package.
|
||||
- [ ] Create it with `npm run new-package package-name`, not by basing it on an existing project.
|
||||
- [ ] `tslint.json` should be present, and `tsconfig.json` should have `noImplicitAny`, `noImplicitThis`, and `strictNullChecks` set to `true`.
|
||||
|
||||
If changing an existing definition:
|
||||
- [ ] Provide a URL to documentation or source code which provides context for the suggested changes: <<url here>>
|
||||
- [ ] Increase the version number in the header if appropriate.
|
||||
- [ ] If you are making substantial changes, consider adding a `tslint.json` containing `{ "extends": "../tslint.json" }`.
|
||||
|
||||
If removing a declaration:
|
||||
- [ ] If a package was never on DefinitelyTyped, you don't need to do anything. (If you wrote a package and provided types, you don't need to register it with us.)
|
||||
- [ ] Delete the package's directory.
|
||||
- [ ] Add it to `notNeededPackages.json`.
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
|
||||
/// <reference path="PayPal-Cordova-Plugin.d.ts"/>
|
||||
|
||||
var item: PayPalItem;
|
||||
item = new PayPalItem("name", 10, "25.00", "USD");
|
||||
item = new PayPalItem("name", 10, "25.00", "USD", null);
|
||||
item = new PayPalItem("name", 10, "25.00", "USD", "SKU_ID");
|
||||
|
||||
var item_name: string = item.name;
|
||||
var item_quantity: number = item.quantity;
|
||||
var item_price: string = item.price;
|
||||
var item_currency: string = item.currency;
|
||||
var item_sku: string = item.sku;
|
||||
|
||||
|
||||
|
||||
var paymentDetails: PayPalPaymentDetails;
|
||||
paymentDetails = new PayPalPaymentDetails("10.50", "2.50", "1.25");
|
||||
|
||||
var paymentDetails_subtotal: string = paymentDetails.subtotal;
|
||||
var paymentDetails_shipping: string = paymentDetails.shipping;
|
||||
var paymentDetails_tax: string = paymentDetails.tax;
|
||||
|
||||
|
||||
|
||||
var shippingAddress: PayPalShippingAddress;
|
||||
shippingAddress = new PayPalShippingAddress("name", "line1", "line2", "city", "state", "postalCode", "countryCode");
|
||||
|
||||
var shippingAddress_recipientName: string = shippingAddress.recipientName;
|
||||
var shippingAddress_line1: string = shippingAddress.line1;
|
||||
var shippingAddress_line2: string = shippingAddress.line2;
|
||||
var shippingAddress_city: string = shippingAddress.city;
|
||||
var shippingAddress_state: string = shippingAddress.state;
|
||||
var shippingAddress_postalCode: string = shippingAddress.postalCode;
|
||||
var shippingAddress_countryCode: string = shippingAddress.countryCode;
|
||||
|
||||
|
||||
|
||||
var payment: PayPalPayment;
|
||||
payment = new PayPalPayment("10.00", "USD", "description", "Auth");
|
||||
payment = new PayPalPayment("10.00", "USD", "description", "Auth", paymentDetails);
|
||||
|
||||
var payment_amount: string = payment.amount;
|
||||
var payment_currency: string = payment.currency;
|
||||
var payment_shortDescription: string = payment.shortDescription;
|
||||
var payment_intent: string = payment.intent;
|
||||
var payment_details: PayPalPaymentDetails = payment.details;
|
||||
var payment_invoiceNumber: string = payment.invoiceNumber;
|
||||
var payment_custom: string = payment.custom;
|
||||
var payment_softDescriptor: string = payment.softDescriptor;
|
||||
var payment_bnCode: string = payment.bnCode;
|
||||
var payment_items: PayPalItem[] = [item, item, item];
|
||||
var payment_shippingAddress: PayPalShippingAddress = shippingAddress;
|
||||
|
||||
|
||||
|
||||
var configOptions: PayPalConfigurationOptions = {
|
||||
defaultUserEmail: "email",
|
||||
defaultUserPhoneCountryCode: "countryCode",
|
||||
defaultUserPhoneNumber: "phoneNumber",
|
||||
merchantName: "merchantName",
|
||||
merchantPrivacyPolicyURL: "merchantPrivacyPolicyURL",
|
||||
merchantUserAgreementURL: "merchantUserAgreementURL",
|
||||
acceptCreditCards: true,
|
||||
payPalShippingAddressOption: 10,
|
||||
rememberUser: true,
|
||||
languageOrLocale: "languageOrLocal",
|
||||
disableBlurWhenBackgrounding: true,
|
||||
presentingInPopover: true,
|
||||
forceDefaultsInSandbox: true,
|
||||
sandboxUserPassword: "sandboxUserPassword",
|
||||
sandboxUserPin: "sandboxUserPin"
|
||||
};
|
||||
|
||||
|
||||
|
||||
var config: PayPalConfiguration;
|
||||
config = new PayPalConfiguration();
|
||||
config = new PayPalConfiguration(null);
|
||||
config = new PayPalConfiguration(configOptions);
|
||||
|
||||
var config_defaultUserEmail: string = config.defaultUserEmail;
|
||||
var config_defaultUserPhoneCountryCode: string = config.defaultUserPhoneCountryCode;
|
||||
var config_defaultUserPhoneNumber: string = config.defaultUserPhoneNumber;
|
||||
var config_merchantName: string = config.merchantName;
|
||||
var config_merchantPrivacyPolicyURL: string = config.merchantPrivacyPolicyURL;
|
||||
var config_merchantUserAgreementURL: string = config.merchantUserAgreementURL;
|
||||
var config_acceptCreditCards: boolean = config.acceptCreditCards;
|
||||
var config_payPalShippingAddressOption: number = config.payPalShippingAddressOption;
|
||||
var config_rememberUser: boolean = config.rememberUser;
|
||||
var config_languageOrLocale: string = config.languageOrLocale;
|
||||
var config_disableBlurWhenBackgrounding: boolean = config.disableBlurWhenBackgrounding;
|
||||
var config_presentingInPopover: boolean = config.presentingInPopover;
|
||||
var config_forceDefaultsInSandbox: boolean = config.forceDefaultsInSandbox;
|
||||
var config_sandboxUserPasword: string = config.sandboxUserPassword;
|
||||
var config_sandboxUserPin: string = config.sandboxUserPin;
|
||||
|
||||
|
||||
|
||||
var clientIds: PayPalCordovaPlugin.PayPalClientIds = {
|
||||
PayPalEnvironmentProduction: "",
|
||||
PayPalEnvironmentSandbox: ""
|
||||
};
|
||||
|
||||
|
||||
|
||||
var apiModule: PayPalCordovaPlugin.PayPalMobileStatic = PayPalMobile;
|
||||
apiModule.version((result: string) => {});
|
||||
apiModule.init(clientIds, () => {});
|
||||
apiModule.prepareToRender("environment", config, () => {});
|
||||
apiModule.renderSinglePaymentUI(payment, (result: any) => {}, (cancelReason: string) => {});
|
||||
apiModule.applicationCorrelationIDForEnvironment("environment", (applicationCorrelationId: string) => {});
|
||||
apiModule.clientMetadataID((clientMetadataId: string) => {});
|
||||
apiModule.renderFuturePaymentUI((result: any) => {}, (cancelReason: string) => {});
|
||||
apiModule.renderProfileSharingUI(["openid", "profile", "email"], (result: any) => {}, (cancelReason: string) => {});
|
||||
@@ -4,35 +4,257 @@
|
||||
|
||||
> The repository for *high quality* TypeScript type definitions.
|
||||
|
||||
For more information see the [definitelytyped.org](http://definitelytyped.org) website.
|
||||
Also see the [definitelytyped.org](http://definitelytyped.org) website, although information in this README is more up-to-date.
|
||||
|
||||
## Usage
|
||||
|
||||
Include a line like this:
|
||||
## What are declaration files?
|
||||
|
||||
```typescript
|
||||
/// <reference path="jquery.d.ts" />
|
||||
See the [TypeScript handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html).
|
||||
|
||||
|
||||
## How do I get them?
|
||||
|
||||
### npm
|
||||
|
||||
This is the preferred method. This is only available for TypeScript 2.0+ users. For example:
|
||||
|
||||
```sh
|
||||
npm install --save-dev @types/node
|
||||
```
|
||||
|
||||
## Contributions
|
||||
The types should then be automatically included by the compiler.
|
||||
See more in the [handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/consumption.html).
|
||||
|
||||
For an NPM package "foo", typings for it will be at "@types/foo".
|
||||
If you can't find your package, look for it on [TypeSearch](https://microsoft.github.io/TypeSearch/).
|
||||
|
||||
If you still can't find it, check if it [bundles](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) its own typings.
|
||||
This is usually provided in a `"types"` or `"typings"` field in the `package.json`,
|
||||
or just look for any ".d.ts" files in the package and manually include them with a `/// <reference path="" />`.
|
||||
|
||||
|
||||
### Other methods
|
||||
|
||||
These can be used by TypeScript 1.0.
|
||||
|
||||
* [Typings](https://github.com/typings/typings)
|
||||
* ~~[NuGet](http://nuget.org/Tpackages?q=DefinitelyTyped)~~ (use preferred alternatives, nuget DT type publishing has been turned off)
|
||||
* Manually download from the `master` branch of this repository
|
||||
|
||||
You may need to add manual [references](http://www.typescriptlang.org/docs/handbook/triple-slash-directives.html).
|
||||
|
||||
|
||||
## How can I contribute?
|
||||
|
||||
DefinitelyTyped only works because of contributions by users like you!
|
||||
|
||||
Please see the [contribution guide](http://definitelytyped.org/guides/contributing.html) on how to contribute to DefinitelyTyped.
|
||||
### Test
|
||||
|
||||
## How to get the definitions
|
||||
Before you share your improvement with the world, use it yourself.
|
||||
|
||||
* Directly from the GitHub repos
|
||||
* [NuGet packages](http://nuget.org/packages?q=DefinitelyTyped)
|
||||
* [TypeScript Definition manager](https://github.com/DefinitelyTyped/tsd)
|
||||
#### Test editing an existing package
|
||||
|
||||
## List of definitions
|
||||
To add new features you can use [module augmentation](http://www.typescriptlang.org/docs/handbook/declaration-merging.html).
|
||||
You can also directly edit the types in `node_modules/@types/foo/index.d.ts`, or copy them from there and follow the steps below.
|
||||
|
||||
* See [CONTRIBUTORS.md](CONTRIBUTORS.md)
|
||||
|
||||
## Requested definitions
|
||||
#### Test a new package
|
||||
|
||||
Add to your `tsconfig.json`:
|
||||
|
||||
```json
|
||||
"baseUrl": "types",
|
||||
"typeRoots": ["types"],
|
||||
```
|
||||
|
||||
(You can also use `src/types`.)
|
||||
Create `types/foo/index.d.ts` containing declarations for the module "foo".
|
||||
You should now be able import from `"foo"` in your code and it will route to the new type definition.
|
||||
Then build *and* run the code to make sure your type definition actually corresponds to what happens at runtime.
|
||||
Once you've tested your definitions with real code, make a PR contributing the definition by copying `types/foo` to `DefinitelyTyped/foo` and adding a `tsconfig.json` and `foo-tests.ts`.
|
||||
|
||||
|
||||
### Make a pull request
|
||||
|
||||
Once you've tested your package, you can share it on DefinitelyTyped.
|
||||
|
||||
First, [fork](https://guides.github.com/activities/forking/) this repository, install [node](https://nodejs.org/), and run `npm install`.
|
||||
|
||||
|
||||
#### Edit an existing package
|
||||
|
||||
* `cd my-package-to-edit`
|
||||
* Make changes. Remember to edit tests.
|
||||
* You may also want to add yourself to "Definitions by" section of the package header.
|
||||
- Do this by adding your name to the end of the line, as in `// Definitions by: Alice <https://github.com/alice>, Bob <https://github.com/bob>`.
|
||||
* `npm install -g typescript@2.0` and run `tsc`.
|
||||
|
||||
When you make a PR to edit an existing package, `dt-bot` should @-mention previous authors.
|
||||
If it doesn't, you can do so yourself in the comment associated with the PR.
|
||||
|
||||
|
||||
#### Create a new package
|
||||
|
||||
If you are the library author, or can make a pull request to the library, [bundle types](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) instead of publishing to DefinitelyTyped.
|
||||
|
||||
If you are adding typings for an NPM package, create a directory with the same name.
|
||||
If the package you are adding typings for is not on NPM, make sure the name you choose for it does not conflict with the name of a package on NPM.
|
||||
(You can use `npm info foo` to check for the existence of the `foo` package.)
|
||||
|
||||
Your package should have this structure:
|
||||
|
||||
| File | Purpose |
|
||||
| --- | --- |
|
||||
| index.d.ts | This contains the typings for the package. |
|
||||
| foo-tests.ts | This contains sample code which tests the typings. This code does *not* run, but it is type-checked. |
|
||||
| tsconfig.json | This allows you to run `tsc` within the package. |
|
||||
| tslint.json | Enables linting. |
|
||||
|
||||
Generate these by running `npm run new-package -- new-package-name`.
|
||||
|
||||
You may edit the `tsconfig.json` to add new files, to add `"target": "es6"` (needed for async functions), to add to `"lib"`, or to add the `"jsx"` compiler option.
|
||||
|
||||
DefinitelyTyped members routinely monitor for new PRs, though keep in mind that the number of other PRs may slow things down.
|
||||
|
||||
For a good example package, see [base64-js](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/base64-js).
|
||||
|
||||
|
||||
#### Common mistakes
|
||||
|
||||
* First, follow advice from the [handbook](http://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html).
|
||||
* Formatting: Either use all tabs, or always use 4 spaces.
|
||||
* `interface Foo { new(): Foo; }`:
|
||||
This defines a type of objects that are new-able. You probably want `declare class Foo { constructor(); }`.
|
||||
* `const Class: { new(): IClass; }`:
|
||||
Prefer to use a class declaration `class Class { constructor(); }` instead of a new-able constant.
|
||||
* `getMeAT<T>(): T`:
|
||||
If a type parameter does not appear in the types of any parameters, you don't really have a generic function, you just have a disguised type assertion.
|
||||
Prefer to use a real type assertion, e.g. `getMeAT() as number`.
|
||||
Example where a type parameter is acceptable: `function id<T>(value: T): T;`.
|
||||
Example where it is not acceptable: `function parseJson<T>(json: string): T;`.
|
||||
Exception: `new Map<string, number>()` is OK.
|
||||
|
||||
|
||||
#### Removing a package
|
||||
|
||||
When a package [bundles](http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html) its own types, types should be removed from DefinitelyTyped to avoid confusion.
|
||||
|
||||
You can remove it by running `npm run not-needed -- typingsPackageName asOfVersion sourceRepoURL [libraryName]`.
|
||||
- `typingsPackageName`: This is the name of the directory to delete.
|
||||
- `asOfVersion`: A stub will be published to `@types/foo` with this version. Should be higher than any currently published version.
|
||||
- `sourceRepoURL`: This should point to the repository that contains the typings.
|
||||
- `libraryName`: Descriptive name of the library, e.g. "Angular 2" instead of "angular2". (If ommitted, will be identical to "typingsPackageName".)
|
||||
|
||||
Any other packages in DefinitelyTyped that referenced the deleted package should be updated to reference the bundled types. To do this, add a `package.json` with `"dependencies": { "foo": "x.y.z" }`.
|
||||
|
||||
If a package was never on DefinitelyTyped, it does not need to be added to `notNeededPackages.json`.
|
||||
|
||||
|
||||
#### Lint
|
||||
|
||||
To lint a package, just add a `tslint.json` to that package containing `{ "extends": "../tslint.json" }`. All new packages must be linted.
|
||||
If a `tslint.json` turns rules off, this is because that hasn't been fixed yet. For example:
|
||||
|
||||
```json
|
||||
{
|
||||
"extends": "../tslint.json",
|
||||
"rules": {
|
||||
// This package uses the Function type, and it will take effort to fix.
|
||||
"forbidden-types": false
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
(To indicate that a lint rule truly does not apply, use `// tslint:disable:rule-name` or better, `//tslint:disable-next-line:rule-name`.)
|
||||
|
||||
Only `.d.ts` files are linted.
|
||||
Test the linter by running `npm run lint -- package-name`. Do not use a globally installed tslint.
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
#### What exactly is the relationship between this repository and the `@types` packages on NPM?
|
||||
|
||||
The `master` branch is automatically published to the `@types` scope on NPM thanks to [types-publisher](https://github.com/Microsoft/types-publisher).
|
||||
This usually happens within an hour of changes being merged.
|
||||
|
||||
#### I'm writing a definition that depends on another definition. Should I use `<reference types="" />` or an import?
|
||||
|
||||
If the module you're referencing is an external module (uses `export`), use an import.
|
||||
If the module you're referencing is an ambient module (uses `declare module`, or just declares globals), use `<reference types="" />`.
|
||||
|
||||
#### What do I do about older versions of typings?
|
||||
|
||||
Currently we don't support this, though it is [planned](https://github.com/Microsoft/types-publisher/issues/3).
|
||||
If you're adding a new major version of a library, you can copy `index.d.ts` to `foo-v2.3.d.ts` and edit `index.d.ts` to be the new version.
|
||||
|
||||
#### I notice some packages having a `package.json` here.
|
||||
|
||||
Usually you won't need this. When publishing a package we will normally automatically create a `package.json` for it.
|
||||
A `package.json` may be included for the sake of specifying dependencies. Here's an [example](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/pikaday/package.json).
|
||||
We do not allow other fields, such as `"description"`, to be defined manually.
|
||||
Also, if you need to reference an older version of typings, you must do that by adding `"dependencies": { "@types/foo": "x.y.z" }` to the package.json.
|
||||
|
||||
#### Some packages have no `tslint.json`, and some `tsconfig.json` are missing `"noImplicitAny": true`, `"noImplicitThis": true`, or `"strictNullChecks": true`.
|
||||
|
||||
Then they are wrong. You can help by submitting a pull request to fix them.
|
||||
|
||||
#### Can I request a definition?
|
||||
|
||||
Here are the [currently requested definitions](https://github.com/DefinitelyTyped/DefinitelyTyped/labels/Definition%3ARequest).
|
||||
|
||||
#### What about type definitions for the DOM?
|
||||
|
||||
If types are part of a web standard, they should be contributed to [TSJS-lib-generator](https://github.com/Microsoft/TSJS-lib-generator) so that they can become part of the default `lib.dom.d.ts`.
|
||||
|
||||
#### A package uses `export =`, but I prefer to use default imports. Can I change `export =` to `export default`?
|
||||
|
||||
If default imports work in your environment, consider turning on the [`--allowSyntheticDefaultImports`](http://www.typescriptlang.org/docs/handbook/compiler-options.html) compiler option.
|
||||
Do not change the type definition if it is accurate.
|
||||
For an NPM package, `export =` is accurate if `node -p 'require("foo")'` is the export, and `export default` is accurate if `node -p 'require("foo").default'` is the export.
|
||||
|
||||
#### I want to use features from TypeScript 2.1.
|
||||
|
||||
Then you will have to add a comment to the last line of your definition header (after `// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped`): `// TypeScript Version: 2.1`.
|
||||
|
||||
#### I want to add a DOM API not present in TypeScript by default.
|
||||
|
||||
This may belong in [TSJS-Lib-Generator](https://github.com/Microsoft/TSJS-lib-generator#readme). See the guidelines there.
|
||||
If the standard is still a draft, it belongs here.
|
||||
Use a name beginning with `dom-` and include a link to the standard as the "Project" link in the header.
|
||||
When it graduates draft mode, we may remove it from DefinitelyTyped and deprecate the associated `@types` package.
|
||||
|
||||
#### I want to update a package to a new major version
|
||||
|
||||
Before making your change, please create a new subfolder with the current version e.g. `v2`, and copy existing files to it. You will need to:
|
||||
|
||||
1. Update the relative paths in `tsconfig.json` as well as `tslint.json`.
|
||||
2. Add path mapping rules to ensure that tests are running against the intended version.
|
||||
|
||||
For example [history v2 `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/history/v2/tsconfig.json) looks like:
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": ["../../"],
|
||||
"paths": {
|
||||
"history": [ "history/v2" ]
|
||||
},
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"history-tests.ts"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Please note that unless upgrading something backwards-compatible like `node`, all packages depending of the updated package need a path mapping to it, as well as packages depending on *those*.
|
||||
For example, `react-router` depends on `history@2`, so [react-router `tsconfig.json`](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/react-router/tsconfig.json) has a path mapping to `"history": [ "history/v2" ]`;
|
||||
transitively `react-router-bootstrap` (which depends on `react-router`) also adds a path mapping in its [tsconfig.json](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/react-router-bootstrap/tsconfig.json).
|
||||
|
||||
Also, `/// <reference types=".." />` will not work with path mapping, so dependencies must use `import`.
|
||||
|
||||
Here is are the [currently requested definitions](https://github.com/DefinitelyTyped/DefinitelyTyped/labels/Definition%3ARequest).
|
||||
|
||||
## License
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
/// <reference path="_debugger.d.ts"/>
|
||||
import _debugger = require("_debugger");
|
||||
var {Client} = _debugger;
|
||||
|
||||
var client = new Client();
|
||||
|
||||
client.connect(8888, 'localhost');
|
||||
client.listbreakpoints((err, res) => {
|
||||
|
||||
});
|
||||
Vendored
-135
@@ -1,135 +0,0 @@
|
||||
// Type definitions for Node.js debugger API
|
||||
// Project: http://nodejs.org/
|
||||
// Definitions by: Basarat Ali Syed <https://github.com/basarat>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts"/>
|
||||
|
||||
declare namespace NodeJS {
|
||||
export module _debugger {
|
||||
export interface Packet {
|
||||
raw: string;
|
||||
headers: string[];
|
||||
body: Message;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
seq: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface RequestInfo {
|
||||
command: string;
|
||||
arguments: any;
|
||||
}
|
||||
|
||||
export interface Request extends Message, RequestInfo {
|
||||
}
|
||||
|
||||
export interface Event extends Message {
|
||||
event: string;
|
||||
body?: any;
|
||||
}
|
||||
|
||||
export interface Response extends Message {
|
||||
request_seq: number;
|
||||
success: boolean;
|
||||
/** Contains error message if success === false. */
|
||||
message?: string;
|
||||
/** Contains message body if success === true. */
|
||||
body?: any;
|
||||
}
|
||||
|
||||
export interface BreakpointMessageBody {
|
||||
type: string;
|
||||
target: number;
|
||||
line: number;
|
||||
}
|
||||
|
||||
export class Protocol {
|
||||
res: Packet;
|
||||
state: string;
|
||||
execute(data: string): void;
|
||||
serialize(rq: Request): string;
|
||||
onResponse: (pkt: Packet) => void;
|
||||
}
|
||||
|
||||
export var NO_FRAME: number;
|
||||
export var port: number;
|
||||
|
||||
export interface ScriptDesc {
|
||||
name: string;
|
||||
id: number;
|
||||
isNative?: boolean;
|
||||
handle?: number;
|
||||
type: string;
|
||||
lineOffset?: number;
|
||||
columnOffset?: number;
|
||||
lineCount?: number;
|
||||
}
|
||||
|
||||
export interface Breakpoint {
|
||||
id: number;
|
||||
scriptId: number;
|
||||
script: ScriptDesc;
|
||||
line: number;
|
||||
condition?: string;
|
||||
scriptReq?: string;
|
||||
}
|
||||
|
||||
export interface RequestHandler {
|
||||
(err: boolean, body: Message, res: Packet): void;
|
||||
request_seq?: number;
|
||||
}
|
||||
|
||||
export interface ResponseBodyHandler {
|
||||
(err: boolean, body?: any): void;
|
||||
request_seq?: number;
|
||||
}
|
||||
|
||||
export interface ExceptionInfo {
|
||||
text: string;
|
||||
}
|
||||
|
||||
export interface BreakResponse {
|
||||
script?: ScriptDesc;
|
||||
exception?: ExceptionInfo;
|
||||
sourceLine: number;
|
||||
sourceLineText: string;
|
||||
sourceColumn: number;
|
||||
}
|
||||
|
||||
export function SourceInfo(body: BreakResponse): string;
|
||||
|
||||
export interface ClientInstance extends EventEmitter {
|
||||
protocol: Protocol;
|
||||
scripts: ScriptDesc[];
|
||||
handles: ScriptDesc[];
|
||||
breakpoints: Breakpoint[];
|
||||
currentSourceLine: number;
|
||||
currentSourceColumn: number;
|
||||
currentSourceLineText: string;
|
||||
currentFrame: number;
|
||||
currentScript: string;
|
||||
|
||||
connect(port: number, host: string): void;
|
||||
req(req: any, cb: RequestHandler): void;
|
||||
reqFrameEval(code: string, frame: number, cb: RequestHandler): void;
|
||||
mirrorObject(obj: any, depth: number, cb: ResponseBodyHandler): void;
|
||||
setBreakpoint(rq: BreakpointMessageBody, cb: RequestHandler): void;
|
||||
clearBreakpoint(rq: Request, cb: RequestHandler): void;
|
||||
listbreakpoints(cb: RequestHandler): void;
|
||||
reqSource(from: number, to: number, cb: RequestHandler): void;
|
||||
reqScripts(cb: any): void;
|
||||
reqContinue(cb: RequestHandler): void;
|
||||
}
|
||||
|
||||
export var Client : {
|
||||
new (): ClientInstance
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare module "_debugger"{
|
||||
export = NodeJS._debugger;
|
||||
}
|
||||
+1
-3
@@ -1,5 +1,3 @@
|
||||
/// <reference path="./abs.d.ts" />
|
||||
|
||||
import Abs from 'abs';
|
||||
import Abs = require('abs');
|
||||
|
||||
const x: string = Abs('/foo');
|
||||
|
||||
Vendored
-14
@@ -1,14 +0,0 @@
|
||||
// Type definitions for abs 1.1.0
|
||||
// Project: https://github.com/IonicaBizau/node-abs
|
||||
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module "abs" {
|
||||
/**
|
||||
* Compute the absolute path of an input.
|
||||
* @param input The input path.
|
||||
*/
|
||||
function Abs(input: string): string;
|
||||
|
||||
export default Abs;
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// Type definitions for abs 1.3
|
||||
// Project: https://github.com/IonicaBizau/node-abs
|
||||
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Compute the absolute path of an input.
|
||||
* @param input The input path.
|
||||
*/
|
||||
declare function Abs(input: string): string;
|
||||
export = Abs;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"abs-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
@@ -1,4 +1,3 @@
|
||||
/// <reference path="./absolute.d.ts" />
|
||||
|
||||
import absolute from 'absolute';
|
||||
|
||||
|
||||
Vendored
-13
@@ -1,13 +0,0 @@
|
||||
// Type definitions for absolute 0.0.1
|
||||
// Project: https://github.com/bahamas10/node-absolute
|
||||
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module "absolute" {
|
||||
/**
|
||||
* Test if a path is absolute
|
||||
*/
|
||||
function absolute(path: string): boolean;
|
||||
|
||||
export default absolute;
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// Type definitions for absolute 0.0.1
|
||||
// Project: https://github.com/bahamas10/node-absolute
|
||||
// Definitions by: Aya Morisawa <https://github.com/AyaMorisawa>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Test if a path is absolute
|
||||
*/
|
||||
declare function absolute(path: string): boolean;
|
||||
|
||||
export default absolute;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"absolute-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/// <reference path="../jquery/jquery.d.ts"/>
|
||||
/// <reference path="acc-wizard.d.ts" />
|
||||
/// <reference types="jquery"/>
|
||||
|
||||
|
||||
/**
|
||||
* @summary Test for "accwizard" without options.
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"acc-wizard-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import accepts = require("accepts");
|
||||
|
||||
const req: any = {};
|
||||
|
||||
const accept = accepts(req);
|
||||
|
||||
const charsets = accept.charsets();
|
||||
const charsetFromEmpty = accept.charset();
|
||||
const charsetFromParams = accept.charset("json", "text");
|
||||
const charsetFromArray = accept.charset(["json", "text"]);
|
||||
|
||||
const encodings = accept.encodings();
|
||||
const encodingFromEmpty = accept.encoding();
|
||||
const encodingFromParams = accept.encoding("json", "text");
|
||||
const encodingFromArray = accept.encoding(["json", "text"]);
|
||||
|
||||
const languages = accept.languages();
|
||||
const languageFromEmpty = accept.language();
|
||||
const languageFromParams = accept.language("json", "text");
|
||||
const languageFromArray = accept.language(["json", "text"]);
|
||||
|
||||
const types = accept.types();
|
||||
const typeFromEmpty = accept.type();
|
||||
const typeFromParams = accept.type("json", "text");
|
||||
const typeFromArray = accept.type(["json", "text"]);
|
||||
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
// Type definitions for accepts 1.3
|
||||
// Project: https://github.com/jshttp/accepts
|
||||
// Definitions by: Stefan Reichel <https://github.com/bomret>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace accepts {
|
||||
export interface Headers {
|
||||
[key: string]: string | string[];
|
||||
}
|
||||
|
||||
export interface Accepts {
|
||||
/**
|
||||
* Return the first accepted charset. If nothing in `charsets` is accepted, then `false` is returned.
|
||||
*/
|
||||
charset(charsets: string[]): string | false;
|
||||
charset(...charsets: string[]): string | false;
|
||||
|
||||
/**
|
||||
* Return the charsets that the request accepts, in the order of the client's preference (most preferred first).
|
||||
*/
|
||||
charsets(): string[];
|
||||
|
||||
/**
|
||||
* Return the first accepted encoding. If nothing in `encodings` is accepted, then `false` is returned.
|
||||
*/
|
||||
encoding(encodings: string[]): string | false;
|
||||
encoding(...encodings: string[]): string | false;
|
||||
|
||||
/**
|
||||
* Return the encodings that the request accepts, in the order of the client's preference (most preferred first).
|
||||
*/
|
||||
encodings(): string[];
|
||||
|
||||
/**
|
||||
* Return the first accepted language. If nothing in `languages` is accepted, then `false` is returned.
|
||||
*/
|
||||
language(languages: string[]): string | false;
|
||||
language(...languages: string[]): string | false;
|
||||
|
||||
/**
|
||||
* Return the languages that the request accepts, in the order of the client's preference (most preferred first).
|
||||
*/
|
||||
languages(): string[];
|
||||
|
||||
/**
|
||||
* Return the first accepted type (and it is returned as the same text as what appears in the `types` array). If nothing in `types` is accepted, then `false` is returned.
|
||||
*
|
||||
* The `types` array can contain full MIME types or file extensions. Any value that is not a full MIME types is passed to `require('mime-types').lookup`.
|
||||
*/
|
||||
type(types: string[]): string | false;
|
||||
type(...types: string[]): string | false;
|
||||
|
||||
/**
|
||||
* Return the types that the request accepts, in the order of the client's preference (most preferred first).
|
||||
*/
|
||||
types(): string[];
|
||||
}
|
||||
}
|
||||
|
||||
declare function accepts(req: { headers: accepts.Headers }): accepts.Accepts;
|
||||
|
||||
export = accepts;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"accepts-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
@@ -1,5 +1,3 @@
|
||||
/// <reference path="accounting.d.ts"/>
|
||||
|
||||
// formatMoney
|
||||
|
||||
// Default usage:
|
||||
|
||||
Vendored
-79
@@ -1,79 +0,0 @@
|
||||
// Type definitions for accounting.js 0.3.2
|
||||
// Project: http://josscrowcroft.github.io/accounting.js/
|
||||
// Definitions by: Sergey Gerasimov <https://github.com/gerich-home/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
interface IAccountingCurrencyFormat {
|
||||
pos: string; // for positive values, eg. "$ 1.00"
|
||||
neg?: string; // for negative values, eg. "$ (1.00)"
|
||||
zero?: string; // for zero values, eg. "$ --"
|
||||
}
|
||||
|
||||
interface IAccountingCurrencySettings<TFormat> {
|
||||
symbol?: string; // default currency symbol is '$'
|
||||
format?: TFormat; // controls output: %s = symbol, %v = value/number
|
||||
decimal?: string; // decimal point separator
|
||||
thousand?: string; // thousands separator
|
||||
precision?: number // decimal places
|
||||
}
|
||||
|
||||
interface IAccountingNumberSettings {
|
||||
precision?: number; // default precision on numbers is 0
|
||||
thousand?: string;
|
||||
decimal?: string;
|
||||
}
|
||||
|
||||
interface IAccountingSettings {
|
||||
currency: IAccountingCurrencySettings<any>; // IAccountingCurrencySettings<string> or IAccountingCurrencySettings<IAccountingCurrencyFormat>
|
||||
number: IAccountingNumberSettings;
|
||||
}
|
||||
|
||||
interface IAccountingStatic {
|
||||
// format any number into currency
|
||||
formatMoney(number: number, symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string;
|
||||
formatMoney(number: number, options: IAccountingCurrencySettings<string>): string;
|
||||
formatMoney(number: number, options: IAccountingCurrencySettings<IAccountingCurrencyFormat>): string;
|
||||
|
||||
formatMoney(numbers: number[], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string[];
|
||||
formatMoney(numbers: number[], options: IAccountingCurrencySettings<string>): string[];
|
||||
formatMoney(numbers: number[], options: IAccountingCurrencySettings<IAccountingCurrencyFormat>): string[];
|
||||
|
||||
// generic case (any array of numbers)
|
||||
formatMoney(numbers: any[], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): any[];
|
||||
formatMoney(numbers: any[], options: IAccountingCurrencySettings<string>): any[];
|
||||
formatMoney(numbers: any[], options: IAccountingCurrencySettings<IAccountingCurrencyFormat>): any[];
|
||||
|
||||
// format a list of values for column-display
|
||||
formatColumn(numbers: number[], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string[];
|
||||
formatColumn(numbers: number[], options: IAccountingCurrencySettings<string>): string[];
|
||||
formatColumn(numbers: number[], options: IAccountingCurrencySettings<IAccountingCurrencyFormat>): string[];
|
||||
|
||||
formatColumn(numbers: number[][], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string[][];
|
||||
formatColumn(numbers: number[][], options: IAccountingCurrencySettings<string>): string[][];
|
||||
formatColumn(numbers: number[][], options: IAccountingCurrencySettings<IAccountingCurrencyFormat>): string[][];
|
||||
|
||||
// format a number with custom precision and localisation
|
||||
formatNumber(number: number, precision?: number, thousand?: string, decimal?: string): string;
|
||||
formatNumber(number: number, options: IAccountingNumberSettings): string;
|
||||
|
||||
formatNumber(number: number[], precision?: number, thousand?: string, decimal?: string): string[];
|
||||
formatNumber(number: number[], options: IAccountingNumberSettings): string[];
|
||||
|
||||
formatNumber(number: any[], precision?: number, thousand?: string, decimal?: string): any[];
|
||||
formatNumber(number: any[], options: IAccountingNumberSettings): any[];
|
||||
|
||||
// better rounding for floating point numbers
|
||||
toFixed(number: number, precision?: number): string;
|
||||
|
||||
// get a value from any formatted number/currency string
|
||||
unformat(string: string, decimal?: string): number;
|
||||
|
||||
// settings object that controls default parameters for library methods
|
||||
settings: IAccountingSettings;
|
||||
}
|
||||
|
||||
declare var accounting: IAccountingStatic;
|
||||
|
||||
declare module "accounting" {
|
||||
export = accounting;
|
||||
}
|
||||
Vendored
+74
@@ -0,0 +1,74 @@
|
||||
// Type definitions for accounting.js 0.3
|
||||
// Project: http://josscrowcroft.github.io/accounting.js/
|
||||
// Definitions by: Sergey Gerasimov <https://github.com/gerich-home/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace accounting {
|
||||
interface CurrencyFormat {
|
||||
pos: string; // for positive values, eg. "$ 1.00"
|
||||
neg?: string; // for negative values, eg. "$ (1.00)"
|
||||
zero?: string; // for zero values, eg. "$ --"
|
||||
}
|
||||
|
||||
interface CurrencySettings<TFormat> {
|
||||
symbol?: string; // default currency symbol is '$'
|
||||
format?: TFormat; // controls output: %s = symbol, %v = value/number
|
||||
decimal?: string; // decimal point separator
|
||||
thousand?: string; // thousands separator
|
||||
precision?: number; // decimal places
|
||||
}
|
||||
|
||||
interface NumberSettings {
|
||||
precision?: number; // default precision on numbers is 0
|
||||
thousand?: string;
|
||||
decimal?: string;
|
||||
}
|
||||
|
||||
interface Settings {
|
||||
currency: CurrencySettings<any>; // IAccountingCurrencySettings<string> or IAccountingCurrencySettings<IAccountingCurrencyFormat>
|
||||
number: NumberSettings;
|
||||
}
|
||||
|
||||
interface Static {
|
||||
// format any number into currency
|
||||
formatMoney(number: number, symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string;
|
||||
formatMoney(number: number, options: CurrencySettings<string> | CurrencySettings<CurrencyFormat>): string;
|
||||
|
||||
formatMoney(numbers: number[], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string[];
|
||||
formatMoney(numbers: number[], options: CurrencySettings<string> | CurrencySettings<CurrencyFormat>): string[];
|
||||
|
||||
// generic case (any array of numbers)
|
||||
formatMoney(numbers: any[], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): any[];
|
||||
formatMoney(numbers: any[], options: CurrencySettings<string> | CurrencySettings<CurrencyFormat>): any[];
|
||||
|
||||
// format a list of values for column-display
|
||||
formatColumn(numbers: number[], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string[];
|
||||
formatColumn(numbers: number[], options: CurrencySettings<string> | CurrencySettings<CurrencyFormat>): string[];
|
||||
|
||||
formatColumn(numbers: number[][], symbol?: string, precision?: number, thousand?: string, decimal?: string, format?: string): string[][];
|
||||
formatColumn(numbers: number[][], options: CurrencySettings<string> | CurrencySettings<CurrencyFormat>): string[][];
|
||||
|
||||
// format a number with custom precision and localisation
|
||||
formatNumber(number: number, precision?: number, thousand?: string, decimal?: string): string;
|
||||
formatNumber(number: number, options: NumberSettings): string;
|
||||
|
||||
formatNumber(number: number[], precision?: number, thousand?: string, decimal?: string): string[];
|
||||
formatNumber(number: number[], options: NumberSettings): string[];
|
||||
|
||||
formatNumber(number: any[], precision?: number, thousand?: string, decimal?: string): any[];
|
||||
formatNumber(number: any[], options: NumberSettings): any[];
|
||||
|
||||
// better rounding for floating point numbers
|
||||
toFixed(number: number, precision?: number): string;
|
||||
|
||||
// get a value from any formatted number/currency string
|
||||
unformat(string: string, decimal?: string): number;
|
||||
|
||||
// settings object that controls default parameters for library methods
|
||||
settings: Settings;
|
||||
}
|
||||
}
|
||||
|
||||
declare var accounting: accounting.Static;
|
||||
export = accounting;
|
||||
export as namespace accounting;
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"accounting-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Vendored
-2984
File diff suppressed because it is too large
Load Diff
@@ -1,26 +0,0 @@
|
||||
/// <reference path="ace.d.ts" />
|
||||
|
||||
var exports: any;
|
||||
var assert: any;
|
||||
var MockRenderer = null;
|
||||
var JavaScriptMode = null;
|
||||
|
||||
/// <reference path="tests/ace-default-tests.ts" />
|
||||
/// <reference path="tests/ace-background_tokenizer-tests.ts" />
|
||||
/// <reference path="tests/ace-document-tests.ts" />
|
||||
/// <reference path="tests/ace-edit_session-tests.ts" />
|
||||
/// <reference path="tests/ace-editor1-tests.ts" />
|
||||
/// <reference path="tests/ace-editor_highlight_selected_word-tests.ts" />
|
||||
/// <reference path="tests/ace-editor_navigation-tests.ts" />
|
||||
/// <reference path="tests/ace-editor_text_edit-tests.ts" />
|
||||
/// <reference path="tests/ace-multi_select-tests.ts" />
|
||||
/// <reference path="tests/ace-placeholder-tests.ts" />
|
||||
/// <reference path="tests/ace-range_list-tests.ts" />
|
||||
/// <reference path="tests/ace-range-tests.ts" />
|
||||
/// <reference path="tests/ace-search-tests.ts" />
|
||||
/// <reference path="tests/ace-selection-tests.ts" />
|
||||
/// <reference path="tests/ace-token_iterator-tests.ts" />
|
||||
/// <reference path="tests/ace-virtual_renderer-tests.ts" />
|
||||
|
||||
|
||||
|
||||
Vendored
+2983
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,129 @@
|
||||
const aceAnchorTests = {
|
||||
|
||||
"test create anchor" : function() {
|
||||
var doc = new AceAjax.Document("juhu");
|
||||
var anchor = new AceAjax.Anchor(doc, 0, 0);
|
||||
|
||||
assert.position(anchor.getPosition(), 0, 0);
|
||||
assert.equal(anchor.getDocument(), doc);
|
||||
},
|
||||
|
||||
"test insert text in same row before cursor should move anchor column": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insert({row: 1, column: 1}, "123");
|
||||
assert.position(anchor.getPosition(), 1, 7);
|
||||
},
|
||||
|
||||
"test insert lines before cursor should move anchor row": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insertLines(1, ["123", "456"]);
|
||||
assert.position(anchor.getPosition(), 3, 4);
|
||||
},
|
||||
|
||||
"test insert new line before cursor should move anchor column": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insertNewLine({row: 0, column: 0});
|
||||
assert.position(anchor.getPosition(), 2, 4);
|
||||
},
|
||||
|
||||
"test insert new line in anchor line before anchor should move anchor column and row": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insertNewLine({row: 1, column: 2});
|
||||
assert.position(anchor.getPosition(), 2, 2);
|
||||
},
|
||||
|
||||
"test delete text in anchor line before anchor should move anchor column": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 1, 1, 3));
|
||||
assert.position(anchor.getPosition(), 1, 2);
|
||||
},
|
||||
|
||||
"test remove range which contains the anchor should move the anchor to the start of the range": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 0, 3);
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 1, 1, 3));
|
||||
assert.position(anchor.getPosition(), 0, 1);
|
||||
},
|
||||
|
||||
"test delete character before the anchor should have no effect": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 4, 1, 5));
|
||||
assert.position(anchor.getPosition(), 1, 4);
|
||||
},
|
||||
|
||||
"test delete lines in anchor line before anchor should move anchor row": function() {
|
||||
var doc = new AceAjax.Document("juhu\n1\n2\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 3, 4);
|
||||
|
||||
doc.removeLines(1, 2);
|
||||
assert.position(anchor.getPosition(), 1, 4);
|
||||
},
|
||||
|
||||
"test remove new line before the cursor": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.removeNewLine(0);
|
||||
assert.position(anchor.getPosition(), 0, 8);
|
||||
},
|
||||
|
||||
"test delete range which contains the anchor should move anchor to the end of the range": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 2, 1, 2));
|
||||
assert.position(anchor.getPosition(), 0, 4);
|
||||
},
|
||||
|
||||
"test delete line which contains the anchor should move anchor to the end of the range": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 5);
|
||||
|
||||
doc.removeLines(1, 1);
|
||||
assert.position(anchor.getPosition(), 1, 0);
|
||||
},
|
||||
|
||||
"test remove after the anchor should have no effect": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 2);
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 4, 2, 2));
|
||||
assert.position(anchor.getPosition(), 1, 2);
|
||||
},
|
||||
|
||||
"test anchor changes triggered by document changes should emit change event": function(next) {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 5);
|
||||
|
||||
anchor.on("change", function(e) {
|
||||
assert.position(anchor.getPosition(), 0, 0);
|
||||
next();
|
||||
});
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 0, 2, 1));
|
||||
},
|
||||
|
||||
"test only fire change event if position changes": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 5);
|
||||
|
||||
anchor.on("change", function(e) {
|
||||
assert.fail();
|
||||
});
|
||||
|
||||
doc.remove(new AceAjax.Range(2, 0, 2, 1));
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
function forceTokenize(session) {
|
||||
for (var i = 0, l = session.getLength(); i < l; i++)
|
||||
session.getTokens(i)
|
||||
}
|
||||
|
||||
function testStates(session, states) {
|
||||
for (var i = 0, l = session.getLength(); i < l; i++)
|
||||
assert.equal(session.bgTokenizer.states[i], states[i])
|
||||
assert.ok(l == states.length)
|
||||
}
|
||||
|
||||
const aceBackgroundTokenizerTests = {
|
||||
|
||||
"test background tokenizer update on session change": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"/*",
|
||||
"*/",
|
||||
"var juhu"
|
||||
]);
|
||||
doc.setMode("./mode/javascript")
|
||||
|
||||
forceTokenize(doc)
|
||||
testStates(doc, ["comment", "start", "start"])
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 2, 1, 2))
|
||||
testStates(doc, [null, "start"])
|
||||
|
||||
forceTokenize(doc)
|
||||
testStates(doc, ["comment", "comment"])
|
||||
|
||||
doc.insert({ row: 0, column: 2 }, "\n*/")
|
||||
testStates(doc, [undefined, undefined, "comment"])
|
||||
|
||||
forceTokenize(doc)
|
||||
testStates(doc, ["comment", "start", "start"])
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,451 @@
|
||||
var editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.getSession().setMode("ace/mode/javascript");
|
||||
|
||||
editor.on("blur", (e) => e);
|
||||
editor.on("change", (e) => e);
|
||||
|
||||
editor.setTheme("ace/theme/twilight");
|
||||
|
||||
editor.getSession().setMode("ace/mode/javascript");
|
||||
|
||||
editor.setValue("the new text here"); // or session.setValue
|
||||
editor.getValue(); // or session.getValue
|
||||
|
||||
editor.session.getTextRange(editor.getSelectionRange());
|
||||
|
||||
editor.insert("Something cool");
|
||||
|
||||
editor.selection.getCursor();
|
||||
|
||||
editor.gotoLine(123);
|
||||
|
||||
editor.session.getLength();
|
||||
|
||||
editor.getSession().setTabSize(4);
|
||||
|
||||
editor.getSession().setUseSoftTabs(true);
|
||||
|
||||
document.getElementById('editor').style.fontSize = '12px';
|
||||
|
||||
editor.getSession().setUseWrapMode(true);
|
||||
|
||||
editor.setHighlightActiveLine(false);
|
||||
|
||||
editor.setShowPrintMargin(false);
|
||||
|
||||
editor.setReadOnly(true); // false to make it editable
|
||||
|
||||
editor.resize()
|
||||
|
||||
editor.find('needle', {
|
||||
backwards: false,
|
||||
wrap: false,
|
||||
caseSensitive: false,
|
||||
wholeWord: false,
|
||||
regExp: false
|
||||
});
|
||||
editor.findNext();
|
||||
editor.findPrevious();
|
||||
|
||||
editor.find('foo');
|
||||
editor.replace('bar');
|
||||
|
||||
editor.replaceAll('bar');
|
||||
|
||||
editor.getSession().on('change', function (e) {
|
||||
// e.type, etc
|
||||
});
|
||||
|
||||
editor.getSession().selection.on('changeSelection', function (e) {
|
||||
});
|
||||
|
||||
editor.getSession().selection.on('changeCursor', function (e) {
|
||||
});
|
||||
|
||||
editor.commands.addCommand({
|
||||
name: 'myCommand',
|
||||
bindKey: { win: 'Ctrl-M', mac: 'Command-M' },
|
||||
exec: function (editor) {
|
||||
//...
|
||||
},
|
||||
readOnly: true // false if this command should not apply in readOnly mode
|
||||
});
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.moveCursorTo(3, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.onTextInput("\n");
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent();
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.removeLines();
|
||||
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", "d"].join("\n"));
|
||||
|
||||
assert.equal(session.toString(), "a\nc\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a");
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "b\nc");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(3, 0);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb\nc");
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb");
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
assert.equal(["a12345", " b12345", " c12345"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 7);
|
||||
|
||||
range = editor.getSelectionRange();
|
||||
assert.position(range.start, 1, 7);
|
||||
assert.position(range.end, 2, 7);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
assert.equal(["a12345", " b12345", "c12345"].join("\n"), session.toString());
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.onTextInput("\n");
|
||||
assert.equal(["", "{"].join("\n"), session.toString());
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), [" a12345", "b12345", " c12345"].join("\n"));
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 1);
|
||||
assert.position(range.end, 2, 1);
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), ["a12345", "b12345", "c12345"].join("\n"));
|
||||
|
||||
range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 2, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.blockOutdent(" ");
|
||||
|
||||
assert.equal(session.toString(), " 12");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.getSelection().selectDown();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal(["// abc", "//cde"].join("\n"), session.toString());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assert.position(selection.start, 0, 4);
|
||||
assert.position(selection.end, 1, 4);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectRight();
|
||||
editor.getSelection().selectRight();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde"].join("\n"), session.toString());
|
||||
assert.range(editor.getSelectionRange(), 0, 0, 1, 1);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectUp();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "11", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
|
||||
// moving again should have no effect
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(2, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["11", "33", "44", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["33", "44", "11", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["11", "33", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(["11", "22", "33", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesDown();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 5, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 3, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesUp();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
|
||||
session.setTabSize(2);
|
||||
session.setUseSoftTabs(true);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
|
||||
session.setTabSize(5);
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
|
||||
|
||||
session.setUseSoftTabs(false);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), "\t");
|
||||
|
||||
editor.removeLines();
|
||||
var step1 = session.toString();
|
||||
assert.equal(step1, "222\n333");
|
||||
|
||||
editor.removeLines();
|
||||
var step2 = session.toString();
|
||||
assert.equal(step2, "333");
|
||||
|
||||
editor.removeLines();
|
||||
var step3 = session.toString();
|
||||
assert.equal(step3, "");
|
||||
|
||||
var undoManager = new AceAjax.UndoManager();
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step2);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step1);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), "");
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), "");
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n56");
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123456");
|
||||
|
||||
session.setUseSoftTabs(true);
|
||||
session.setTabSize(4);
|
||||
|
||||
editor.moveCursorTo(1, 8);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n 456");
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4657", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4576", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectRight();
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
assert.position(editor.getCursorPosition(), 1, 3);
|
||||
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.removeToLineEnd();
|
||||
assert.equal(session.getValue(), ["123", "45", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.removeToLineEnd();
|
||||
assert.position(editor.getCursorPosition(), 1, 4);
|
||||
assert.equal(session.getValue(), ["123", "456789"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
@@ -0,0 +1,252 @@
|
||||
const aceDocumentTests = {
|
||||
"test: insert text in line": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 0, column: 1 }, "juhu");
|
||||
assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert new line": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertNewLine({ row: 0, column: 1 });
|
||||
assert.equal(doc.getValue(), ["1", "2", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1", "2", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert lines at the beginning": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertLines(0, ["aa", "bb"]);
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert lines at the end": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertLines(2, ["aa", "bb"]);
|
||||
assert.equal(doc.getValue(), ["12", "34", "aa", "bb"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert lines in the middle": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertLines(1, ["aa", "bb"]);
|
||||
assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert multi line string at the start": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 0, column: 0 }, "aa\nbb\ncc");
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert multi line string at the end": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 2, column: 0 }, "aa\nbb\ncc");
|
||||
assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert multi line string in the middle": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 0, column: 1 }, "aa\nbb\ncc");
|
||||
assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete in line": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 1, 0, 3));
|
||||
assert.equal(doc.getValue(), ["14", "5678"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1234", "5678"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["14", "5678"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete new line": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 4, 1, 0));
|
||||
assert.equal(doc.getValue(), ["12345678"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1234", "5678"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12345678"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete multi line range line": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678", "abcd"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 2, 2, 2));
|
||||
assert.equal(doc.getValue(), ["12cd"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1234", "5678", "abcd"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12cd"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete full lines": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678", "abcd"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 0, 3, 0));
|
||||
assert.equal(doc.getValue(), ["1234", ""].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: remove lines should return the removed lines": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678", "abcd"]);
|
||||
|
||||
var removed = doc.removeLines(1, 2);
|
||||
assert.equal(removed.join("\n"), ["5678", "abcd"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: should handle unix style new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"]);
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: should handle windows style new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.setNewLineMode("unix");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: set new line mode to 'windows' should use '\\r\\n' as new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\n"));
|
||||
doc.setNewLineMode("windows");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\r\n"));
|
||||
} ,
|
||||
|
||||
"test: set new line mode to 'unix' should use '\\n' as new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.setNewLineMode("unix");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: set new line mode to 'auto' should detect the incoming nl type": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\n"));
|
||||
|
||||
doc.setNewLineMode("auto");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.setNewLineMode("auto");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.replace(new AceAjax.Range(0, 0, 2, 1), ["4", "5", "6"].join("\n"));
|
||||
assert.equal(["4", "5", "6"].join("\n"), doc.getValue());
|
||||
} ,
|
||||
|
||||
"test: set value": function() {
|
||||
var doc = new AceAjax.Document("1");
|
||||
assert.equal("1", doc.getValue());
|
||||
|
||||
doc.setValue(doc.getValue());
|
||||
assert.equal("1", doc.getValue());
|
||||
|
||||
var doc = new AceAjax.Document("1\n2");
|
||||
assert.equal("1\n2", doc.getValue());
|
||||
|
||||
doc.setValue(doc.getValue());
|
||||
assert.equal("1\n2", doc.getValue());
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,919 @@
|
||||
|
||||
|
||||
var lang: any;
|
||||
|
||||
function createFoldTestSession() {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"));
|
||||
session.setUndoManager(new AceAjax.UndoManager());
|
||||
session.addFold("args...", new AceAjax.Range(0, 13, 0, 18));
|
||||
session.addFold("foo...", new AceAjax.Range(1, 10, 2, 10));
|
||||
session.addFold("bar...", new AceAjax.Range(2, 20, 2, 25));
|
||||
return session;
|
||||
}
|
||||
|
||||
function assertArray(a, b) {
|
||||
assert.equal(a + "", b + "");
|
||||
assert.ok(a.length == b.length);
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
assert.equal(a[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
const aceEditSessionTests = {
|
||||
|
||||
"test: find matching opening bracket in Text mode": function() {
|
||||
var session = new AceAjax.EditSession(["(()(", "())))"]);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 3 }), 0, 1);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 2 }), 1, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 3 }), 0, 3);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 4 }), 0, 0);
|
||||
assert.equal(session.findMatchingBracket({ row: 1, column: 5 }), null);
|
||||
} ,
|
||||
|
||||
"test: find matching closing bracket in Text mode": function() {
|
||||
var session = new AceAjax.EditSession(["(()(", "())))"]);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 1 }), 1, 1);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 1 }), 1, 1);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 4 }), 1, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 2 }), 0, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 1 }), 1, 3);
|
||||
assert.equal(session.findMatchingBracket({ row: 0, column: 0 }), null);
|
||||
} ,
|
||||
|
||||
"test: find matching opening bracket in JavaScript mode": function() {
|
||||
var lines = [
|
||||
"function foo() {",
|
||||
" var str = \"{ foo()\";",
|
||||
" if (debug) {",
|
||||
" // write str (a string) to the console",
|
||||
" console.log(str);",
|
||||
" }",
|
||||
" str += \" bar() }\";",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"), null);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 14 }), 0, 12);
|
||||
assert.position(session.findMatchingBracket({ row: 7, column: 1 }), 0, 15);
|
||||
assert.position(session.findMatchingBracket({ row: 6, column: 20 }), 1, 15);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 22 }), 1, 20);
|
||||
assert.position(session.findMatchingBracket({ row: 3, column: 31 }), 3, 21);
|
||||
assert.position(session.findMatchingBracket({ row: 4, column: 24 }), 4, 19);
|
||||
assert.equal(session.findMatchingBracket({ row: 0, column: 1 }), null);
|
||||
} ,
|
||||
|
||||
"test: find matching closing bracket in JavaScript mode": function() {
|
||||
var lines = [
|
||||
"function foo() {",
|
||||
" var str = \"{ foo()\";",
|
||||
" if (debug) {",
|
||||
" // write str (a string) to the console",
|
||||
" console.log(str);",
|
||||
" }",
|
||||
" str += \" bar() }\";",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"), null);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 13 }), 0, 13);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 16 }), 7, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 16 }), 6, 19);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 21 }), 1, 21);
|
||||
assert.position(session.findMatchingBracket({ row: 3, column: 22 }), 3, 30);
|
||||
assert.position(session.findMatchingBracket({ row: 4, column: 20 }), 4, 23);
|
||||
} ,
|
||||
|
||||
"test: handle unbalanced brackets in JavaScript mode": function() {
|
||||
var lines = [
|
||||
"function foo() {",
|
||||
" var str = \"{ foo()\";",
|
||||
" if (debug) {",
|
||||
" // write str a string) to the console",
|
||||
" console.log(str);",
|
||||
" ",
|
||||
" str += \" bar() \";",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"), null);
|
||||
|
||||
assert.equal(session.findMatchingBracket({ row: 0, column: 16 }), null);
|
||||
assert.equal(session.findMatchingBracket({ row: 3, column: 30 }), null);
|
||||
assert.equal(session.findMatchingBracket({ row: 1, column: 16 }), null);
|
||||
} ,
|
||||
|
||||
"test: match different bracket types": function() {
|
||||
var session = new AceAjax.EditSession(["({[", ")]}"]);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 1 }), 1, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 2 }), 1, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 3 }), 1, 1);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 1 }), 0, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 2 }), 0, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 3 }), 0, 1);
|
||||
} ,
|
||||
|
||||
"test: move lines down": function() {
|
||||
var session = new AceAjax.EditSession(["a1", "a2", "a3", "a4"]);
|
||||
|
||||
session.moveLinesDown(0, 1);
|
||||
assert.equal(session.getValue(), ["a3", "a1", "a2", "a4"].join("\n"));
|
||||
|
||||
session.moveLinesDown(1, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesDown(2, 3);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesDown(2, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a2", "a1"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: move lines up": function() {
|
||||
var session = new AceAjax.EditSession(["a1", "a2", "a3", "a4"]);
|
||||
|
||||
session.moveLinesUp(2, 3);
|
||||
assert.equal(session.getValue(), ["a1", "a3", "a4", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesUp(1, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesUp(0, 1);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesUp(2, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a1", "a4", "a2"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: duplicate lines": function() {
|
||||
var session = new AceAjax.EditSession(["1", "2", "3", "4"]);
|
||||
|
||||
session.duplicateLines(1, 2);
|
||||
assert.equal(session.getValue(), ["1", "2", "3", "2", "3", "4"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: duplicate last line": function() {
|
||||
var session = new AceAjax.EditSession(["1", "2", "3"]);
|
||||
|
||||
session.duplicateLines(2, 2);
|
||||
assert.equal(session.getValue(), ["1", "2", "3", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: duplicate first line": function() {
|
||||
var session = new AceAjax.EditSession(["1", "2", "3"]);
|
||||
|
||||
session.duplicateLines(0, 0);
|
||||
assert.equal(session.getValue(), ["1", "1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: getScreenLastRowColumn": function() {
|
||||
var session = new AceAjax.EditSession([
|
||||
"juhu",
|
||||
"12\t\t34",
|
||||
"??a"
|
||||
]);
|
||||
|
||||
assert.equal(session.getScreenLastRowColumn(0), 4);
|
||||
assert.equal(session.getScreenLastRowColumn(1), 10);
|
||||
assert.equal(session.getScreenLastRowColumn(2), 5);
|
||||
} ,
|
||||
|
||||
"test: convert document to screen coordinates": function() {
|
||||
var session = new AceAjax.EditSession("01234\t567890\t1234");
|
||||
session.setTabSize(4);
|
||||
|
||||
assert.equal(session.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(session.documentToScreenColumn(0, 4), 4);
|
||||
assert.equal(session.documentToScreenColumn(0, 5), 5);
|
||||
assert.equal(session.documentToScreenColumn(0, 6), 8);
|
||||
assert.equal(session.documentToScreenColumn(0, 12), 14);
|
||||
assert.equal(session.documentToScreenColumn(0, 13), 16);
|
||||
|
||||
session.setTabSize(2);
|
||||
|
||||
assert.equal(session.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(session.documentToScreenColumn(0, 4), 4);
|
||||
assert.equal(session.documentToScreenColumn(0, 5), 5);
|
||||
assert.equal(session.documentToScreenColumn(0, 6), 6);
|
||||
assert.equal(session.documentToScreenColumn(0, 7), 7);
|
||||
assert.equal(session.documentToScreenColumn(0, 12), 12);
|
||||
assert.equal(session.documentToScreenColumn(0, 13), 14);
|
||||
} ,
|
||||
|
||||
"test: convert document to screen coordinates with leading tabs": function() {
|
||||
var session = new AceAjax.EditSession("\t\t123");
|
||||
session.setTabSize(4);
|
||||
|
||||
assert.equal(session.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(session.documentToScreenColumn(0, 1), 4);
|
||||
assert.equal(session.documentToScreenColumn(0, 2), 8);
|
||||
assert.equal(session.documentToScreenColumn(0, 3), 9);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen without soft wrap": function() {
|
||||
var session = new AceAjax.EditSession([
|
||||
"juhu",
|
||||
"12\t\t34",
|
||||
"??a"
|
||||
]);
|
||||
|
||||
assert.position(session.documentToScreenPosition(0, 3), 0, 3);
|
||||
assert.position(session.documentToScreenPosition(1, 3), 1, 4);
|
||||
assert.position(session.documentToScreenPosition(1, 4), 1, 8);
|
||||
assert.position(session.documentToScreenPosition(2, 2), 2, 4);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen with soft wrap": function() {
|
||||
var session = new AceAjax.EditSession(["foo bar foo bar"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(12, 12);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.documentToScreenPosition(0, 11), 0, 11);
|
||||
assert.position(session.documentToScreenPosition(0, 12), 1, 0);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen with soft wrap and multibyte characters": function() {
|
||||
var session = new AceAjax.EditSession(["??a"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(2, 2);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.documentToScreenPosition(0, 1), 1, 0);
|
||||
assert.position(session.documentToScreenPosition(0, 2), 2, 0);
|
||||
assert.position(session.documentToScreenPosition(0, 4), 2, 1);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen should clip position to the document boundaries": function() {
|
||||
var session = new AceAjax.EditSession("foo bar\njuhu kinners");
|
||||
|
||||
assert.position(session.documentToScreenPosition(-1, 4), 0, 0);
|
||||
assert.position(session.documentToScreenPosition(3, 0), 1, 12);
|
||||
} ,
|
||||
|
||||
"test: convert screen to document coordinates": function() {
|
||||
var session = new AceAjax.EditSession("01234\t567890\t1234");
|
||||
session.setTabSize(4);
|
||||
|
||||
assert.equal(session.screenToDocumentColumn(0, 0), 0);
|
||||
assert.equal(session.screenToDocumentColumn(0, 4), 4);
|
||||
assert.equal(session.screenToDocumentColumn(0, 5), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 6), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 7), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 8), 6);
|
||||
assert.equal(session.screenToDocumentColumn(0, 9), 7);
|
||||
assert.equal(session.screenToDocumentColumn(0, 15), 12);
|
||||
assert.equal(session.screenToDocumentColumn(0, 19), 16);
|
||||
|
||||
session.setTabSize(2);
|
||||
|
||||
assert.equal(session.screenToDocumentColumn(0, 0), 0);
|
||||
assert.equal(session.screenToDocumentColumn(0, 4), 4);
|
||||
assert.equal(session.screenToDocumentColumn(0, 5), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 6), 6);
|
||||
assert.equal(session.screenToDocumentColumn(0, 12), 12);
|
||||
assert.equal(session.screenToDocumentColumn(0, 13), 12);
|
||||
assert.equal(session.screenToDocumentColumn(0, 14), 13);
|
||||
} ,
|
||||
|
||||
"test: screenToDocument with soft wrap": function() {
|
||||
var session = new AceAjax.EditSession(["foo bar foo bar"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(12, 12);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.screenToDocumentPosition(1, 0), 0, 12);
|
||||
assert.position(session.screenToDocumentPosition(0, 11), 0, 11);
|
||||
// Check if the position is clamped the right way.
|
||||
assert.position(session.screenToDocumentPosition(0, 12), 0, 11);
|
||||
assert.position(session.screenToDocumentPosition(0, 20), 0, 11);
|
||||
} ,
|
||||
|
||||
"test: screenToDocument with soft wrap and multi byte characters": function() {
|
||||
var session = new AceAjax.EditSession(["? a"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.screenToDocumentPosition(0, 1), 0, 0);
|
||||
assert.position(session.screenToDocumentPosition(0, 2), 0, 1);
|
||||
assert.position(session.screenToDocumentPosition(0, 3), 0, 2);
|
||||
assert.position(session.screenToDocumentPosition(0, 4), 0, 3);
|
||||
assert.position(session.screenToDocumentPosition(0, 5), 0, 3);
|
||||
} ,
|
||||
|
||||
"test: screenToDocument should clip position to the document boundaries": function() {
|
||||
var session = new AceAjax.EditSession("foo bar\njuhu kinners");
|
||||
|
||||
assert.position(session.screenToDocumentPosition(-1, 4), 0, 0);
|
||||
assert.position(session.screenToDocumentPosition(0, -1), 0, 0);
|
||||
assert.position(session.screenToDocumentPosition(0, 30), 0, 7);
|
||||
assert.position(session.screenToDocumentPosition(2, 4), 1, 12);
|
||||
assert.position(session.screenToDocumentPosition(1, 30), 1, 12);
|
||||
assert.position(session.screenToDocumentPosition(20, 50), 1, 12);
|
||||
assert.position(session.screenToDocumentPosition(20, 5), 1, 12);
|
||||
|
||||
// and the same for folded rows
|
||||
session.addFold("...", new AceAjax.Range(0, 1, 1, 3));
|
||||
assert.position(session.screenToDocumentPosition(1, 2), 1, 12);
|
||||
// for wrapped rows
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(5, 5);
|
||||
assert.position(session.screenToDocumentPosition(4, 1), 1, 12);
|
||||
} ,
|
||||
|
||||
"test: wrapLine split function": function() {
|
||||
function computeAndAssert(line, assertEqual, wrapLimit?, tabSize?) {
|
||||
wrapLimit = wrapLimit || 12;
|
||||
tabSize = tabSize || 4;
|
||||
line = lang.stringTrimRight(line);
|
||||
var tokens = AceAjax.EditSession.prototype.$getDisplayTokens(line);
|
||||
var splits = AceAjax.EditSession.prototype.$computeWrapSplits(tokens, wrapLimit, tabSize);
|
||||
// console.log("String:", line, "Result:", splits, "Expected:", assertEqual);
|
||||
assert.ok(splits.length == assertEqual.length);
|
||||
for (var i = 0; i < splits.length; i++) {
|
||||
assert.ok(splits[i] == assertEqual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Basic splitting.
|
||||
computeAndAssert("foo bar foo bar", [12]);
|
||||
computeAndAssert("foo bar f bar", [12]);
|
||||
computeAndAssert("foo bar f r", [14]);
|
||||
computeAndAssert("foo bar foo bar foo bara foo", [12, 25]);
|
||||
|
||||
// Don't split if there is only whitespaces/tabs at the end of the line.
|
||||
computeAndAssert("foo foo foo \t \t", []);
|
||||
|
||||
// If there is no space to split, force split.
|
||||
computeAndAssert("foooooooooooooo", [12]);
|
||||
computeAndAssert("fooooooooooooooooooooooooooo", [12, 24]);
|
||||
computeAndAssert("foo bar fooooooooooobooooooo", [8, 20]);
|
||||
|
||||
// Basic splitting + tabs.
|
||||
computeAndAssert("foo \t\tbar", [6]);
|
||||
computeAndAssert("foo \t \tbar", [7]);
|
||||
|
||||
// Ignore spaces/tabs at beginning of split.
|
||||
computeAndAssert("foo \t \t \t \t bar", [14]);
|
||||
|
||||
// Test wrapping for asian characters.
|
||||
computeAndAssert("??", [1], 2);
|
||||
computeAndAssert(" ??", [1, 2], 2);
|
||||
computeAndAssert(" ?\t?", [1, 3], 2);
|
||||
computeAndAssert(" ??\t?", [1, 4], 4);
|
||||
|
||||
// Test wrapping for punctuation.
|
||||
computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2);
|
||||
computeAndAssert(" a.b", [1, 2, 3], 1);
|
||||
computeAndAssert("#>>", [1, 2], 1);
|
||||
} ,
|
||||
|
||||
"test get longest line": function() {
|
||||
var session = new AceAjax.EditSession(["12"]);
|
||||
session.setTabSize(4);
|
||||
assert.equal(session.getScreenWidth(), 2);
|
||||
|
||||
session.doc.insertNewLine({ row: 0, column: Infinity });
|
||||
session.doc.insertLines(1, ["123"]);
|
||||
assert.equal(session.getScreenWidth(), 3);
|
||||
|
||||
session.doc.insertNewLine({ row: 0, column: Infinity });
|
||||
session.doc.insertLines(1, ["\t\t"]);
|
||||
|
||||
assert.equal(session.getScreenWidth(), 8);
|
||||
|
||||
session.setTabSize(2);
|
||||
assert.equal(session.getScreenWidth(), 4);
|
||||
} ,
|
||||
|
||||
"test issue 83": function() {
|
||||
var session = new AceAjax.EditSession("");
|
||||
var editor = new AceAjax.Editor(null, session);
|
||||
var document = session.getDocument();
|
||||
|
||||
session.setUseWrapMode(true);
|
||||
|
||||
document.insertLines(0, ["a", "b"]);
|
||||
document.insertLines(2, ["c", "d"]);
|
||||
document.removeLines(1, 2);
|
||||
} ,
|
||||
|
||||
"test wrapMode init has to create wrapData array": function() {
|
||||
var session = new AceAjax.EditSession("foo bar\nfoo bar");
|
||||
var editor = new AceAjax.Editor(null, session);
|
||||
var document = session.getDocument();
|
||||
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(3, 3);
|
||||
session.adjustWrapLimit(80);
|
||||
} ,
|
||||
|
||||
"test first line blank with wrap": function() {
|
||||
var session = new AceAjax.EditSession("\nfoo");
|
||||
session.setUseWrapMode(true);
|
||||
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test first line blank with wrap 2": function() {
|
||||
var session = new AceAjax.EditSession("");
|
||||
session.setUseWrapMode(true);
|
||||
session.setValue("\nfoo");
|
||||
|
||||
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test fold getFoldDisplayLine": function() {
|
||||
var session = createFoldTestSession();
|
||||
function assertDisplayLine(foldLine, str) {
|
||||
var line = session.getLine(foldLine.end.row);
|
||||
var displayLine =
|
||||
session.getFoldDisplayLine(foldLine, foldLine.end.row, line.length);
|
||||
assert.equal(displayLine, str);
|
||||
}
|
||||
} ,
|
||||
|
||||
"test foldLine idxToPosition": function() {
|
||||
var session = createFoldTestSession();
|
||||
|
||||
function assertIdx2Pos(foldLineIdx, idx, row, column) {
|
||||
var foldLine = null;
|
||||
assert.position(foldLine.idxToPosition(idx), row, column);
|
||||
}
|
||||
|
||||
// "function foo(items) {",
|
||||
// " for (var i=0; i<items.length; i++) {",
|
||||
// " alert(items[i] + \"juhu\");",
|
||||
// " } // Real Tab.",
|
||||
// "}"
|
||||
|
||||
assertIdx2Pos(0, 12, 0, 12);
|
||||
assertIdx2Pos(0, 13, 0, 13);
|
||||
assertIdx2Pos(0, 14, 0, 13);
|
||||
assertIdx2Pos(0, 19, 0, 13);
|
||||
assertIdx2Pos(0, 20, 0, 18);
|
||||
|
||||
assertIdx2Pos(1, 10, 1, 10);
|
||||
assertIdx2Pos(1, 11, 1, 10);
|
||||
assertIdx2Pos(1, 15, 1, 10);
|
||||
assertIdx2Pos(1, 16, 2, 10);
|
||||
assertIdx2Pos(1, 26, 2, 20);
|
||||
assertIdx2Pos(1, 27, 2, 20);
|
||||
assertIdx2Pos(1, 32, 2, 25);
|
||||
} ,
|
||||
|
||||
"test fold documentToScreen": function() {
|
||||
var session = createFoldTestSession();
|
||||
function assertDoc2Screen(docRow, docCol, screenRow, screenCol) {
|
||||
assert.position(
|
||||
session.documentToScreenPosition(docRow, docCol),
|
||||
screenRow, screenCol
|
||||
);
|
||||
}
|
||||
|
||||
// One fold ending in the same row.
|
||||
assertDoc2Screen(0, 0, 0, 0);
|
||||
assertDoc2Screen(0, 13, 0, 13);
|
||||
assertDoc2Screen(0, 14, 0, 13);
|
||||
assertDoc2Screen(0, 17, 0, 13);
|
||||
assertDoc2Screen(0, 18, 0, 20);
|
||||
|
||||
// Fold ending on some other row.
|
||||
assertDoc2Screen(1, 0, 1, 0);
|
||||
assertDoc2Screen(1, 10, 1, 10);
|
||||
assertDoc2Screen(1, 11, 1, 10);
|
||||
assertDoc2Screen(1, 99, 1, 10);
|
||||
|
||||
assertDoc2Screen(2, 0, 1, 10);
|
||||
assertDoc2Screen(2, 9, 1, 10);
|
||||
assertDoc2Screen(2, 10, 1, 16);
|
||||
assertDoc2Screen(2, 11, 1, 17);
|
||||
|
||||
// Fold in the same row with fold over more then one row in the same row.
|
||||
assertDoc2Screen(2, 19, 1, 25);
|
||||
assertDoc2Screen(2, 20, 1, 26);
|
||||
assertDoc2Screen(2, 21, 1, 26);
|
||||
|
||||
assertDoc2Screen(2, 24, 1, 26);
|
||||
assertDoc2Screen(2, 25, 1, 32);
|
||||
assertDoc2Screen(2, 26, 1, 33);
|
||||
assertDoc2Screen(2, 99, 1, 40);
|
||||
|
||||
// Test one position after the folds. Should be all like normal.
|
||||
assertDoc2Screen(3, 0, 2, 0);
|
||||
} ,
|
||||
|
||||
"test fold screenToDocument": function() {
|
||||
var session = createFoldTestSession();
|
||||
function assertScreen2Doc(docRow, docCol, screenRow, screenCol) {
|
||||
assert.position(
|
||||
session.screenToDocumentPosition(screenRow, screenCol),
|
||||
docRow, docCol
|
||||
);
|
||||
}
|
||||
|
||||
// One fold ending in the same row.
|
||||
assertScreen2Doc(0, 0, 0, 0);
|
||||
assertScreen2Doc(0, 13, 0, 13);
|
||||
assertScreen2Doc(0, 13, 0, 14);
|
||||
assertScreen2Doc(0, 18, 0, 20);
|
||||
assertScreen2Doc(0, 19, 0, 21);
|
||||
|
||||
// Fold ending on some other row.
|
||||
assertScreen2Doc(1, 0, 1, 0);
|
||||
assertScreen2Doc(1, 10, 1, 10);
|
||||
assertScreen2Doc(1, 10, 1, 11);
|
||||
|
||||
assertScreen2Doc(1, 10, 1, 15);
|
||||
assertScreen2Doc(2, 10, 1, 16);
|
||||
assertScreen2Doc(2, 11, 1, 17);
|
||||
|
||||
// Fold in the same row with fold over more then one row in the same row.
|
||||
assertScreen2Doc(2, 19, 1, 25);
|
||||
assertScreen2Doc(2, 20, 1, 26);
|
||||
assertScreen2Doc(2, 20, 1, 27);
|
||||
|
||||
assertScreen2Doc(2, 20, 1, 31);
|
||||
assertScreen2Doc(2, 25, 1, 32);
|
||||
assertScreen2Doc(2, 26, 1, 33);
|
||||
assertScreen2Doc(2, 33, 1, 99);
|
||||
|
||||
// Test one position after the folds. Should be all like normal.
|
||||
assertScreen2Doc(3, 0, 2, 0);
|
||||
} ,
|
||||
|
||||
"test getFoldsInRange()": function() {
|
||||
var session = createFoldTestSession();
|
||||
var foldLines = null;
|
||||
var folds = foldLines[0].folds.concat(foldLines[1].folds);
|
||||
|
||||
function test(startRow, startColumn, endColumn, endRow, folds) {
|
||||
var r = new AceAjax.Range(startRow, startColumn, endColumn, endRow);
|
||||
var retFolds = session.getFoldsInRange(r);
|
||||
|
||||
assert.ok(retFolds.length == folds.length);
|
||||
for (var i = 0; i < retFolds.length; i++) {
|
||||
assert.equal(retFolds[i].range + "", folds[i].range + "");
|
||||
}
|
||||
}
|
||||
|
||||
test(0, 0, 0, 13, []);
|
||||
test(0, 0, 0, 14, [folds[0]]);
|
||||
test(0, 0, 0, 18, [folds[0]]);
|
||||
test(0, 0, 1, 10, [folds[0]]);
|
||||
test(0, 0, 1, 11, [folds[0], folds[1]]);
|
||||
test(0, 18, 1, 11, [folds[1]]);
|
||||
test(2, 0, 2, 13, [folds[1]]);
|
||||
test(2, 10, 2, 20, []);
|
||||
test(2, 10, 2, 11, []);
|
||||
test(2, 19, 2, 20, []);
|
||||
} ,
|
||||
|
||||
"test fold one-line text insert": function() {
|
||||
// These are mostly test for the FoldLine.addRemoveChars function.
|
||||
var session = createFoldTestSession();
|
||||
var undoManager = session.getUndoManager();
|
||||
var foldLines = null;
|
||||
|
||||
function insert(row, column, text) {
|
||||
session.insert({ row: row, column: column }, text);
|
||||
}
|
||||
|
||||
var foldLine, fold, folds;
|
||||
// First line.
|
||||
foldLine = null;
|
||||
fold = foldLine.folds[0];
|
||||
|
||||
insert(0, 0, "0");
|
||||
assert.range(foldLine.range, 0, 14, 0, 19);
|
||||
assert.range(fold.range, 0, 14, 0, 19);
|
||||
insert(0, 14, "1");
|
||||
assert.range(foldLine.range, 0, 15, 0, 20);
|
||||
assert.range(fold.range, 0, 15, 0, 20);
|
||||
insert(0, 20, "2");
|
||||
assert.range(foldLine.range, 0, 15, 0, 20);
|
||||
assert.range(fold.range, 0, 15, 0, 20);
|
||||
|
||||
// Second line.
|
||||
foldLine = null;
|
||||
folds = foldLine.folds;
|
||||
|
||||
insert(1, 0, "3");
|
||||
assert.range(foldLine.range, 1, 11, 2, 25);
|
||||
assert.range(folds[0].range, 1, 11, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
insert(1, 11, "4");
|
||||
assert.range(foldLine.range, 1, 12, 2, 25);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
insert(2, 10, "5");
|
||||
assert.range(foldLine.range, 1, 12, 2, 26);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 21, 2, 26);
|
||||
|
||||
insert(2, 21, "6");
|
||||
assert.range(foldLine.range, 1, 12, 2, 27);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 22, 2, 27);
|
||||
|
||||
insert(2, 27, "7");
|
||||
assert.range(foldLine.range, 1, 12, 2, 27);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 22, 2, 27);
|
||||
|
||||
// UNDO = REMOVE
|
||||
undoManager.undo(); // 6
|
||||
assert.range(foldLine.range, 1, 12, 2, 27);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 22, 2, 27);
|
||||
|
||||
undoManager.undo(); // 5
|
||||
assert.range(foldLine.range, 1, 12, 2, 26);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 21, 2, 26);
|
||||
|
||||
undoManager.undo(); // 4
|
||||
assert.range(foldLine.range, 1, 12, 2, 25);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
undoManager.undo(); // 3
|
||||
assert.range(foldLine.range, 1, 11, 2, 25);
|
||||
assert.range(folds[0].range, 1, 11, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
undoManager.undo(); // Beginning first line.
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 0, 15, 0, 20);
|
||||
assert.range(foldLines[1].range, 1, 10, 2, 25);
|
||||
|
||||
foldLine = null;
|
||||
fold = foldLine.folds[0];
|
||||
|
||||
undoManager.undo(); // 2
|
||||
assert.range(foldLine.range, 0, 15, 0, 20);
|
||||
assert.range(fold.range, 0, 15, 0, 20);
|
||||
|
||||
undoManager.undo(); // 1
|
||||
assert.range(foldLine.range, 0, 14, 0, 19);
|
||||
assert.range(fold.range, 0, 14, 0, 19);
|
||||
|
||||
undoManager.undo(); // 0
|
||||
assert.range(foldLine.range, 0, 13, 0, 18);
|
||||
assert.range(fold.range, 0, 13, 0, 18);
|
||||
} ,
|
||||
|
||||
"test fold multi-line insert/remove": function() {
|
||||
var session = createFoldTestSession(),
|
||||
undoManager = session.getUndoManager(),
|
||||
foldLines = null;
|
||||
function insert(row, column, text) {
|
||||
session.insert({ row: row, column: column }, text);
|
||||
}
|
||||
|
||||
var foldLines = null, foldLine, fold, folds;
|
||||
|
||||
insert(0, 0, "\nfo0");
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 2, 10, 3, 25);
|
||||
|
||||
insert(2, 0, "\nba1");
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 3, 13, 4, 25);
|
||||
|
||||
insert(3, 10, "\nfo2");
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 25);
|
||||
|
||||
insert(5, 10, "\nba3");
|
||||
assert.equal(foldLines.length, 3);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 10);
|
||||
assert.range(foldLines[2].range, 6, 13, 6, 18);
|
||||
|
||||
insert(6, 18, "\nfo4");
|
||||
assert.equal(foldLines.length, 3);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 10);
|
||||
assert.range(foldLines[2].range, 6, 13, 6, 18);
|
||||
|
||||
undoManager.undo(); // 3
|
||||
assert.equal(foldLines.length, 3);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 10);
|
||||
assert.range(foldLines[2].range, 6, 13, 6, 18);
|
||||
|
||||
undoManager.undo(); // 2
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 25);
|
||||
|
||||
undoManager.undo(); // 1
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 3, 13, 4, 25);
|
||||
|
||||
undoManager.undo(); // 0
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 2, 10, 3, 25);
|
||||
|
||||
undoManager.undo(); // Beginning
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 0, 13, 0, 18);
|
||||
assert.range(foldLines[1].range, 1, 10, 2, 25);
|
||||
// TODO: Add test for inseration inside of folds.
|
||||
} ,
|
||||
|
||||
"test fold wrap data compution": function() {
|
||||
function assertWrap(line0, line1, line2) {
|
||||
line0 && assertArray(wrapData[0], line0);
|
||||
line1 && assertArray(wrapData[1], line1);
|
||||
line2 && assertArray(wrapData[2], line2);
|
||||
}
|
||||
|
||||
function removeFoldAssertWrap(docRow, docColumn, line0, line1, line2) {
|
||||
session.removeFold(session.getFoldAt(docRow, docColumn));
|
||||
assertWrap(line0, line1, line2);
|
||||
}
|
||||
|
||||
var lines = [
|
||||
"foo bar foo bar",
|
||||
"foo bar foo bar",
|
||||
"foo bar foo bar"
|
||||
];
|
||||
|
||||
var session = new AceAjax.EditSession(lines.join("\n"));
|
||||
session.setUseWrapMode(true);
|
||||
var wrapData = null;
|
||||
|
||||
// Do a simple assertion without folds to check basic functionallity.
|
||||
assertWrap([8], [8], [8]);
|
||||
|
||||
// --- Do in line folding ---
|
||||
|
||||
// Adding a fold. The split position is inside of the fold. As placeholder
|
||||
// are not splitable, the split should be before the split.
|
||||
session.addFold("woot", new AceAjax.Range(0, 4, 0, 15));
|
||||
assertWrap([4], [8], [8]);
|
||||
|
||||
// Remove the fold again which should reset the wrapData.
|
||||
removeFoldAssertWrap(0, 4, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot", new AceAjax.Range(0, 6, 0, 9));
|
||||
assertWrap([6, 13], [8], [8]);
|
||||
removeFoldAssertWrap(0, 6, [8], [8], [8]);
|
||||
|
||||
// The fold fits into the wrap limit - no split expected.
|
||||
session.addFold("woot", new AceAjax.Range(0, 3, 0, 15));
|
||||
assertWrap([], [8], [8]);
|
||||
removeFoldAssertWrap(0, 4, [8], [8], [8]);
|
||||
|
||||
// Fold after split position should be all fine.
|
||||
session.addFold("woot", new AceAjax.Range(0, 8, 0, 15));
|
||||
assertWrap([8], [8], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
// Fold's placeholder is far too long for wrapSplit.
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 8, 0, 15));
|
||||
assertWrap([8], [8], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
// Fold's placeholder is far too long for wrapSplit
|
||||
// + content at the end of the line
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 6, 0, 8));
|
||||
assertWrap([6, 20], [8], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 6, 0, 8));
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 8, 0, 10));
|
||||
assertWrap([6, 20, 34], [8], [8]);
|
||||
session.removeFold(session.getFoldAt(0, 7));
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 7, 0, 9));
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 13, 0, 15));
|
||||
assertWrap([7, 21, 25], [8], [8]);
|
||||
session.removeFold(session.getFoldAt(0, 7));
|
||||
removeFoldAssertWrap(0, 14, [8], [8], [8]);
|
||||
|
||||
// --- Do some multiline folding ---
|
||||
|
||||
// Add a fold over two lines. Note, that the wrapData[1] stays the
|
||||
// same. This is an implementation detail and expected behavior.
|
||||
session.addFold("woot", new AceAjax.Range(0, 8, 1, 15));
|
||||
assertWrap([8], [8 /* See comments */], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot", new AceAjax.Range(0, 9, 1, 11));
|
||||
assertWrap([8, 14], [8 /* See comments */], [8]);
|
||||
removeFoldAssertWrap(0, 9, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot", new AceAjax.Range(0, 9, 1, 15));
|
||||
assertWrap([8], [8 /* See comments */], [8]);
|
||||
removeFoldAssertWrap(0, 9, [8], [8], [8]);
|
||||
|
||||
return session;
|
||||
} ,
|
||||
|
||||
"test add fold": function() {
|
||||
var session = createFoldTestSession();
|
||||
var fold;
|
||||
|
||||
function tryAddFold(placeholder, range, shouldFail) {
|
||||
var fail = false;
|
||||
try {
|
||||
fold = session.addFold(placeholder, range);
|
||||
} catch (e) {
|
||||
fail = true;
|
||||
}
|
||||
if (fail != shouldFail) {
|
||||
throw "Expected to get an exception";
|
||||
}
|
||||
}
|
||||
|
||||
tryAddFold("foo", new AceAjax.Range(0, 13, 0, 17), false);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 14, 0, 18), true);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 13, 0, 18), false);
|
||||
|
||||
tryAddFold("f", new AceAjax.Range(0, 13, 0, 18), false);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 18, 0, 21), false);
|
||||
session.removeFold(fold);
|
||||
|
||||
tryAddFold("foo", new AceAjax.Range(0, 18, 0, 22), false);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 18, 0, 19), true);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 22, 1, 10), false);
|
||||
} ,
|
||||
|
||||
"test add subfolds": function() {
|
||||
var session = createFoldTestSession();
|
||||
var fold, oldFold;
|
||||
var foldData = null;
|
||||
|
||||
oldFold = foldData[0].folds[0];
|
||||
|
||||
fold = session.addFold("fold0", new AceAjax.Range(0, 10, 0, 21));
|
||||
assert.equal(foldData[0].folds.length, 1);
|
||||
assert.equal(fold.subFolds.length, 1);
|
||||
assert.equal(fold.subFolds[0], oldFold);
|
||||
|
||||
session.expandFold(fold);
|
||||
assert.equal(foldData[0].folds.length, 1);
|
||||
assert.equal(foldData[0].folds[0], oldFold);
|
||||
assert.equal(fold.subFolds.length, 0);
|
||||
|
||||
fold = session.addFold("fold0", new AceAjax.Range(0, 13, 2, 10));
|
||||
assert.equal(foldData.length, 1);
|
||||
assert.equal(fold.subFolds.length, 2);
|
||||
assert.equal(fold.subFolds[0], oldFold);
|
||||
|
||||
session.expandFold(fold);
|
||||
assert.equal(foldData.length, 2);
|
||||
assert.equal(foldData[0].folds.length, 1);
|
||||
assert.equal(foldData[0].folds[0], oldFold);
|
||||
assert.equal(fold.subFolds.length, 0);
|
||||
|
||||
session.unfold(null, true);
|
||||
fold = session.addFold("fold0", new AceAjax.Range(0, 0, 0, 21));
|
||||
session.addFold("fold0", new AceAjax.Range(0, 1, 0, 5));
|
||||
session.addFold("fold0", new AceAjax.Range(0, 6, 0, 8));
|
||||
assert.equal(fold.subFolds.length, 2);
|
||||
} ,
|
||||
|
||||
"test row cache": function() {
|
||||
var session = createFoldTestSession();
|
||||
|
||||
session.screenToDocumentPosition(2, 3);
|
||||
|
||||
session.screenToDocumentPosition(5, 3);
|
||||
|
||||
session.screenToDocumentPosition(0, 3);
|
||||
|
||||
var pos = session.screenToDocumentPosition(0, 0);
|
||||
assert.equal(pos.row, 0);
|
||||
|
||||
session.screenToDocumentPosition(1, 0);
|
||||
|
||||
|
||||
session.screenToDocumentPosition(1, 3);
|
||||
|
||||
session.screenToDocumentPosition(5, 3);
|
||||
|
||||
session = new AceAjax.EditSession(new Array(30).join("\n"));
|
||||
session.documentToScreenPosition(2, 0);
|
||||
session.documentToScreenPosition(2, 0);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,151 @@
|
||||
const aceEditor1Tests = {
|
||||
|
||||
setUp: function(next) {
|
||||
this.session1 = new AceAjax.EditSession(["abc", "def"]);
|
||||
this.session2 = new AceAjax.EditSession(["ghi", "jkl"]);
|
||||
|
||||
|
||||
var editor = new AceAjax.Editor(null);
|
||||
next();
|
||||
} ,
|
||||
|
||||
"test: change document": function() {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.setSession(this.session1);
|
||||
assert.equal(editor.getSession(), this.session1);
|
||||
|
||||
editor.setSession(this.session2);
|
||||
assert.equal(editor.getSession(), this.session2);
|
||||
} ,
|
||||
|
||||
"test: only changes to the new document should have effect": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
var called = false;
|
||||
editor.onDocumentChange = function () {
|
||||
called = true;
|
||||
};
|
||||
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
|
||||
this.session1.duplicateLines(0, 0);
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.duplicateLines(0, 0);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use cursor of new document": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
this.session1.getSelection().moveCursorTo(0, 1);
|
||||
this.session2.getSelection().moveCursorTo(1, 0);
|
||||
|
||||
editor.setSession(this.session1);
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
} ,
|
||||
|
||||
"test: only changing the cursor of the new doc should not have an effect": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.onCursorChange = function () {
|
||||
called = true;
|
||||
};
|
||||
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
var called = false;
|
||||
this.session1.getSelection().moveCursorTo(0, 1);
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.getSelection().moveCursorTo(1, 1);
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use selection of new document": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
this.session1.getSelection().selectTo(0, 1);
|
||||
this.session2.getSelection().selectTo(1, 0);
|
||||
|
||||
editor.setSession(this.session1);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 1);
|
||||
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
} ,
|
||||
|
||||
"test: only changing the selection of the new doc should not have an effect": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.onSelectionChange = function () {
|
||||
called = true;
|
||||
};
|
||||
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
|
||||
var called = false;
|
||||
this.session1.getSelection().selectTo(0, 1);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.getSelection().selectTo(1, 1);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 1);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use mode of new document": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.onChangeMode = function () {
|
||||
called = true;
|
||||
};
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
|
||||
var called = false;
|
||||
this.session1.setMode(new Text());
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.setMode(null);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use stop worker of old document": function (next) {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
var self = this;
|
||||
|
||||
// 1. Open an editor and set the session to CssMode
|
||||
self.editor.setSession(self.session1);
|
||||
self.session1.setMode(null);
|
||||
|
||||
// 2. Add a line or two of valid CSS.
|
||||
self.session1.setValue("DIV { color: red; }");
|
||||
|
||||
// 3. Clear the session value.
|
||||
self.session1.setValue("");
|
||||
|
||||
// 4. Set the session to HtmlMode
|
||||
self.session1.setMode(null);
|
||||
|
||||
// 5. Try to type valid HTML
|
||||
self.session1.insert({ row: 0, column: 0 }, "<html></html>");
|
||||
|
||||
setTimeout(function () {
|
||||
assert.equal(Object.keys(self.session1.getAnnotations()).length, 0);
|
||||
next();
|
||||
}, 600);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,217 @@
|
||||
|
||||
|
||||
var lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
|
||||
"Mauris at arcu mi, eu lobortis mauris. Quisque ut libero eget " +
|
||||
"diam congue vehicula. Quisque ut odio ut mi aliquam tincidunt. " +
|
||||
"Duis lacinia aliquam lorem eget eleifend. Morbi eget felis mi. " +
|
||||
"Duis quam ligula, consequat vitae convallis volutpat, blandit " +
|
||||
"nec neque. Nulla facilisi. Etiam suscipit lorem ac justo " +
|
||||
"sollicitudin tristique. Phasellus ut posuere nunc. Aliquam " +
|
||||
"scelerisque mollis felis non gravida. Vestibulum lacus sem, " +
|
||||
"posuere non bibendum id, luctus non dolor. Aenean id metus " +
|
||||
"lorem, vel dapibus est. Donec gravida feugiat augue nec " +
|
||||
"accumsan.Lorem ipsum dolor sit amet, consectetur adipiscing " +
|
||||
"elit. Nulla vulputate, velit vitae tincidunt congue, nunc " +
|
||||
"augue accumsan velit, eu consequat turpis lectus ac orci. " +
|
||||
"Pellentesque ornare dolor feugiat dui auctor eu varius nulla " +
|
||||
"fermentum. Sed aliquam odio at velit lacinia vel fermentum " +
|
||||
"felis sodales. In dignissim magna eget nunc lobortis non " +
|
||||
"fringilla nibh ullamcorper. Donec facilisis malesuada elit " +
|
||||
"at egestas. Etiam bibendum, diam vitae tempor aliquet, dui " +
|
||||
"libero vehicula odio, eget bibendum mauris velit eu lorem.\n" +
|
||||
"consectetur";
|
||||
|
||||
function callHighlighterUpdate(session: AceAjax.IEditSession, firstRow: number, lastRow: number) {
|
||||
var rangeCount = 0;
|
||||
var mockMarkerLayer = { drawSingleLineMarker: function () { rangeCount++; } }
|
||||
return rangeCount;
|
||||
}
|
||||
|
||||
var assert: any;
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
|
||||
const aceEditorHighlighSelectedWorkTests = {
|
||||
setUp: function(next) {
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
var selection = session.getSelection();
|
||||
next();
|
||||
} ,
|
||||
|
||||
"test: highlight selected words by default": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
assert.equal(editor.getHighlightSelectedWord(), true);
|
||||
} ,
|
||||
|
||||
"test: highlight a word": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 9);
|
||||
selection.selectWord();
|
||||
|
||||
var highlighter = null;
|
||||
assert.ok(highlighter != null);
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "ipsum");
|
||||
assert.equal(highlighter.cache.length, 0);
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 2);
|
||||
} ,
|
||||
|
||||
"test: highlight a word and clear highlight": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 8);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "ipsum");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 2);
|
||||
|
||||
session.highlight("");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: highlight another word": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolor");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 4);
|
||||
} ,
|
||||
|
||||
"test: no selection, no highlight": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.clearSelection();
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: select a word, no highlight": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
|
||||
editor.setHighlightSelectedWord(false);
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolor");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: select a word with no matches": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.setHighlightSelectedWord(true);
|
||||
|
||||
var currentOptions = this.search.getOptions();
|
||||
var newOptions = {
|
||||
wrap: true,
|
||||
wholeWord: true,
|
||||
caseSensitive: true,
|
||||
needle: "Mauris"
|
||||
};
|
||||
this.search.set(newOptions);
|
||||
|
||||
var match = this.search.find(session);
|
||||
assert.notEqual(match, null, "found a match for 'Mauris'");
|
||||
|
||||
this.search.set(currentOptions);
|
||||
|
||||
selection.setSelectionRange(match);
|
||||
|
||||
assert.equal(session.getTextRange(match), "Mauris");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 1);
|
||||
} ,
|
||||
|
||||
"test: partial word selection 1": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
selection.selectLeft();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolo");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: partial word selection 2": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 13);
|
||||
selection.selectWord();
|
||||
selection.selectRight();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolor ");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: partial word selection 3": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
selection.selectLeft();
|
||||
selection.shiftSelection(1);
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "olor");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: select last word": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 1);
|
||||
|
||||
var currentOptions = this.search.getOptions();
|
||||
var newOptions = {
|
||||
wrap: true,
|
||||
wholeWord: true,
|
||||
caseSensitive: true,
|
||||
backwards: true,
|
||||
needle: "consectetur"
|
||||
};
|
||||
this.search.set(newOptions);
|
||||
|
||||
var match = this.search.find(session);
|
||||
assert.notEqual(match, null, "found a match for 'consectetur'");
|
||||
assert.position(match.start, 1, 0);
|
||||
|
||||
this.search.set(currentOptions);
|
||||
|
||||
selection.setSelectionRange(match);
|
||||
|
||||
assert.equal(session.getTextRange(match), "consectetur");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 1), 3);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,116 @@
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
const aceEditorNavigationTests = {
|
||||
createEditSession: function (rows, cols) {
|
||||
var line = new Array(cols + 1).join("a");
|
||||
var text = new Array(rows).join(line + "\n") + line;
|
||||
return new AceAjax.EditSession(text);
|
||||
},
|
||||
|
||||
"test: navigate to end of file should scroll the last line into view": function () {
|
||||
var doc = this.createEditSession(200, 10);
|
||||
var editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.navigateFileEnd();
|
||||
var cursor = editor.getCursorPosition();
|
||||
|
||||
assert.ok(editor.getFirstVisibleRow() <= cursor.row);
|
||||
assert.ok(editor.getLastVisibleRow() >= cursor.row);
|
||||
},
|
||||
|
||||
"test: navigate to start of file should scroll the first row into view": function () {
|
||||
var doc = this.createEditSession(200, 10);
|
||||
var editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.moveCursorTo(editor.getLastVisibleRow() + 20);
|
||||
editor.navigateFileStart();
|
||||
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
},
|
||||
|
||||
"test: goto hidden line should scroll the line into the middle of the viewport": function () {
|
||||
var editor = new AceAjax.Editor(renderer, this.createEditSession(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(101);
|
||||
assert.position(editor.getCursorPosition(), 100, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 89);
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(11);
|
||||
assert.position(editor.getCursorPosition(), 10, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(6);
|
||||
assert.position(editor.getCursorPosition(), 5, 0);
|
||||
assert.equal(0, editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(1);
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(191);
|
||||
assert.position(editor.getCursorPosition(), 190, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 179);
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(196);
|
||||
assert.position(editor.getCursorPosition(), 195, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 180);
|
||||
},
|
||||
|
||||
"test: goto visible line should only move the cursor and not scroll": function () {
|
||||
var editor = new AceAjax.Editor(renderer, this.createEditSession(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(12);
|
||||
assert.position(editor.getCursorPosition(), 11, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(30, 0);
|
||||
editor.gotoLine(33);
|
||||
assert.position(editor.getCursorPosition(), 32, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 30);
|
||||
},
|
||||
|
||||
"test: navigate from the end of a long line down to a short line and back should maintain the curser column": function () {
|
||||
var editor = new AceAjax.Editor(renderer, new AceAjax.EditSession(["123456", "1"]));
|
||||
|
||||
editor.navigateTo(0, 6);
|
||||
assert.position(editor.getCursorPosition(), 0, 6);
|
||||
|
||||
editor.navigateDown();
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
editor.navigateUp();
|
||||
assert.position(editor.getCursorPosition(), 0, 6);
|
||||
},
|
||||
|
||||
"test: reset desired column on navigate left or right": function () {
|
||||
var editor = new AceAjax.Editor(renderer, new AceAjax.EditSession(["123456", "12"]));
|
||||
|
||||
editor.navigateTo(0, 6);
|
||||
assert.position(editor.getCursorPosition(), 0, 6);
|
||||
|
||||
editor.navigateDown();
|
||||
assert.position(editor.getCursorPosition(), 1, 2);
|
||||
|
||||
editor.navigateLeft();
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
editor.navigateUp();
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
},
|
||||
|
||||
"test: typing text should update the desired column": function () {
|
||||
var editor = new AceAjax.Editor(renderer, new AceAjax.EditSession(["1234", "1234567890"]));
|
||||
|
||||
editor.navigateTo(0, 3);
|
||||
editor.insert("juhu");
|
||||
|
||||
editor.navigateDown();
|
||||
assert.position(editor.getCursorPosition(), 1, 7);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,498 @@
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
var mode: any;
|
||||
const aceEditorTextEditTests = {
|
||||
"test: delete line from the middle": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a\nc\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a");
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
},
|
||||
|
||||
"test: delete multiple selected lines": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
},
|
||||
|
||||
"test: delete first line": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "b\nc");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
},
|
||||
|
||||
"test: delete last should also delete the new line of the previous line": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", ""].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(3, 0);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb\nc");
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb");
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
},
|
||||
|
||||
"test: indent block": function () {
|
||||
var session = new AceAjax.EditSession(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
assert.equal(["a12345", " b12345", " c12345"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 7);
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 1, 7);
|
||||
assert.position(range.end, 2, 7);
|
||||
},
|
||||
|
||||
"test: indent selected lines": function () {
|
||||
var session = new AceAjax.EditSession(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
assert.equal(["a12345", " b12345", "c12345"].join("\n"), session.toString());
|
||||
},
|
||||
|
||||
"test: no auto indent if cursor is before the {": function () {
|
||||
var session = new AceAjax.EditSession("{",mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.onTextInput("\n");
|
||||
assert.equal(["", "{"].join("\n"), session.toString());
|
||||
},
|
||||
|
||||
"test: outdent block": function () {
|
||||
var session = new AceAjax.EditSession([" a12345", " b12345", " c12345"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), [" a12345", "b12345", " c12345"].join("\n"));
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 1);
|
||||
assert.position(range.end, 2, 1);
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), ["a12345", "b12345", "c12345"].join("\n"));
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 2, 0);
|
||||
},
|
||||
|
||||
"test: outent without a selection should update cursor": function () {
|
||||
var session = new AceAjax.EditSession(" 12");
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.blockOutdent(" ");
|
||||
|
||||
assert.equal(session.toString(), " 12");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
},
|
||||
|
||||
"test: comment lines should perserve selection": function () {
|
||||
var session = new AceAjax.EditSession([" abc", "cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.getSelection().selectDown();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal(["// abc", "//cde"].join("\n"), session.toString());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assert.position(selection.start, 0, 4);
|
||||
assert.position(selection.end, 1, 4);
|
||||
},
|
||||
|
||||
"test: uncomment lines should perserve selection": function () {
|
||||
var session = new AceAjax.EditSession(["// abc", "//cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectRight();
|
||||
editor.getSelection().selectRight();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde"].join("\n"), session.toString());
|
||||
assert.range(editor.getSelectionRange(), 0, 0, 1, 1);
|
||||
},
|
||||
|
||||
"test: toggle comment lines twice should return the original text": function () {
|
||||
var session = new AceAjax.EditSession([" abc", "cde", "fg"], mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());
|
||||
},
|
||||
|
||||
|
||||
"test: comment lines - if the selection end is at the line start it should stay there": function () {
|
||||
//select down
|
||||
var session = new AceAjax.EditSession(["abc", "cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
|
||||
// select up
|
||||
var session = new AceAjax.EditSession(["abc", "cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectUp();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
},
|
||||
|
||||
"test: move lines down should select moved lines": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "11", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
|
||||
// moving again should have no effect
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
},
|
||||
|
||||
"test: move lines up should select moved lines": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(2, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["11", "33", "44", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["33", "44", "11", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
},
|
||||
|
||||
"test: move line without active selection should not move cursor relative to the moved line": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["11", "33", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(["11", "22", "33", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
},
|
||||
|
||||
"test: copy lines down should select lines and place cursor at the selection start": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesDown();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 5, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 3, 0);
|
||||
},
|
||||
|
||||
"test: copy lines up should select lines and place cursor at the selection start": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesUp();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
},
|
||||
|
||||
"test: input a tab with soft tab should convert it to spaces": function () {
|
||||
var session = new AceAjax.EditSession("");
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
session.setTabSize(2);
|
||||
session.setUseSoftTabs(true);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
|
||||
session.setTabSize(5);
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
},
|
||||
|
||||
"test: input tab without soft tabs should keep the tab character": function () {
|
||||
var session = new AceAjax.EditSession("");
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
session.setUseSoftTabs(false);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), "\t");
|
||||
},
|
||||
|
||||
"test: undo/redo for delete line": function () {
|
||||
var session = new AceAjax.EditSession(["111", "222", "333"]);
|
||||
var undoManager = new AceAjax.UndoManager();
|
||||
session.setUndoManager(undoManager);
|
||||
|
||||
var initialText = session.toString();
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.removeLines();
|
||||
var step1 = session.toString();
|
||||
assert.equal(step1, "222\n333");
|
||||
|
||||
editor.removeLines();
|
||||
var step2 = session.toString();
|
||||
assert.equal(step2, "333");
|
||||
|
||||
editor.removeLines();
|
||||
var step3 = session.toString();
|
||||
assert.equal(step3, "");
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step2);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step1);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), initialText);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), initialText);
|
||||
},
|
||||
|
||||
"test: remove left should remove character left of the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "456"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n56");
|
||||
},
|
||||
|
||||
"test: remove left should remove line break if cursor is at line start": function () {
|
||||
var session = new AceAjax.EditSession(["123", "456"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123456");
|
||||
},
|
||||
|
||||
"test: remove left should remove tabsize spaces if cursor is on a tab stop and preceeded by spaces": function () {
|
||||
var session = new AceAjax.EditSession(["123", " 456"]);
|
||||
session.setUseSoftTabs(true);
|
||||
session.setTabSize(4);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 8);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n 456");
|
||||
},
|
||||
|
||||
"test: transpose at line start should be a noop": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose in line should swap the charaters before and after the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4657", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose at line end should swap the last two characters": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4576", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose with non empty selection should be a noop": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectRight();
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose should move the cursor behind the last swapped character": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
assert.position(editor.getCursorPosition(), 1, 3);
|
||||
},
|
||||
|
||||
"test: remove to line end": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.removeToLineEnd();
|
||||
assert.equal(session.getValue(), ["123", "45", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: remove to line end at line end should remove the new line": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.removeToLineEnd();
|
||||
assert.position(editor.getCursorPosition(), 1, 4);
|
||||
assert.equal(session.getValue(), ["123", "456789"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform selection to uppercase": function () {
|
||||
var session = new AceAjax.EditSession(["ajax", "dot", "org"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform word to uppercase": function () {
|
||||
var session = new AceAjax.EditSession(["ajax", "dot", "org"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
},
|
||||
|
||||
"test: transform selection to lowercase": function () {
|
||||
var session = new AceAjax.EditSession(["AJAX", "DOT", "ORG"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform word to lowercase": function () {
|
||||
var session = new AceAjax.EditSession(["AJAX", "DOT", "ORG"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,109 @@
|
||||
var exec = function (name?, times?, args?) {
|
||||
do {
|
||||
editor.commands.exec(name, editor, args);
|
||||
} while (times-- > 1)
|
||||
};
|
||||
var testRanges = function (str) {
|
||||
assert.equal(editor.selection.getAllRanges() + "", str + "");
|
||||
}
|
||||
|
||||
const aceMultiSelectTests = {
|
||||
|
||||
name: "ACE multi_select.js",
|
||||
|
||||
"test: multiselect editing": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.w"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.navigateFileEnd();
|
||||
exec("selectMoreBefore", 3);
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
assert.equal(editor.selection.getAllRanges().length, 4);
|
||||
|
||||
var newLine = editor.session.getDocument().getNewLineCharacter();
|
||||
var copyText = "wwww".split("").join(newLine);
|
||||
assert.equal(editor.getCopyText(), copyText);
|
||||
exec("insertstring", 1, "a");
|
||||
exec("backspace", 2);
|
||||
assert.equal(editor.session.getValue(), "w1.w2\ntt\ntt");
|
||||
assert.equal(editor.selection.getAllRanges().length, 4);
|
||||
|
||||
exec("selectall");
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
//assert.equal(editor.selection.getAllRanges().length, 1);
|
||||
} ,
|
||||
|
||||
"test: multiselect navigation": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.we"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.selectMoreLines(1);
|
||||
testRanges("Range: [0/0] -> [0/0],Range: [1/0] -> [1/0]");
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
|
||||
exec("golinedown");
|
||||
exec("gotolineend");
|
||||
testRanges("Range: [1/9] -> [1/9],Range: [2/10] -> [2/10]");
|
||||
exec("selectwordleft");
|
||||
|
||||
testRanges("Range: [1/8] -> [1/9],Range: [2/8] -> [2/10]");
|
||||
exec("golinedown", 2);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
} ,
|
||||
|
||||
"test: multiselect session change": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.w"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.selectMoreLines(1)
|
||||
testRanges("Range: [0/0] -> [0/0],Range: [1/0] -> [1/0]");
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
|
||||
var doc2 = new AceAjax.EditSession(["w1"]);
|
||||
editor.setSession(doc2);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
|
||||
editor.setSession(doc);
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
} ,
|
||||
|
||||
"test: multiselect addRange": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.w"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
var selection = editor.selection;
|
||||
|
||||
var range1 = new AceAjax.Range(0, 2, 0, 4);
|
||||
editor.selection.fromOrientedRange(range1);
|
||||
|
||||
var range2 = new AceAjax.Range(0, 3, 0, 4);
|
||||
selection.addRange(range2);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
assert.ok(range2.isEqual(editor.selection.getRange()));
|
||||
|
||||
var range3 = new AceAjax.Range(0, 1, 0, 1);
|
||||
selection.addRange(range3);
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
testRanges([range3, range2]);
|
||||
|
||||
var range4 = new AceAjax.Range(0, 0, 4, 0);
|
||||
selection.addRange(range4);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,106 @@
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
var mode: any;
|
||||
const acePlaceholderTests = {
|
||||
|
||||
"test: simple at the end appending of text": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.insert('b');
|
||||
assert.equal(session.doc.getValue(), "var ab = 10;\nconsole.log(ab, ab);");
|
||||
editor.insert('cd');
|
||||
assert.equal(session.doc.getValue(), "var abcd = 10;\nconsole.log(abcd, abcd);");
|
||||
editor.remove('left');
|
||||
editor.remove('left');
|
||||
editor.remove('left');
|
||||
assert.equal(session.doc.getValue(), "var a = 10;\nconsole.log(a, a);");
|
||||
},
|
||||
|
||||
"test: inserting text outside placeholder": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);\n", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(2, 0);
|
||||
editor.insert('b');
|
||||
assert.equal(session.doc.getValue(), "var a = 10;\nconsole.log(a, a);\nb");
|
||||
},
|
||||
|
||||
"test: insertion at the beginning": function (next) {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 4);
|
||||
editor.insert('$');
|
||||
assert.equal(session.doc.getValue(), "var $a = 10;\nconsole.log($a, $a);");
|
||||
editor.moveCursorTo(0, 4);
|
||||
// Have to put this in a setTimeout because the anchor is only fixed later.
|
||||
setTimeout(function () {
|
||||
editor.insert('v');
|
||||
assert.equal(session.doc.getValue(), "var v$a = 10;\nconsole.log(v$a, v$a);");
|
||||
next();
|
||||
}, 10);
|
||||
},
|
||||
|
||||
"test: detaching placeholder": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.insert('b');
|
||||
assert.equal(session.doc.getValue(), "var ab = 10;\nconsole.log(ab, ab);");
|
||||
p.detach();
|
||||
editor.insert('cd');
|
||||
assert.equal(session.doc.getValue(), "var abcd = 10;\nconsole.log(ab, ab);");
|
||||
},
|
||||
|
||||
"test: events": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
var entered = false;
|
||||
var left = false;
|
||||
p.on("cursorEnter", function () {
|
||||
entered = true;
|
||||
});
|
||||
p.on("cursorLeave", function () {
|
||||
left = true;
|
||||
});
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.moveCursorTo(0, 4);
|
||||
p.onCursorChange(); // Have to do this by hand because moveCursorTo doesn't trigger the event
|
||||
assert.ok(entered);
|
||||
editor.moveCursorTo(1, 0);
|
||||
p.onCursorChange(); // Have to do this by hand because moveCursorTo doesn't trigger the event
|
||||
assert.ok(left);
|
||||
},
|
||||
|
||||
"test: cancel": function (next) {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
session.setUndoManager(new AceAjax.UndoManager());
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.insert('b');
|
||||
editor.insert('cd');
|
||||
editor.remove('left');
|
||||
assert.equal(session.doc.getValue(), "var abc = 10;\nconsole.log(abc, abc);");
|
||||
// Wait a little for the changes to enter the undo stack
|
||||
setTimeout(function () {
|
||||
p.cancel();
|
||||
assert.equal(session.doc.getValue(), "var a = 10;\nconsole.log(a, a);");
|
||||
next();
|
||||
}, 80);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,144 @@
|
||||
const aceRangeTests = {
|
||||
|
||||
name: "ACE range.js",
|
||||
|
||||
"test: create range": function () {
|
||||
var range = new AceAjax.Range(1, 2, 3, 4);
|
||||
|
||||
assert.equal(range.start.row, 1);
|
||||
assert.equal(range.start.column, 2);
|
||||
assert.equal(range.end.row, 3);
|
||||
assert.equal(range.end.column, 4);
|
||||
},
|
||||
|
||||
"test: create from points": function () {
|
||||
var range = AceAjax.Range.fromPoints({ row: 1, column: 2 }, { row: 3, column: 4 });
|
||||
|
||||
assert.equal(range.start.row, 1);
|
||||
assert.equal(range.start.column, 2);
|
||||
assert.equal(range.end.row, 3);
|
||||
assert.equal(range.end.column, 4);
|
||||
},
|
||||
|
||||
"test: clip to rows": function () {
|
||||
assert.range(new AceAjax.Range(0, 20, 100, 30).clipRows(10, 30), 10, 0, 31, 0);
|
||||
assert.range(new AceAjax.Range(0, 20, 30, 10).clipRows(10, 30), 10, 0, 30, 10);
|
||||
|
||||
var range = new AceAjax.Range(0, 20, 3, 10);
|
||||
var range = range.clipRows(10, 30);
|
||||
|
||||
assert.ok(range.isEmpty());
|
||||
assert.range(range, 10, 0, 10, 0);
|
||||
},
|
||||
|
||||
"test: isEmpty": function () {
|
||||
var range = new AceAjax.Range(1, 2, 1, 2);
|
||||
assert.ok(range.isEmpty());
|
||||
|
||||
var range = new AceAjax.Range(1, 2, 1, 6);
|
||||
assert.notOk(range.isEmpty());
|
||||
},
|
||||
|
||||
"test: is multi line": function () {
|
||||
var range = new AceAjax.Range(1, 2, 1, 6);
|
||||
assert.notOk(range.isMultiLine());
|
||||
|
||||
var range = new AceAjax.Range(1, 2, 2, 6);
|
||||
assert.ok(range.isMultiLine());
|
||||
},
|
||||
|
||||
"test: clone": function () {
|
||||
var range = new AceAjax.Range(1, 2, 3, 4);
|
||||
var clone = range.clone();
|
||||
|
||||
assert.position(clone.start, 1, 2);
|
||||
assert.position(clone.end, 3, 4);
|
||||
|
||||
clone.start.column = 20;
|
||||
assert.position(range.start, 1, 2);
|
||||
|
||||
clone.end.column = 20;
|
||||
assert.position(range.end, 3, 4);
|
||||
},
|
||||
|
||||
"test: contains for multi line ranges": function () {
|
||||
var range = new AceAjax.Range(1, 10, 5, 20);
|
||||
|
||||
assert.ok(range.contains(1, 10));
|
||||
assert.ok(range.contains(2, 0));
|
||||
assert.ok(range.contains(3, 100));
|
||||
assert.ok(range.contains(5, 19));
|
||||
assert.ok(range.contains(5, 20));
|
||||
|
||||
assert.notOk(range.contains(1, 9));
|
||||
assert.notOk(range.contains(0, 0));
|
||||
assert.notOk(range.contains(5, 21));
|
||||
},
|
||||
|
||||
"test: contains for single line ranges": function () {
|
||||
var range = new AceAjax.Range(1, 10, 1, 20);
|
||||
|
||||
assert.ok(range.contains(1, 10));
|
||||
assert.ok(range.contains(1, 15));
|
||||
assert.ok(range.contains(1, 20));
|
||||
|
||||
assert.notOk(range.contains(0, 9));
|
||||
assert.notOk(range.contains(2, 9));
|
||||
assert.notOk(range.contains(1, 9));
|
||||
assert.notOk(range.contains(1, 21));
|
||||
},
|
||||
|
||||
"test: extend range": function () {
|
||||
var range = new AceAjax.Range(2, 10, 2, 30);
|
||||
|
||||
var range = range.extend(2, 5);
|
||||
assert.range(range, 2, 5, 2, 30);
|
||||
|
||||
var range = range.extend(2, 35);
|
||||
assert.range(range, 2, 5, 2, 35);
|
||||
|
||||
var range = range.extend(2, 15);
|
||||
assert.range(range, 2, 5, 2, 35);
|
||||
|
||||
var range = range.extend(1, 4);
|
||||
assert.range(range, 1, 4, 2, 35);
|
||||
|
||||
var range = range.extend(6, 10);
|
||||
assert.range(range, 1, 4, 6, 10);
|
||||
},
|
||||
|
||||
"test: collapse rows": function () {
|
||||
var range = new AceAjax.Range(0, 2, 1, 2);
|
||||
assert.range(range.collapseRows(), 0, 0, 1, 0);
|
||||
|
||||
var range = new AceAjax.Range(2, 2, 3, 1);
|
||||
assert.range(range.collapseRows(), 2, 0, 3, 0);
|
||||
|
||||
var range = new AceAjax.Range(2, 2, 3, 0);
|
||||
assert.range(range.collapseRows(), 2, 0, 2, 0);
|
||||
|
||||
var range = new AceAjax.Range(2, 0, 2, 0);
|
||||
assert.range(range.collapseRows(), 2, 0, 2, 0);
|
||||
},
|
||||
|
||||
"test: to screen range": function () {
|
||||
var session = new AceAjax.EditSession([
|
||||
"juhu",
|
||||
"12\t\t34",
|
||||
"ぁぁa",
|
||||
"\t\t34",
|
||||
]);
|
||||
|
||||
var range = new AceAjax.Range(0, 0, 0, 3);
|
||||
assert.range(range.toScreenRange(session), 0, 0, 0, 3);
|
||||
|
||||
var range = new AceAjax.Range(1, 1, 1, 3);
|
||||
assert.range(range.toScreenRange(session), 1, 1, 1, 4);
|
||||
|
||||
var range = new AceAjax.Range(2, 1, 2, 2);
|
||||
assert.range(range.toScreenRange(session), 2, 2, 2, 4);
|
||||
|
||||
var range = new AceAjax.Range(3, 0, 3, 4);
|
||||
assert.range(range.toScreenRange(session), 3, 0, 3, 10);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
function flatten(rangeList) {
|
||||
var points = [];
|
||||
rangeList.ranges.forEach(function (r) {
|
||||
points.push(r.start.row, r.start.column, r.end.row, r.end.column)
|
||||
})
|
||||
return points;
|
||||
}
|
||||
function testRangeList(rangeList, points) {
|
||||
assert.equal("" + flatten(rangeList), "" + points);
|
||||
}
|
||||
|
||||
const aceRangeListTests = {
|
||||
|
||||
name: "ACE range_list.js",
|
||||
|
||||
"test: rangeList pointIndex": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.ranges = [
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(8, 8, 9, 9)
|
||||
];
|
||||
|
||||
assert.equal(rangeList.pointIndex({ row: 0, column: 1 }), -1);
|
||||
assert.equal(rangeList.pointIndex({ row: 1, column: 2 }), 0);
|
||||
assert.equal(rangeList.pointIndex({ row: 1, column: 3 }), 0);
|
||||
assert.equal(rangeList.pointIndex({ row: 3, column: 4 }), 0);
|
||||
assert.equal(rangeList.pointIndex({ row: 4, column: 1 }), -2);
|
||||
assert.equal(rangeList.pointIndex({ row: 5, column: 1 }), 1);
|
||||
assert.equal(rangeList.pointIndex({ row: 8, column: 9 }), 2);
|
||||
assert.equal(rangeList.pointIndex({ row: 18, column: 9 }), -4);
|
||||
} ,
|
||||
|
||||
"test: rangeList add": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.addList([
|
||||
new AceAjax.Range(9, 0, 9, 1),
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(8, 8, 9, 9),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(3, 20, 3, 24),
|
||||
new AceAjax.Range(6, 6, 7, 7)
|
||||
]);
|
||||
assert.equal(rangeList.ranges.length, 5);
|
||||
|
||||
rangeList.add(new AceAjax.Range(1, 2, 3, 5));
|
||||
assert.range(rangeList.ranges[0], 1, 2, 3, 5);
|
||||
assert.equal(rangeList.ranges.length, 5);
|
||||
|
||||
rangeList.add(new AceAjax.Range(7, 7, 7, 7));
|
||||
assert.range(rangeList.ranges[3], 7, 7, 7, 7);
|
||||
rangeList.add(new AceAjax.Range(7, 8, 7, 8));
|
||||
assert.range(rangeList.ranges[4], 7, 8, 7, 8);
|
||||
} ,
|
||||
|
||||
"test: rangeList add empty": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.addList([
|
||||
new AceAjax.Range(7, 10, 7, 10),
|
||||
new AceAjax.Range(9, 10, 9, 10),
|
||||
new AceAjax.Range(8, 10, 8, 10)
|
||||
]);
|
||||
assert.equal(rangeList.ranges.length, 3);
|
||||
|
||||
rangeList.add(new AceAjax.Range(9, 10, 9, 10));
|
||||
testRangeList(rangeList, [7, 10, 7, 10, 8, 10, 8, 10, 9, 10, 9, 10]);
|
||||
} ,
|
||||
|
||||
"test: rangeList merge": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.addList([
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(6, 6, 7, 7),
|
||||
new AceAjax.Range(8, 8, 9, 9)
|
||||
]);
|
||||
var removed = [];
|
||||
|
||||
assert.equal(rangeList.ranges.length, 4);
|
||||
|
||||
rangeList.ranges[1].end.row = 7;
|
||||
removed = rangeList.merge();
|
||||
assert.equal(removed.length, 1);
|
||||
assert.range(rangeList.ranges[1], 4, 2, 7, 7);
|
||||
assert.equal(rangeList.ranges.length, 3);
|
||||
|
||||
rangeList.ranges[0].end.row = 10;
|
||||
removed = rangeList.merge();
|
||||
assert.range(rangeList.ranges[0], 1, 2, 10, 4);
|
||||
assert.equal(removed.length, 2);
|
||||
assert.equal(rangeList.ranges.length, 1);
|
||||
|
||||
rangeList.ranges.push(new AceAjax.Range(10, 10, 10, 10));
|
||||
rangeList.ranges.push(new AceAjax.Range(10, 10, 10, 10));
|
||||
removed = rangeList.merge();
|
||||
assert.equal(rangeList.ranges.length, 2);
|
||||
} ,
|
||||
|
||||
"test: rangeList remove": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
var list = [
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(6, 6, 7, 7),
|
||||
new AceAjax.Range(8, 8, 9, 9)
|
||||
];
|
||||
rangeList.addList(list);
|
||||
assert.equal(rangeList.ranges.length, 4);
|
||||
rangeList.substractPoint({ row: 1, column: 2 });
|
||||
assert.equal(rangeList.ranges.length, 3);
|
||||
rangeList.substractPoint({ row: 6, column: 7 });
|
||||
assert.equal(rangeList.ranges.length, 2);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,414 @@
|
||||
const aceSearchTests = {
|
||||
"test: configure the search object": function () {
|
||||
var search = new AceAjax.Search();
|
||||
search.set({
|
||||
needle: "juhu"
|
||||
});
|
||||
},
|
||||
|
||||
"test: find simple text in document": function () {
|
||||
var session = new AceAjax.EditSession(["juhu kinners 123", "456"]);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 12);
|
||||
},
|
||||
|
||||
"test: find simple text in next line": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: find text starting at cursor position": function () {
|
||||
var session = new AceAjax.EditSession(["juhu kinners", "juhu kinners 123"]);
|
||||
session.getSelection().moveCursorTo(0, 6);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: wrap search is on by default": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
assert.notEqual(search.find(session), null);
|
||||
},
|
||||
|
||||
"test: wrap search should wrap at file end": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: wrap search should find needle even if it starts inside it": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(6, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: wrap search with no match should return 'null'": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "xyz",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
assert.equal(search.find(session), null);
|
||||
},
|
||||
|
||||
"test: case sensitive is by default off": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "JUHU"
|
||||
});
|
||||
|
||||
assert.range(search.find(session), 1, 0, 1, 4);
|
||||
},
|
||||
|
||||
"test: case sensitive search": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "KINNERS",
|
||||
caseSensitive: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.equal(range, null);
|
||||
},
|
||||
|
||||
"test: whole word search should not match inside of words": function () {
|
||||
var session = new AceAjax.EditSession(["juhukinners", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners",
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: find backwards": function () {
|
||||
var session = new AceAjax.EditSession(["juhu juhu juhu juhu"]);
|
||||
session.getSelection().moveCursorTo(0, 10);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
backwards: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 9);
|
||||
},
|
||||
|
||||
"test: find in selection": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
session.getSelection().setSelectionAnchor(1, 0);
|
||||
session.getSelection().selectTo(3, 5);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 0);
|
||||
assert.position(range.end, 1, 4);
|
||||
|
||||
search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(3, 2);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 0);
|
||||
assert.position(range.end, 1, 4);
|
||||
},
|
||||
|
||||
"test: find backwards in selection": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(3, 2);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
backwards: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 2, 0);
|
||||
assert.position(range.end, 2, 4);
|
||||
|
||||
search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(1, 2);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 0);
|
||||
assert.position(range.end, 1, 4);
|
||||
},
|
||||
|
||||
"test: edge case - match directly before the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "123", "juhu"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(2, 5);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 2, 0);
|
||||
assert.position(range.end, 2, 4);
|
||||
},
|
||||
|
||||
"test: edge case - match backwards directly after the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "123", "juhu"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
backwards: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(2, 0);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 2, 0);
|
||||
assert.position(range.end, 2, 4);
|
||||
},
|
||||
|
||||
"test: find using a regular expression": function () {
|
||||
var session = new AceAjax.EditSession(["abc123 123 cd", "abc"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "\\d+",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 3);
|
||||
assert.position(range.end, 0, 6);
|
||||
},
|
||||
|
||||
"test: find using a regular expression and whole word": function () {
|
||||
var session = new AceAjax.EditSession(["abc123 123 cd", "abc"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "\\d+\\b",
|
||||
regExp: true,
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 7);
|
||||
assert.position(range.end, 0, 10);
|
||||
},
|
||||
|
||||
"test: use regular expressions with capture groups": function () {
|
||||
var session = new AceAjax.EditSession([" ab: 12px", " <h1 abc"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "(\\d+)",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 6);
|
||||
assert.position(range.end, 0, 8);
|
||||
},
|
||||
|
||||
"test: find all matches in selection": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(3, 2);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "uh",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 2);
|
||||
assert.position(ranges[0].start, 1, 1);
|
||||
assert.position(ranges[0].end, 1, 3);
|
||||
assert.position(ranges[1].start, 2, 1);
|
||||
assert.position(ranges[1].end, 2, 3);
|
||||
},
|
||||
|
||||
|
||||
"test: find all multiline matches": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "hu\nju",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 3);
|
||||
assert.position(ranges[0].start, 0, 2);
|
||||
assert.position(ranges[0].end, 1, 2);
|
||||
assert.position(ranges[1].start, 1, 2);
|
||||
assert.position(ranges[1].end, 2, 2);
|
||||
},
|
||||
|
||||
"test: replace() should return the replacement if the input matches the needle": function () {
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu"
|
||||
});
|
||||
|
||||
assert.equal(search.replace("juhu", "kinners"), "kinners");
|
||||
assert.equal(search.replace("", "kinners"), null);
|
||||
assert.equal(search.replace(" juhu", "kinners"), null);
|
||||
|
||||
// case sensitivity
|
||||
assert.equal(search.replace("Juhu", "kinners"), "kinners");
|
||||
search.set({ caseSensitive: true });
|
||||
assert.equal(search.replace("Juhu", "kinners"), null);
|
||||
|
||||
// regexp replacement
|
||||
},
|
||||
|
||||
"test: replace with a RegExp search": function () {
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "\\d+",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
assert.equal(search.replace("123", "kinners"), "kinners");
|
||||
assert.equal(search.replace("01234", "kinners"), "kinners");
|
||||
assert.equal(search.replace("", "kinners"), null);
|
||||
assert.equal(search.replace("a12", "kinners"), null);
|
||||
assert.equal(search.replace("12a", "kinners"), null);
|
||||
},
|
||||
|
||||
"test: replace with RegExp match and capture groups": function () {
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "ab(\\d\\d)",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
assert.equal(search.replace("ab12", "cd$1"), "cd12");
|
||||
assert.equal(search.replace("ab12", "-$&-"), "-ab12-");
|
||||
assert.equal(search.replace("ab12", "$$"), "$");
|
||||
},
|
||||
|
||||
"test: find all using regular expresion containing $": function () {
|
||||
var session = new AceAjax.EditSession(["a", " b", "c ", "d"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "[ ]+$",
|
||||
regExp: true,
|
||||
wrap: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(1, 2);
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 1);
|
||||
assert.position(ranges[0].start, 2, 1);
|
||||
assert.position(ranges[0].end, 2, 2);
|
||||
},
|
||||
|
||||
"test: find all matches in a line": function () {
|
||||
var session = new AceAjax.EditSession("foo bar foo baz foobar foo");
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "foo",
|
||||
wrap: true,
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(0, 4);
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 3);
|
||||
assert.position(ranges[0].start, 0, 0);
|
||||
assert.position(ranges[0].end, 0, 3);
|
||||
assert.position(ranges[1].start, 0, 8);
|
||||
assert.position(ranges[1].end, 0, 11);
|
||||
assert.position(ranges[2].start, 0, 23);
|
||||
assert.position(ranges[2].end, 0, 26);
|
||||
},
|
||||
|
||||
"test: find all matches in a line backwards": function () {
|
||||
var session = new AceAjax.EditSession("foo bar foo baz foobar foo");
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "foo",
|
||||
wrap: true,
|
||||
wholeWord: true,
|
||||
backwards: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(0, 13);
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 3);
|
||||
assert.position(ranges[2].start, 0, 23);
|
||||
assert.position(ranges[2].end, 0, 26);
|
||||
assert.position(ranges[1].start, 0, 8);
|
||||
assert.position(ranges[1].end, 0, 11);
|
||||
assert.position(ranges[0].start, 0, 0);
|
||||
assert.position(ranges[0].end, 0, 3);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,409 @@
|
||||
const aceSelectionTests = {
|
||||
createSession: function (rows, cols) {
|
||||
var line = new Array(cols + 1).join("a");
|
||||
var text = new Array(rows).join(line + "\n") + line;
|
||||
return new AceAjax.EditSession(text);
|
||||
},
|
||||
|
||||
"test: move cursor to end of file should place the cursor on last row and column": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorFileEnd();
|
||||
assert.position(selection.getCursor(), 199, 10);
|
||||
},
|
||||
|
||||
"test: moveCursor to start of file should place the cursor on the first row and column": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorFileStart();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: move selection lead to end of file": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileEnd();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 100, 5);
|
||||
assert.position(range.end, 199, 10);
|
||||
},
|
||||
|
||||
"test: move selection lead to start of file": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileStart();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 100, 5);
|
||||
},
|
||||
|
||||
"test: move cursor word right": function () {
|
||||
var session = new AceAjax.EditSession([
|
||||
"ab",
|
||||
" Juhu Kinners (abc, 12)",
|
||||
" cde"
|
||||
].join("\n"));
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
assert.position(selection.getCursor(), 1, 0);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 5);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 13);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 18);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 22);
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 2, 4);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 2, 4);
|
||||
},
|
||||
|
||||
"test: select word right if cursor in word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 2);
|
||||
selection.moveCursorWordRight();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 4);
|
||||
},
|
||||
|
||||
"test: moveCursor word left": function () {
|
||||
var session = new AceAjax.EditSession([
|
||||
"ab",
|
||||
" Juhu Kinners (abc, 12)",
|
||||
" cde"
|
||||
].join("\n"));
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
selection.moveCursorLineEnd();
|
||||
assert.position(selection.getCursor(), 1, 23);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 20);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 15);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 6);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 1);
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: moveCursor word left with umlauts": function () {
|
||||
var session = new AceAjax.EditSession(" Fu� F��e");
|
||||
|
||||
var selection = session.getSelection();
|
||||
selection.moveCursorTo(0, 9)
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 5);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 1);
|
||||
},
|
||||
|
||||
"test: select word left if cursor in word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 5);
|
||||
},
|
||||
|
||||
"test: select word right and select": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 0);
|
||||
selection.selectWordRight();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 0, 4);
|
||||
},
|
||||
|
||||
"test: select word left and select": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 3);
|
||||
selection.selectWordLeft();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 0, 3);
|
||||
},
|
||||
|
||||
"test: select word with cursor in word should select the word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners 123");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 12);
|
||||
},
|
||||
|
||||
"test: select word with cursor in word including right whitespace should select the word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners 123");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
selection.selectAWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 18);
|
||||
},
|
||||
|
||||
"test: select word with cursor betwen white space and word should select the word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 0, 4);
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 12);
|
||||
},
|
||||
|
||||
"test: select word with cursor in white space should select white space": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 4);
|
||||
assert.position(range.end, 0, 6);
|
||||
},
|
||||
|
||||
"test: moving cursor should fire a 'changeCursor' event": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
|
||||
var called = false;
|
||||
selection.addEventListener("changeCursor", function () {
|
||||
called = true;
|
||||
});
|
||||
|
||||
selection.moveCursorTo(0, 6);
|
||||
assert.ok(called);
|
||||
},
|
||||
|
||||
"test: calling setCursor with the same position should not fire an event": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
|
||||
var called = false;
|
||||
selection.addEventListener("changeCursor", function () {
|
||||
called = true;
|
||||
});
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
assert.notOk(called);
|
||||
},
|
||||
|
||||
"test: moveWordright should move past || and [": function () {
|
||||
var session = new AceAjax.EditSession("||foo[");
|
||||
var selection = session.getSelection();
|
||||
|
||||
// Move behind ||foo
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 0, 5);
|
||||
|
||||
// Move behind [
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 0, 6);
|
||||
},
|
||||
|
||||
"test: moveWordLeft should move past || and [": function () {
|
||||
var session = new AceAjax.EditSession("||foo[");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 6);
|
||||
|
||||
// Move behind [foo
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 2);
|
||||
|
||||
// Move behind ||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: move cursor to line start should move cursor to end of the indentation first": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 6);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
"test: move cursor to line start when the cursor is at the end of the indentation should move cursor to column 0": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 4);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 0);
|
||||
},
|
||||
|
||||
"test: move cursor to line start when the cursor is at column 0 should move cursor to the end of the indentation": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 0);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
// Eclipse style
|
||||
"test: move cursor to line start when the cursor is before the initial indentation should move cursor to the end of the indentation": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 2);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
"test go line up when in the middle of the first line should go to document start": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.moveCursorUp();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: (wrap) go line up when in the middle of the first line should go to document start": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
session.setWrapLimitRange(5, 5);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.moveCursorUp();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
|
||||
"test go line down when in the middle of the last line should go to document end": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 12);
|
||||
},
|
||||
|
||||
"test (wrap) go line down when in the middle of the last line should go to document end": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
session.setWrapLimitRange(8, 8);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 10);
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 12);
|
||||
},
|
||||
|
||||
"test go line up twice and then once down when in the second should go back to the previous column": function () {
|
||||
var session = new AceAjax.EditSession("juhu\nkinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 4);
|
||||
selection.moveCursorUp();
|
||||
selection.moveCursorUp();
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
"test (keyboard navigation) when curLine is not EOL and targetLine is all whitespace new column should be current column": function () {
|
||||
var session = new AceAjax.EditSession("function (a) {\n\
|
||||
\n\
|
||||
}");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(2, 0);
|
||||
selection.moveCursorUp();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 0);
|
||||
},
|
||||
|
||||
"test (keyboard navigation) when curLine is EOL and targetLine is shorter dan current column, new column should be targetLine's EOL": function () {
|
||||
var session = new AceAjax.EditSession("function (a) {\n\
|
||||
\n\
|
||||
}");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,164 @@
|
||||
const aceTokenIteratorTests = {
|
||||
"test: token iterator initialization in JavaScript document": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
assert.equal(iterator.getCurrentToken().value, "function");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
iterator.stepForward();
|
||||
assert.equal(iterator.getCurrentToken().value, " ");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 8);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 4);
|
||||
assert.equal(iterator.getCurrentToken().value, "function");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
iterator.stepForward();
|
||||
assert.equal(iterator.getCurrentToken().value, " ");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 8);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 2, 18);
|
||||
assert.equal(iterator.getCurrentToken().value, "items");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 2);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 14);
|
||||
|
||||
iterator.stepForward();
|
||||
assert.equal(iterator.getCurrentToken().value, "[");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 2);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 19);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 4, 0);
|
||||
assert.equal(iterator.getCurrentToken().value, "}");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 4);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
iterator.stepBackward();
|
||||
assert.equal(iterator.getCurrentToken().value, "// Real Tab.");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 3);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 6);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 5, 0);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator initialization in text document": function () {
|
||||
var lines = [
|
||||
"Lorem ipsum dolor sit amet, consectetur adipisicing elit,",
|
||||
"sed do eiusmod tempor incididunt ut labore et dolore magna",
|
||||
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation",
|
||||
"ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"));
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[0]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 4);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[0]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 2, 18);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[2]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 2);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 3, lines[3].length - 1);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[3]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 3);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 4, 0);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator step forward in JavaScript document": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var tokens = [];
|
||||
var len = session.getLength();
|
||||
for (var i = 0; i < len; i++)
|
||||
tokens = tokens.concat(session.getTokens(i));
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
for (var i = 1; i < tokens.length; i++)
|
||||
assert.equal(iterator.stepForward(), tokens[i]);
|
||||
assert.equal(iterator.stepForward(), null);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator step backward in JavaScript document": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var tokens = [];
|
||||
var len = session.getLength();
|
||||
for (var i = 0; i < len; i++)
|
||||
tokens = tokens.concat(session.getTokens(i));
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 4, 0);
|
||||
for (var i = tokens.length - 2; i >= 0; i--)
|
||||
assert.equal(iterator.stepBackward(), tokens[i]);
|
||||
assert.equal(iterator.stepBackward(), null);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator reports correct row and column": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
|
||||
assert.equal(iterator.getCurrentToken().value, "foo");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 9);
|
||||
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
|
||||
assert.equal(iterator.getCurrentToken().value, "for");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 1);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 4);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
const aceVirtualRendererTests = {
|
||||
"test: screen2text the column should be rounded to the next character edge": function () {
|
||||
var el = document.createElement("div");
|
||||
|
||||
if (!el.getBoundingClientRect) {
|
||||
console.log("Skipping test: This test only runs in the browser");
|
||||
return;
|
||||
}
|
||||
|
||||
el.style.left = "20px";
|
||||
el.style.top = "30px";
|
||||
el.style.width = "300px";
|
||||
el.style.height = "100px";
|
||||
document.body.appendChild(el);
|
||||
|
||||
var renderer = new AceAjax.VirtualRenderer(el);
|
||||
renderer.setPadding(0);
|
||||
renderer.setSession(new AceAjax.EditSession("1234"));
|
||||
|
||||
var r = renderer.scroller.getBoundingClientRect();
|
||||
function testPixelToText(x, y, row, column) {
|
||||
assert.position(renderer.screenToTextCoordinates(x + r.left, y + r.top), row, column);
|
||||
}
|
||||
|
||||
renderer.characterWidth = 10;
|
||||
renderer.lineHeight = 15;
|
||||
|
||||
testPixelToText(4, 0, 0, 0);
|
||||
testPixelToText(5, 0, 0, 1);
|
||||
testPixelToText(9, 0, 0, 1);
|
||||
testPixelToText(10, 0, 0, 1);
|
||||
testPixelToText(14, 0, 0, 1);
|
||||
testPixelToText(15, 0, 0, 2);
|
||||
document.body.removeChild(el);
|
||||
}
|
||||
|
||||
// change tab size after setDocument (for text layer)
|
||||
};
|
||||
@@ -1,132 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var exports = {
|
||||
|
||||
"test create anchor" : function() {
|
||||
var doc = new AceAjax.Document("juhu");
|
||||
var anchor = new AceAjax.Anchor(doc, 0, 0);
|
||||
|
||||
assert.position(anchor.getPosition(), 0, 0);
|
||||
assert.equal(anchor.getDocument(), doc);
|
||||
},
|
||||
|
||||
"test insert text in same row before cursor should move anchor column": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insert({row: 1, column: 1}, "123");
|
||||
assert.position(anchor.getPosition(), 1, 7);
|
||||
},
|
||||
|
||||
"test insert lines before cursor should move anchor row": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insertLines(1, ["123", "456"]);
|
||||
assert.position(anchor.getPosition(), 3, 4);
|
||||
},
|
||||
|
||||
"test insert new line before cursor should move anchor column": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insertNewLine({row: 0, column: 0});
|
||||
assert.position(anchor.getPosition(), 2, 4);
|
||||
},
|
||||
|
||||
"test insert new line in anchor line before anchor should move anchor column and row": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.insertNewLine({row: 1, column: 2});
|
||||
assert.position(anchor.getPosition(), 2, 2);
|
||||
},
|
||||
|
||||
"test delete text in anchor line before anchor should move anchor column": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 1, 1, 3));
|
||||
assert.position(anchor.getPosition(), 1, 2);
|
||||
},
|
||||
|
||||
"test remove range which contains the anchor should move the anchor to the start of the range": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 0, 3);
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 1, 1, 3));
|
||||
assert.position(anchor.getPosition(), 0, 1);
|
||||
},
|
||||
|
||||
"test delete character before the anchor should have no effect": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 4, 1, 5));
|
||||
assert.position(anchor.getPosition(), 1, 4);
|
||||
},
|
||||
|
||||
"test delete lines in anchor line before anchor should move anchor row": function() {
|
||||
var doc = new AceAjax.Document("juhu\n1\n2\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 3, 4);
|
||||
|
||||
doc.removeLines(1, 2);
|
||||
assert.position(anchor.getPosition(), 1, 4);
|
||||
},
|
||||
|
||||
"test remove new line before the cursor": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.removeNewLine(0);
|
||||
assert.position(anchor.getPosition(), 0, 8);
|
||||
},
|
||||
|
||||
"test delete range which contains the anchor should move anchor to the end of the range": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 4);
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 2, 1, 2));
|
||||
assert.position(anchor.getPosition(), 0, 4);
|
||||
},
|
||||
|
||||
"test delete line which contains the anchor should move anchor to the end of the range": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 5);
|
||||
|
||||
doc.removeLines(1, 1);
|
||||
assert.position(anchor.getPosition(), 1, 0);
|
||||
},
|
||||
|
||||
"test remove after the anchor should have no effect": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 2);
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 4, 2, 2));
|
||||
assert.position(anchor.getPosition(), 1, 2);
|
||||
},
|
||||
|
||||
"test anchor changes triggered by document changes should emit change event": function(next) {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 5);
|
||||
|
||||
anchor.on("change", function(e) {
|
||||
assert.position(anchor.getPosition(), 0, 0);
|
||||
next();
|
||||
});
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 0, 2, 1));
|
||||
},
|
||||
|
||||
"test only fire change event if position changes": function() {
|
||||
var doc = new AceAjax.Document("juhu\nkinners\n123");
|
||||
var anchor = new AceAjax.Anchor(doc, 1, 5);
|
||||
|
||||
anchor.on("change", function(e) {
|
||||
assert.fail();
|
||||
});
|
||||
|
||||
doc.remove(new AceAjax.Range(2, 0, 2, 1));
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
|
||||
function forceTokenize(session) {
|
||||
for (var i = 0, l = session.getLength(); i < l; i++)
|
||||
session.getTokens(i)
|
||||
}
|
||||
|
||||
function testStates(session, states) {
|
||||
for (var i = 0, l = session.getLength(); i < l; i++)
|
||||
assert.equal(session.bgTokenizer.states[i], states[i])
|
||||
assert.ok(l == states.length)
|
||||
}
|
||||
|
||||
var exports = {
|
||||
|
||||
"test background tokenizer update on session change": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"/*",
|
||||
"*/",
|
||||
"var juhu"
|
||||
]);
|
||||
doc.setMode("./mode/javascript")
|
||||
|
||||
forceTokenize(doc)
|
||||
testStates(doc, ["comment", "start", "start"])
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 2, 1, 2))
|
||||
testStates(doc, [null, "start"])
|
||||
|
||||
forceTokenize(doc)
|
||||
testStates(doc, ["comment", "comment"])
|
||||
|
||||
doc.insert({ row: 0, column: 2 }, "\n*/")
|
||||
testStates(doc, [undefined, undefined, "comment"])
|
||||
|
||||
forceTokenize(doc)
|
||||
testStates(doc, ["comment", "start", "start"])
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,451 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var editor = ace.edit("editor");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.getSession().setMode("ace/mode/javascript");
|
||||
|
||||
editor.setTheme("ace/theme/twilight");
|
||||
|
||||
editor.getSession().setMode("ace/mode/javascript");
|
||||
|
||||
editor.setValue("the new text here"); // or session.setValue
|
||||
editor.getValue(); // or session.getValue
|
||||
|
||||
editor.session.getTextRange(editor.getSelectionRange());
|
||||
|
||||
editor.insert("Something cool");
|
||||
|
||||
editor.selection.getCursor();
|
||||
|
||||
editor.gotoLine(123);
|
||||
|
||||
editor.session.getLength();
|
||||
|
||||
editor.getSession().setTabSize(4);
|
||||
|
||||
editor.getSession().setUseSoftTabs(true);
|
||||
|
||||
document.getElementById('editor').style.fontSize = '12px';
|
||||
|
||||
editor.getSession().setUseWrapMode(true);
|
||||
|
||||
editor.setHighlightActiveLine(false);
|
||||
|
||||
editor.setShowPrintMargin(false);
|
||||
|
||||
editor.setReadOnly(true); // false to make it editable
|
||||
|
||||
editor.resize()
|
||||
|
||||
editor.find('needle', {
|
||||
backwards: false,
|
||||
wrap: false,
|
||||
caseSensitive: false,
|
||||
wholeWord: false,
|
||||
regExp: false
|
||||
});
|
||||
editor.findNext();
|
||||
editor.findPrevious();
|
||||
|
||||
editor.find('foo');
|
||||
editor.replace('bar');
|
||||
|
||||
editor.replaceAll('bar');
|
||||
|
||||
editor.getSession().on('change', function (e) {
|
||||
// e.type, etc
|
||||
});
|
||||
|
||||
editor.getSession().selection.on('changeSelection', function (e) {
|
||||
});
|
||||
|
||||
editor.getSession().selection.on('changeCursor', function (e) {
|
||||
});
|
||||
|
||||
editor.commands.addCommand({
|
||||
name: 'myCommand',
|
||||
bindKey: { win: 'Ctrl-M', mac: 'Command-M' },
|
||||
exec: function (editor) {
|
||||
//...
|
||||
},
|
||||
readOnly: true // false if this command should not apply in readOnly mode
|
||||
});
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.moveCursorTo(3, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.onTextInput("\n");
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent();
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.removeLines();
|
||||
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", "d"].join("\n"));
|
||||
|
||||
assert.equal(session.toString(), "a\nc\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a");
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "b\nc");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(3, 0);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb\nc");
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb");
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
assert.equal(["a12345", " b12345", " c12345"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 7);
|
||||
|
||||
range = editor.getSelectionRange();
|
||||
assert.position(range.start, 1, 7);
|
||||
assert.position(range.end, 2, 7);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
assert.equal(["a12345", " b12345", "c12345"].join("\n"), session.toString());
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.onTextInput("\n");
|
||||
assert.equal(["", "{"].join("\n"), session.toString());
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), [" a12345", "b12345", " c12345"].join("\n"));
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 1);
|
||||
assert.position(range.end, 2, 1);
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), ["a12345", "b12345", "c12345"].join("\n"));
|
||||
|
||||
range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 2, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.blockOutdent(" ");
|
||||
|
||||
assert.equal(session.toString(), " 12");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.getSelection().selectDown();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal(["// abc", "//cde"].join("\n"), session.toString());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assert.position(selection.start, 0, 4);
|
||||
assert.position(selection.end, 1, 4);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectRight();
|
||||
editor.getSelection().selectRight();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde"].join("\n"), session.toString());
|
||||
assert.range(editor.getSelectionRange(), 0, 0, 1, 1);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectUp();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "11", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
|
||||
// moving again should have no effect
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(2, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["11", "33", "44", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["33", "44", "11", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["11", "33", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(["11", "22", "33", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesDown();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 5, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 3, 0);
|
||||
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesUp();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
|
||||
session.setTabSize(2);
|
||||
session.setUseSoftTabs(true);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
|
||||
session.setTabSize(5);
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
|
||||
|
||||
session.setUseSoftTabs(false);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), "\t");
|
||||
|
||||
editor.removeLines();
|
||||
var step1 = session.toString();
|
||||
assert.equal(step1, "222\n333");
|
||||
|
||||
editor.removeLines();
|
||||
var step2 = session.toString();
|
||||
assert.equal(step2, "333");
|
||||
|
||||
editor.removeLines();
|
||||
var step3 = session.toString();
|
||||
assert.equal(step3, "");
|
||||
|
||||
var undoManager = new AceAjax.UndoManager();
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step2);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step1);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), "");
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), "");
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n56");
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123456");
|
||||
|
||||
session.setUseSoftTabs(true);
|
||||
session.setTabSize(4);
|
||||
|
||||
editor.moveCursorTo(1, 8);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n 456");
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4657", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4576", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectRight();
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
assert.position(editor.getCursorPosition(), 1, 3);
|
||||
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.removeToLineEnd();
|
||||
assert.equal(session.getValue(), ["123", "45", "89"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.removeToLineEnd();
|
||||
assert.position(editor.getCursorPosition(), 1, 4);
|
||||
assert.equal(session.getValue(), ["123", "456789"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,255 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var exports = {
|
||||
"test: insert text in line": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 0, column: 1 }, "juhu");
|
||||
assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1juhu2", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert new line": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertNewLine({ row: 0, column: 1 });
|
||||
assert.equal(doc.getValue(), ["1", "2", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1", "2", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert lines at the beginning": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertLines(0, ["aa", "bb"]);
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "12", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert lines at the end": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertLines(2, ["aa", "bb"]);
|
||||
assert.equal(doc.getValue(), ["12", "34", "aa", "bb"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert lines in the middle": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insertLines(1, ["aa", "bb"]);
|
||||
assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "aa", "bb", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert multi line string at the start": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 0, column: 0 }, "aa\nbb\ncc");
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["aa", "bb", "cc12", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert multi line string at the end": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 2, column: 0 }, "aa\nbb\ncc");
|
||||
assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34aa", "bb", "cc"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: insert multi line string in the middle": function() {
|
||||
var doc = new AceAjax.Document(["12", "34"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.insert({ row: 0, column: 1 }, "aa\nbb\ncc");
|
||||
assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12", "34"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1aa", "bb", "cc2", "34"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete in line": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 1, 0, 3));
|
||||
assert.equal(doc.getValue(), ["14", "5678"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1234", "5678"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["14", "5678"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete new line": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 4, 1, 0));
|
||||
assert.equal(doc.getValue(), ["12345678"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1234", "5678"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12345678"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete multi line range line": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678", "abcd"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(0, 2, 2, 2));
|
||||
assert.equal(doc.getValue(), ["12cd"].join("\n"));
|
||||
|
||||
var d = deltas.concat();
|
||||
doc.revertDeltas(d);
|
||||
assert.equal(doc.getValue(), ["1234", "5678", "abcd"].join("\n"));
|
||||
|
||||
doc.applyDeltas(d);
|
||||
assert.equal(doc.getValue(), ["12cd"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: delete full lines": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678", "abcd"]);
|
||||
|
||||
var deltas = [];
|
||||
doc.on("change", function (e) { deltas.push(e.data); });
|
||||
|
||||
doc.remove(new AceAjax.Range(1, 0, 3, 0));
|
||||
assert.equal(doc.getValue(), ["1234", ""].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: remove lines should return the removed lines": function() {
|
||||
var doc = new AceAjax.Document(["1234", "5678", "abcd"]);
|
||||
|
||||
var removed = doc.removeLines(1, 2);
|
||||
assert.equal(removed.join("\n"), ["5678", "abcd"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: should handle unix style new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"]);
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: should handle windows style new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.setNewLineMode("unix");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: set new line mode to 'windows' should use '\\r\\n' as new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\n"));
|
||||
doc.setNewLineMode("windows");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\r\n"));
|
||||
} ,
|
||||
|
||||
"test: set new line mode to 'unix' should use '\\n' as new lines": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.setNewLineMode("unix");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: set new line mode to 'auto' should detect the incoming nl type": function() {
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\n"));
|
||||
|
||||
doc.setNewLineMode("auto");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\n"));
|
||||
|
||||
var doc = new AceAjax.Document(["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.setNewLineMode("auto");
|
||||
assert.equal(doc.getValue(), ["1", "2", "3"].join("\r\n"));
|
||||
|
||||
doc.replace(new AceAjax.Range(0, 0, 2, 1), ["4", "5", "6"].join("\n"));
|
||||
assert.equal(["4", "5", "6"].join("\n"), doc.getValue());
|
||||
} ,
|
||||
|
||||
"test: set value": function() {
|
||||
var doc = new AceAjax.Document("1");
|
||||
assert.equal("1", doc.getValue());
|
||||
|
||||
doc.setValue(doc.getValue());
|
||||
assert.equal("1", doc.getValue());
|
||||
|
||||
var doc = new AceAjax.Document("1\n2");
|
||||
assert.equal("1\n2", doc.getValue());
|
||||
|
||||
doc.setValue(doc.getValue());
|
||||
assert.equal("1\n2", doc.getValue());
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,920 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var lang: any;
|
||||
var assert: any;
|
||||
|
||||
function createFoldTestSession() {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"));
|
||||
session.setUndoManager(new AceAjax.UndoManager());
|
||||
session.addFold("args...", new AceAjax.Range(0, 13, 0, 18));
|
||||
session.addFold("foo...", new AceAjax.Range(1, 10, 2, 10));
|
||||
session.addFold("bar...", new AceAjax.Range(2, 20, 2, 25));
|
||||
return session;
|
||||
}
|
||||
|
||||
function assertArray(a, b) {
|
||||
assert.equal(a + "", b + "");
|
||||
assert.ok(a.length == b.length);
|
||||
for (var i = 0; i < a.length; i++) {
|
||||
assert.equal(a[i], b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var exports = {
|
||||
|
||||
"test: find matching opening bracket in Text mode": function() {
|
||||
var session = new AceAjax.EditSession(["(()(", "())))"]);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 3 }), 0, 1);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 2 }), 1, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 3 }), 0, 3);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 4 }), 0, 0);
|
||||
assert.equal(session.findMatchingBracket({ row: 1, column: 5 }), null);
|
||||
} ,
|
||||
|
||||
"test: find matching closing bracket in Text mode": function() {
|
||||
var session = new AceAjax.EditSession(["(()(", "())))"]);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 1 }), 1, 1);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 1 }), 1, 1);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 4 }), 1, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 2 }), 0, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 1 }), 1, 3);
|
||||
assert.equal(session.findMatchingBracket({ row: 0, column: 0 }), null);
|
||||
} ,
|
||||
|
||||
"test: find matching opening bracket in JavaScript mode": function() {
|
||||
var lines = [
|
||||
"function foo() {",
|
||||
" var str = \"{ foo()\";",
|
||||
" if (debug) {",
|
||||
" // write str (a string) to the console",
|
||||
" console.log(str);",
|
||||
" }",
|
||||
" str += \" bar() }\";",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"), null);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 14 }), 0, 12);
|
||||
assert.position(session.findMatchingBracket({ row: 7, column: 1 }), 0, 15);
|
||||
assert.position(session.findMatchingBracket({ row: 6, column: 20 }), 1, 15);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 22 }), 1, 20);
|
||||
assert.position(session.findMatchingBracket({ row: 3, column: 31 }), 3, 21);
|
||||
assert.position(session.findMatchingBracket({ row: 4, column: 24 }), 4, 19);
|
||||
assert.equal(session.findMatchingBracket({ row: 0, column: 1 }), null);
|
||||
} ,
|
||||
|
||||
"test: find matching closing bracket in JavaScript mode": function() {
|
||||
var lines = [
|
||||
"function foo() {",
|
||||
" var str = \"{ foo()\";",
|
||||
" if (debug) {",
|
||||
" // write str (a string) to the console",
|
||||
" console.log(str);",
|
||||
" }",
|
||||
" str += \" bar() }\";",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"), null);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 13 }), 0, 13);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 16 }), 7, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 16 }), 6, 19);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 21 }), 1, 21);
|
||||
assert.position(session.findMatchingBracket({ row: 3, column: 22 }), 3, 30);
|
||||
assert.position(session.findMatchingBracket({ row: 4, column: 20 }), 4, 23);
|
||||
} ,
|
||||
|
||||
"test: handle unbalanced brackets in JavaScript mode": function() {
|
||||
var lines = [
|
||||
"function foo() {",
|
||||
" var str = \"{ foo()\";",
|
||||
" if (debug) {",
|
||||
" // write str a string) to the console",
|
||||
" console.log(str);",
|
||||
" ",
|
||||
" str += \" bar() \";",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"), null);
|
||||
|
||||
assert.equal(session.findMatchingBracket({ row: 0, column: 16 }), null);
|
||||
assert.equal(session.findMatchingBracket({ row: 3, column: 30 }), null);
|
||||
assert.equal(session.findMatchingBracket({ row: 1, column: 16 }), null);
|
||||
} ,
|
||||
|
||||
"test: match different bracket types": function() {
|
||||
var session = new AceAjax.EditSession(["({[", ")]}"]);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 1 }), 1, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 2 }), 1, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 0, column: 3 }), 1, 1);
|
||||
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 1 }), 0, 0);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 2 }), 0, 2);
|
||||
assert.position(session.findMatchingBracket({ row: 1, column: 3 }), 0, 1);
|
||||
} ,
|
||||
|
||||
"test: move lines down": function() {
|
||||
var session = new AceAjax.EditSession(["a1", "a2", "a3", "a4"]);
|
||||
|
||||
session.moveLinesDown(0, 1);
|
||||
assert.equal(session.getValue(), ["a3", "a1", "a2", "a4"].join("\n"));
|
||||
|
||||
session.moveLinesDown(1, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesDown(2, 3);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesDown(2, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a2", "a1"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: move lines up": function() {
|
||||
var session = new AceAjax.EditSession(["a1", "a2", "a3", "a4"]);
|
||||
|
||||
session.moveLinesUp(2, 3);
|
||||
assert.equal(session.getValue(), ["a1", "a3", "a4", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesUp(1, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesUp(0, 1);
|
||||
assert.equal(session.getValue(), ["a3", "a4", "a1", "a2"].join("\n"));
|
||||
|
||||
session.moveLinesUp(2, 2);
|
||||
assert.equal(session.getValue(), ["a3", "a1", "a4", "a2"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: duplicate lines": function() {
|
||||
var session = new AceAjax.EditSession(["1", "2", "3", "4"]);
|
||||
|
||||
session.duplicateLines(1, 2);
|
||||
assert.equal(session.getValue(), ["1", "2", "3", "2", "3", "4"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: duplicate last line": function() {
|
||||
var session = new AceAjax.EditSession(["1", "2", "3"]);
|
||||
|
||||
session.duplicateLines(2, 2);
|
||||
assert.equal(session.getValue(), ["1", "2", "3", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: duplicate first line": function() {
|
||||
var session = new AceAjax.EditSession(["1", "2", "3"]);
|
||||
|
||||
session.duplicateLines(0, 0);
|
||||
assert.equal(session.getValue(), ["1", "1", "2", "3"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test: getScreenLastRowColumn": function() {
|
||||
var session = new AceAjax.EditSession([
|
||||
"juhu",
|
||||
"12\t\t34",
|
||||
"??a"
|
||||
]);
|
||||
|
||||
assert.equal(session.getScreenLastRowColumn(0), 4);
|
||||
assert.equal(session.getScreenLastRowColumn(1), 10);
|
||||
assert.equal(session.getScreenLastRowColumn(2), 5);
|
||||
} ,
|
||||
|
||||
"test: convert document to screen coordinates": function() {
|
||||
var session = new AceAjax.EditSession("01234\t567890\t1234");
|
||||
session.setTabSize(4);
|
||||
|
||||
assert.equal(session.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(session.documentToScreenColumn(0, 4), 4);
|
||||
assert.equal(session.documentToScreenColumn(0, 5), 5);
|
||||
assert.equal(session.documentToScreenColumn(0, 6), 8);
|
||||
assert.equal(session.documentToScreenColumn(0, 12), 14);
|
||||
assert.equal(session.documentToScreenColumn(0, 13), 16);
|
||||
|
||||
session.setTabSize(2);
|
||||
|
||||
assert.equal(session.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(session.documentToScreenColumn(0, 4), 4);
|
||||
assert.equal(session.documentToScreenColumn(0, 5), 5);
|
||||
assert.equal(session.documentToScreenColumn(0, 6), 6);
|
||||
assert.equal(session.documentToScreenColumn(0, 7), 7);
|
||||
assert.equal(session.documentToScreenColumn(0, 12), 12);
|
||||
assert.equal(session.documentToScreenColumn(0, 13), 14);
|
||||
} ,
|
||||
|
||||
"test: convert document to screen coordinates with leading tabs": function() {
|
||||
var session = new AceAjax.EditSession("\t\t123");
|
||||
session.setTabSize(4);
|
||||
|
||||
assert.equal(session.documentToScreenColumn(0, 0), 0);
|
||||
assert.equal(session.documentToScreenColumn(0, 1), 4);
|
||||
assert.equal(session.documentToScreenColumn(0, 2), 8);
|
||||
assert.equal(session.documentToScreenColumn(0, 3), 9);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen without soft wrap": function() {
|
||||
var session = new AceAjax.EditSession([
|
||||
"juhu",
|
||||
"12\t\t34",
|
||||
"??a"
|
||||
]);
|
||||
|
||||
assert.position(session.documentToScreenPosition(0, 3), 0, 3);
|
||||
assert.position(session.documentToScreenPosition(1, 3), 1, 4);
|
||||
assert.position(session.documentToScreenPosition(1, 4), 1, 8);
|
||||
assert.position(session.documentToScreenPosition(2, 2), 2, 4);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen with soft wrap": function() {
|
||||
var session = new AceAjax.EditSession(["foo bar foo bar"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(12, 12);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.documentToScreenPosition(0, 11), 0, 11);
|
||||
assert.position(session.documentToScreenPosition(0, 12), 1, 0);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen with soft wrap and multibyte characters": function() {
|
||||
var session = new AceAjax.EditSession(["??a"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(2, 2);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.documentToScreenPosition(0, 1), 1, 0);
|
||||
assert.position(session.documentToScreenPosition(0, 2), 2, 0);
|
||||
assert.position(session.documentToScreenPosition(0, 4), 2, 1);
|
||||
} ,
|
||||
|
||||
"test: documentToScreen should clip position to the document boundaries": function() {
|
||||
var session = new AceAjax.EditSession("foo bar\njuhu kinners");
|
||||
|
||||
assert.position(session.documentToScreenPosition(-1, 4), 0, 0);
|
||||
assert.position(session.documentToScreenPosition(3, 0), 1, 12);
|
||||
} ,
|
||||
|
||||
"test: convert screen to document coordinates": function() {
|
||||
var session = new AceAjax.EditSession("01234\t567890\t1234");
|
||||
session.setTabSize(4);
|
||||
|
||||
assert.equal(session.screenToDocumentColumn(0, 0), 0);
|
||||
assert.equal(session.screenToDocumentColumn(0, 4), 4);
|
||||
assert.equal(session.screenToDocumentColumn(0, 5), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 6), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 7), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 8), 6);
|
||||
assert.equal(session.screenToDocumentColumn(0, 9), 7);
|
||||
assert.equal(session.screenToDocumentColumn(0, 15), 12);
|
||||
assert.equal(session.screenToDocumentColumn(0, 19), 16);
|
||||
|
||||
session.setTabSize(2);
|
||||
|
||||
assert.equal(session.screenToDocumentColumn(0, 0), 0);
|
||||
assert.equal(session.screenToDocumentColumn(0, 4), 4);
|
||||
assert.equal(session.screenToDocumentColumn(0, 5), 5);
|
||||
assert.equal(session.screenToDocumentColumn(0, 6), 6);
|
||||
assert.equal(session.screenToDocumentColumn(0, 12), 12);
|
||||
assert.equal(session.screenToDocumentColumn(0, 13), 12);
|
||||
assert.equal(session.screenToDocumentColumn(0, 14), 13);
|
||||
} ,
|
||||
|
||||
"test: screenToDocument with soft wrap": function() {
|
||||
var session = new AceAjax.EditSession(["foo bar foo bar"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(12, 12);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.screenToDocumentPosition(1, 0), 0, 12);
|
||||
assert.position(session.screenToDocumentPosition(0, 11), 0, 11);
|
||||
// Check if the position is clamped the right way.
|
||||
assert.position(session.screenToDocumentPosition(0, 12), 0, 11);
|
||||
assert.position(session.screenToDocumentPosition(0, 20), 0, 11);
|
||||
} ,
|
||||
|
||||
"test: screenToDocument with soft wrap and multi byte characters": function() {
|
||||
var session = new AceAjax.EditSession(["? a"]);
|
||||
session.setUseWrapMode(true);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
assert.position(session.screenToDocumentPosition(0, 1), 0, 0);
|
||||
assert.position(session.screenToDocumentPosition(0, 2), 0, 1);
|
||||
assert.position(session.screenToDocumentPosition(0, 3), 0, 2);
|
||||
assert.position(session.screenToDocumentPosition(0, 4), 0, 3);
|
||||
assert.position(session.screenToDocumentPosition(0, 5), 0, 3);
|
||||
} ,
|
||||
|
||||
"test: screenToDocument should clip position to the document boundaries": function() {
|
||||
var session = new AceAjax.EditSession("foo bar\njuhu kinners");
|
||||
|
||||
assert.position(session.screenToDocumentPosition(-1, 4), 0, 0);
|
||||
assert.position(session.screenToDocumentPosition(0, -1), 0, 0);
|
||||
assert.position(session.screenToDocumentPosition(0, 30), 0, 7);
|
||||
assert.position(session.screenToDocumentPosition(2, 4), 1, 12);
|
||||
assert.position(session.screenToDocumentPosition(1, 30), 1, 12);
|
||||
assert.position(session.screenToDocumentPosition(20, 50), 1, 12);
|
||||
assert.position(session.screenToDocumentPosition(20, 5), 1, 12);
|
||||
|
||||
// and the same for folded rows
|
||||
session.addFold("...", new AceAjax.Range(0, 1, 1, 3));
|
||||
assert.position(session.screenToDocumentPosition(1, 2), 1, 12);
|
||||
// for wrapped rows
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(5, 5);
|
||||
assert.position(session.screenToDocumentPosition(4, 1), 1, 12);
|
||||
} ,
|
||||
|
||||
"test: wrapLine split function": function() {
|
||||
function computeAndAssert(line, assertEqual, wrapLimit?, tabSize?) {
|
||||
wrapLimit = wrapLimit || 12;
|
||||
tabSize = tabSize || 4;
|
||||
line = lang.stringTrimRight(line);
|
||||
var tokens = AceAjax.EditSession.prototype.$getDisplayTokens(line);
|
||||
var splits = AceAjax.EditSession.prototype.$computeWrapSplits(tokens, wrapLimit, tabSize);
|
||||
// console.log("String:", line, "Result:", splits, "Expected:", assertEqual);
|
||||
assert.ok(splits.length == assertEqual.length);
|
||||
for (var i = 0; i < splits.length; i++) {
|
||||
assert.ok(splits[i] == assertEqual[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// Basic splitting.
|
||||
computeAndAssert("foo bar foo bar", [12]);
|
||||
computeAndAssert("foo bar f bar", [12]);
|
||||
computeAndAssert("foo bar f r", [14]);
|
||||
computeAndAssert("foo bar foo bar foo bara foo", [12, 25]);
|
||||
|
||||
// Don't split if there is only whitespaces/tabs at the end of the line.
|
||||
computeAndAssert("foo foo foo \t \t", []);
|
||||
|
||||
// If there is no space to split, force split.
|
||||
computeAndAssert("foooooooooooooo", [12]);
|
||||
computeAndAssert("fooooooooooooooooooooooooooo", [12, 24]);
|
||||
computeAndAssert("foo bar fooooooooooobooooooo", [8, 20]);
|
||||
|
||||
// Basic splitting + tabs.
|
||||
computeAndAssert("foo \t\tbar", [6]);
|
||||
computeAndAssert("foo \t \tbar", [7]);
|
||||
|
||||
// Ignore spaces/tabs at beginning of split.
|
||||
computeAndAssert("foo \t \t \t \t bar", [14]);
|
||||
|
||||
// Test wrapping for asian characters.
|
||||
computeAndAssert("??", [1], 2);
|
||||
computeAndAssert(" ??", [1, 2], 2);
|
||||
computeAndAssert(" ?\t?", [1, 3], 2);
|
||||
computeAndAssert(" ??\t?", [1, 4], 4);
|
||||
|
||||
// Test wrapping for punctuation.
|
||||
computeAndAssert(" ab.c;ef++", [1, 3, 5, 7, 8], 2);
|
||||
computeAndAssert(" a.b", [1, 2, 3], 1);
|
||||
computeAndAssert("#>>", [1, 2], 1);
|
||||
} ,
|
||||
|
||||
"test get longest line": function() {
|
||||
var session = new AceAjax.EditSession(["12"]);
|
||||
session.setTabSize(4);
|
||||
assert.equal(session.getScreenWidth(), 2);
|
||||
|
||||
session.doc.insertNewLine({ row: 0, column: Infinity });
|
||||
session.doc.insertLines(1, ["123"]);
|
||||
assert.equal(session.getScreenWidth(), 3);
|
||||
|
||||
session.doc.insertNewLine({ row: 0, column: Infinity });
|
||||
session.doc.insertLines(1, ["\t\t"]);
|
||||
|
||||
assert.equal(session.getScreenWidth(), 8);
|
||||
|
||||
session.setTabSize(2);
|
||||
assert.equal(session.getScreenWidth(), 4);
|
||||
} ,
|
||||
|
||||
"test issue 83": function() {
|
||||
var session = new AceAjax.EditSession("");
|
||||
var editor = new AceAjax.Editor(null, session);
|
||||
var document = session.getDocument();
|
||||
|
||||
session.setUseWrapMode(true);
|
||||
|
||||
document.insertLines(0, ["a", "b"]);
|
||||
document.insertLines(2, ["c", "d"]);
|
||||
document.removeLines(1, 2);
|
||||
} ,
|
||||
|
||||
"test wrapMode init has to create wrapData array": function() {
|
||||
var session = new AceAjax.EditSession("foo bar\nfoo bar");
|
||||
var editor = new AceAjax.Editor(null, session);
|
||||
var document = session.getDocument();
|
||||
|
||||
session.setUseWrapMode(true);
|
||||
session.setWrapLimitRange(3, 3);
|
||||
session.adjustWrapLimit(80);
|
||||
} ,
|
||||
|
||||
"test first line blank with wrap": function() {
|
||||
var session = new AceAjax.EditSession("\nfoo");
|
||||
session.setUseWrapMode(true);
|
||||
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test first line blank with wrap 2": function() {
|
||||
var session = new AceAjax.EditSession("");
|
||||
session.setUseWrapMode(true);
|
||||
session.setValue("\nfoo");
|
||||
|
||||
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
|
||||
} ,
|
||||
|
||||
"test fold getFoldDisplayLine": function() {
|
||||
var session = createFoldTestSession();
|
||||
function assertDisplayLine(foldLine, str) {
|
||||
var line = session.getLine(foldLine.end.row);
|
||||
var displayLine =
|
||||
session.getFoldDisplayLine(foldLine, foldLine.end.row, line.length);
|
||||
assert.equal(displayLine, str);
|
||||
}
|
||||
} ,
|
||||
|
||||
"test foldLine idxToPosition": function() {
|
||||
var session = createFoldTestSession();
|
||||
|
||||
function assertIdx2Pos(foldLineIdx, idx, row, column) {
|
||||
var foldLine = null;
|
||||
assert.position(foldLine.idxToPosition(idx), row, column);
|
||||
}
|
||||
|
||||
// "function foo(items) {",
|
||||
// " for (var i=0; i<items.length; i++) {",
|
||||
// " alert(items[i] + \"juhu\");",
|
||||
// " } // Real Tab.",
|
||||
// "}"
|
||||
|
||||
assertIdx2Pos(0, 12, 0, 12);
|
||||
assertIdx2Pos(0, 13, 0, 13);
|
||||
assertIdx2Pos(0, 14, 0, 13);
|
||||
assertIdx2Pos(0, 19, 0, 13);
|
||||
assertIdx2Pos(0, 20, 0, 18);
|
||||
|
||||
assertIdx2Pos(1, 10, 1, 10);
|
||||
assertIdx2Pos(1, 11, 1, 10);
|
||||
assertIdx2Pos(1, 15, 1, 10);
|
||||
assertIdx2Pos(1, 16, 2, 10);
|
||||
assertIdx2Pos(1, 26, 2, 20);
|
||||
assertIdx2Pos(1, 27, 2, 20);
|
||||
assertIdx2Pos(1, 32, 2, 25);
|
||||
} ,
|
||||
|
||||
"test fold documentToScreen": function() {
|
||||
var session = createFoldTestSession();
|
||||
function assertDoc2Screen(docRow, docCol, screenRow, screenCol) {
|
||||
assert.position(
|
||||
session.documentToScreenPosition(docRow, docCol),
|
||||
screenRow, screenCol
|
||||
);
|
||||
}
|
||||
|
||||
// One fold ending in the same row.
|
||||
assertDoc2Screen(0, 0, 0, 0);
|
||||
assertDoc2Screen(0, 13, 0, 13);
|
||||
assertDoc2Screen(0, 14, 0, 13);
|
||||
assertDoc2Screen(0, 17, 0, 13);
|
||||
assertDoc2Screen(0, 18, 0, 20);
|
||||
|
||||
// Fold ending on some other row.
|
||||
assertDoc2Screen(1, 0, 1, 0);
|
||||
assertDoc2Screen(1, 10, 1, 10);
|
||||
assertDoc2Screen(1, 11, 1, 10);
|
||||
assertDoc2Screen(1, 99, 1, 10);
|
||||
|
||||
assertDoc2Screen(2, 0, 1, 10);
|
||||
assertDoc2Screen(2, 9, 1, 10);
|
||||
assertDoc2Screen(2, 10, 1, 16);
|
||||
assertDoc2Screen(2, 11, 1, 17);
|
||||
|
||||
// Fold in the same row with fold over more then one row in the same row.
|
||||
assertDoc2Screen(2, 19, 1, 25);
|
||||
assertDoc2Screen(2, 20, 1, 26);
|
||||
assertDoc2Screen(2, 21, 1, 26);
|
||||
|
||||
assertDoc2Screen(2, 24, 1, 26);
|
||||
assertDoc2Screen(2, 25, 1, 32);
|
||||
assertDoc2Screen(2, 26, 1, 33);
|
||||
assertDoc2Screen(2, 99, 1, 40);
|
||||
|
||||
// Test one position after the folds. Should be all like normal.
|
||||
assertDoc2Screen(3, 0, 2, 0);
|
||||
} ,
|
||||
|
||||
"test fold screenToDocument": function() {
|
||||
var session = createFoldTestSession();
|
||||
function assertScreen2Doc(docRow, docCol, screenRow, screenCol) {
|
||||
assert.position(
|
||||
session.screenToDocumentPosition(screenRow, screenCol),
|
||||
docRow, docCol
|
||||
);
|
||||
}
|
||||
|
||||
// One fold ending in the same row.
|
||||
assertScreen2Doc(0, 0, 0, 0);
|
||||
assertScreen2Doc(0, 13, 0, 13);
|
||||
assertScreen2Doc(0, 13, 0, 14);
|
||||
assertScreen2Doc(0, 18, 0, 20);
|
||||
assertScreen2Doc(0, 19, 0, 21);
|
||||
|
||||
// Fold ending on some other row.
|
||||
assertScreen2Doc(1, 0, 1, 0);
|
||||
assertScreen2Doc(1, 10, 1, 10);
|
||||
assertScreen2Doc(1, 10, 1, 11);
|
||||
|
||||
assertScreen2Doc(1, 10, 1, 15);
|
||||
assertScreen2Doc(2, 10, 1, 16);
|
||||
assertScreen2Doc(2, 11, 1, 17);
|
||||
|
||||
// Fold in the same row with fold over more then one row in the same row.
|
||||
assertScreen2Doc(2, 19, 1, 25);
|
||||
assertScreen2Doc(2, 20, 1, 26);
|
||||
assertScreen2Doc(2, 20, 1, 27);
|
||||
|
||||
assertScreen2Doc(2, 20, 1, 31);
|
||||
assertScreen2Doc(2, 25, 1, 32);
|
||||
assertScreen2Doc(2, 26, 1, 33);
|
||||
assertScreen2Doc(2, 33, 1, 99);
|
||||
|
||||
// Test one position after the folds. Should be all like normal.
|
||||
assertScreen2Doc(3, 0, 2, 0);
|
||||
} ,
|
||||
|
||||
"test getFoldsInRange()": function() {
|
||||
var session = createFoldTestSession();
|
||||
var foldLines = null;
|
||||
var folds = foldLines[0].folds.concat(foldLines[1].folds);
|
||||
|
||||
function test(startRow, startColumn, endColumn, endRow, folds) {
|
||||
var r = new AceAjax.Range(startRow, startColumn, endColumn, endRow);
|
||||
var retFolds = session.getFoldsInRange(r);
|
||||
|
||||
assert.ok(retFolds.length == folds.length);
|
||||
for (var i = 0; i < retFolds.length; i++) {
|
||||
assert.equal(retFolds[i].range + "", folds[i].range + "");
|
||||
}
|
||||
}
|
||||
|
||||
test(0, 0, 0, 13, []);
|
||||
test(0, 0, 0, 14, [folds[0]]);
|
||||
test(0, 0, 0, 18, [folds[0]]);
|
||||
test(0, 0, 1, 10, [folds[0]]);
|
||||
test(0, 0, 1, 11, [folds[0], folds[1]]);
|
||||
test(0, 18, 1, 11, [folds[1]]);
|
||||
test(2, 0, 2, 13, [folds[1]]);
|
||||
test(2, 10, 2, 20, []);
|
||||
test(2, 10, 2, 11, []);
|
||||
test(2, 19, 2, 20, []);
|
||||
} ,
|
||||
|
||||
"test fold one-line text insert": function() {
|
||||
// These are mostly test for the FoldLine.addRemoveChars function.
|
||||
var session = createFoldTestSession();
|
||||
var undoManager = session.getUndoManager();
|
||||
var foldLines = null;
|
||||
|
||||
function insert(row, column, text) {
|
||||
session.insert({ row: row, column: column }, text);
|
||||
}
|
||||
|
||||
var foldLine, fold, folds;
|
||||
// First line.
|
||||
foldLine = null;
|
||||
fold = foldLine.folds[0];
|
||||
|
||||
insert(0, 0, "0");
|
||||
assert.range(foldLine.range, 0, 14, 0, 19);
|
||||
assert.range(fold.range, 0, 14, 0, 19);
|
||||
insert(0, 14, "1");
|
||||
assert.range(foldLine.range, 0, 15, 0, 20);
|
||||
assert.range(fold.range, 0, 15, 0, 20);
|
||||
insert(0, 20, "2");
|
||||
assert.range(foldLine.range, 0, 15, 0, 20);
|
||||
assert.range(fold.range, 0, 15, 0, 20);
|
||||
|
||||
// Second line.
|
||||
foldLine = null;
|
||||
folds = foldLine.folds;
|
||||
|
||||
insert(1, 0, "3");
|
||||
assert.range(foldLine.range, 1, 11, 2, 25);
|
||||
assert.range(folds[0].range, 1, 11, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
insert(1, 11, "4");
|
||||
assert.range(foldLine.range, 1, 12, 2, 25);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
insert(2, 10, "5");
|
||||
assert.range(foldLine.range, 1, 12, 2, 26);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 21, 2, 26);
|
||||
|
||||
insert(2, 21, "6");
|
||||
assert.range(foldLine.range, 1, 12, 2, 27);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 22, 2, 27);
|
||||
|
||||
insert(2, 27, "7");
|
||||
assert.range(foldLine.range, 1, 12, 2, 27);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 22, 2, 27);
|
||||
|
||||
// UNDO = REMOVE
|
||||
undoManager.undo(); // 6
|
||||
assert.range(foldLine.range, 1, 12, 2, 27);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 22, 2, 27);
|
||||
|
||||
undoManager.undo(); // 5
|
||||
assert.range(foldLine.range, 1, 12, 2, 26);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 21, 2, 26);
|
||||
|
||||
undoManager.undo(); // 4
|
||||
assert.range(foldLine.range, 1, 12, 2, 25);
|
||||
assert.range(folds[0].range, 1, 12, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
undoManager.undo(); // 3
|
||||
assert.range(foldLine.range, 1, 11, 2, 25);
|
||||
assert.range(folds[0].range, 1, 11, 2, 10);
|
||||
assert.range(folds[1].range, 2, 20, 2, 25);
|
||||
|
||||
undoManager.undo(); // Beginning first line.
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 0, 15, 0, 20);
|
||||
assert.range(foldLines[1].range, 1, 10, 2, 25);
|
||||
|
||||
foldLine = null;
|
||||
fold = foldLine.folds[0];
|
||||
|
||||
undoManager.undo(); // 2
|
||||
assert.range(foldLine.range, 0, 15, 0, 20);
|
||||
assert.range(fold.range, 0, 15, 0, 20);
|
||||
|
||||
undoManager.undo(); // 1
|
||||
assert.range(foldLine.range, 0, 14, 0, 19);
|
||||
assert.range(fold.range, 0, 14, 0, 19);
|
||||
|
||||
undoManager.undo(); // 0
|
||||
assert.range(foldLine.range, 0, 13, 0, 18);
|
||||
assert.range(fold.range, 0, 13, 0, 18);
|
||||
} ,
|
||||
|
||||
"test fold multi-line insert/remove": function() {
|
||||
var session = createFoldTestSession(),
|
||||
undoManager = session.getUndoManager(),
|
||||
foldLines = null;
|
||||
function insert(row, column, text) {
|
||||
session.insert({ row: row, column: column }, text);
|
||||
}
|
||||
|
||||
var foldLines = null, foldLine, fold, folds;
|
||||
|
||||
insert(0, 0, "\nfo0");
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 2, 10, 3, 25);
|
||||
|
||||
insert(2, 0, "\nba1");
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 3, 13, 4, 25);
|
||||
|
||||
insert(3, 10, "\nfo2");
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 25);
|
||||
|
||||
insert(5, 10, "\nba3");
|
||||
assert.equal(foldLines.length, 3);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 10);
|
||||
assert.range(foldLines[2].range, 6, 13, 6, 18);
|
||||
|
||||
insert(6, 18, "\nfo4");
|
||||
assert.equal(foldLines.length, 3);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 10);
|
||||
assert.range(foldLines[2].range, 6, 13, 6, 18);
|
||||
|
||||
undoManager.undo(); // 3
|
||||
assert.equal(foldLines.length, 3);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 10);
|
||||
assert.range(foldLines[2].range, 6, 13, 6, 18);
|
||||
|
||||
undoManager.undo(); // 2
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 4, 6, 5, 25);
|
||||
|
||||
undoManager.undo(); // 1
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 3, 13, 4, 25);
|
||||
|
||||
undoManager.undo(); // 0
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 1, 16, 1, 21);
|
||||
assert.range(foldLines[1].range, 2, 10, 3, 25);
|
||||
|
||||
undoManager.undo(); // Beginning
|
||||
assert.equal(foldLines.length, 2);
|
||||
assert.range(foldLines[0].range, 0, 13, 0, 18);
|
||||
assert.range(foldLines[1].range, 1, 10, 2, 25);
|
||||
// TODO: Add test for inseration inside of folds.
|
||||
} ,
|
||||
|
||||
"test fold wrap data compution": function() {
|
||||
function assertWrap(line0, line1, line2) {
|
||||
line0 && assertArray(wrapData[0], line0);
|
||||
line1 && assertArray(wrapData[1], line1);
|
||||
line2 && assertArray(wrapData[2], line2);
|
||||
}
|
||||
|
||||
function removeFoldAssertWrap(docRow, docColumn, line0, line1, line2) {
|
||||
session.removeFold(session.getFoldAt(docRow, docColumn));
|
||||
assertWrap(line0, line1, line2);
|
||||
}
|
||||
|
||||
var lines = [
|
||||
"foo bar foo bar",
|
||||
"foo bar foo bar",
|
||||
"foo bar foo bar"
|
||||
];
|
||||
|
||||
var session = new AceAjax.EditSession(lines.join("\n"));
|
||||
session.setUseWrapMode(true);
|
||||
var wrapData = null;
|
||||
|
||||
// Do a simple assertion without folds to check basic functionallity.
|
||||
assertWrap([8], [8], [8]);
|
||||
|
||||
// --- Do in line folding ---
|
||||
|
||||
// Adding a fold. The split position is inside of the fold. As placeholder
|
||||
// are not splitable, the split should be before the split.
|
||||
session.addFold("woot", new AceAjax.Range(0, 4, 0, 15));
|
||||
assertWrap([4], [8], [8]);
|
||||
|
||||
// Remove the fold again which should reset the wrapData.
|
||||
removeFoldAssertWrap(0, 4, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot", new AceAjax.Range(0, 6, 0, 9));
|
||||
assertWrap([6, 13], [8], [8]);
|
||||
removeFoldAssertWrap(0, 6, [8], [8], [8]);
|
||||
|
||||
// The fold fits into the wrap limit - no split expected.
|
||||
session.addFold("woot", new AceAjax.Range(0, 3, 0, 15));
|
||||
assertWrap([], [8], [8]);
|
||||
removeFoldAssertWrap(0, 4, [8], [8], [8]);
|
||||
|
||||
// Fold after split position should be all fine.
|
||||
session.addFold("woot", new AceAjax.Range(0, 8, 0, 15));
|
||||
assertWrap([8], [8], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
// Fold's placeholder is far too long for wrapSplit.
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 8, 0, 15));
|
||||
assertWrap([8], [8], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
// Fold's placeholder is far too long for wrapSplit
|
||||
// + content at the end of the line
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 6, 0, 8));
|
||||
assertWrap([6, 20], [8], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 6, 0, 8));
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 8, 0, 10));
|
||||
assertWrap([6, 20, 34], [8], [8]);
|
||||
session.removeFold(session.getFoldAt(0, 7));
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 7, 0, 9));
|
||||
session.addFold("woot0123456789", new AceAjax.Range(0, 13, 0, 15));
|
||||
assertWrap([7, 21, 25], [8], [8]);
|
||||
session.removeFold(session.getFoldAt(0, 7));
|
||||
removeFoldAssertWrap(0, 14, [8], [8], [8]);
|
||||
|
||||
// --- Do some multiline folding ---
|
||||
|
||||
// Add a fold over two lines. Note, that the wrapData[1] stays the
|
||||
// same. This is an implementation detail and expected behavior.
|
||||
session.addFold("woot", new AceAjax.Range(0, 8, 1, 15));
|
||||
assertWrap([8], [8 /* See comments */], [8]);
|
||||
removeFoldAssertWrap(0, 8, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot", new AceAjax.Range(0, 9, 1, 11));
|
||||
assertWrap([8, 14], [8 /* See comments */], [8]);
|
||||
removeFoldAssertWrap(0, 9, [8], [8], [8]);
|
||||
|
||||
session.addFold("woot", new AceAjax.Range(0, 9, 1, 15));
|
||||
assertWrap([8], [8 /* See comments */], [8]);
|
||||
removeFoldAssertWrap(0, 9, [8], [8], [8]);
|
||||
|
||||
return session;
|
||||
} ,
|
||||
|
||||
"test add fold": function() {
|
||||
var session = createFoldTestSession();
|
||||
var fold;
|
||||
|
||||
function tryAddFold(placeholder, range, shouldFail) {
|
||||
var fail = false;
|
||||
try {
|
||||
fold = session.addFold(placeholder, range);
|
||||
} catch (e) {
|
||||
fail = true;
|
||||
}
|
||||
if (fail != shouldFail) {
|
||||
throw "Expected to get an exception";
|
||||
}
|
||||
}
|
||||
|
||||
tryAddFold("foo", new AceAjax.Range(0, 13, 0, 17), false);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 14, 0, 18), true);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 13, 0, 18), false);
|
||||
|
||||
tryAddFold("f", new AceAjax.Range(0, 13, 0, 18), false);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 18, 0, 21), false);
|
||||
session.removeFold(fold);
|
||||
|
||||
tryAddFold("foo", new AceAjax.Range(0, 18, 0, 22), false);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 18, 0, 19), true);
|
||||
tryAddFold("foo", new AceAjax.Range(0, 22, 1, 10), false);
|
||||
} ,
|
||||
|
||||
"test add subfolds": function() {
|
||||
var session = createFoldTestSession();
|
||||
var fold, oldFold;
|
||||
var foldData = null;
|
||||
|
||||
oldFold = foldData[0].folds[0];
|
||||
|
||||
fold = session.addFold("fold0", new AceAjax.Range(0, 10, 0, 21));
|
||||
assert.equal(foldData[0].folds.length, 1);
|
||||
assert.equal(fold.subFolds.length, 1);
|
||||
assert.equal(fold.subFolds[0], oldFold);
|
||||
|
||||
session.expandFold(fold);
|
||||
assert.equal(foldData[0].folds.length, 1);
|
||||
assert.equal(foldData[0].folds[0], oldFold);
|
||||
assert.equal(fold.subFolds.length, 0);
|
||||
|
||||
fold = session.addFold("fold0", new AceAjax.Range(0, 13, 2, 10));
|
||||
assert.equal(foldData.length, 1);
|
||||
assert.equal(fold.subFolds.length, 2);
|
||||
assert.equal(fold.subFolds[0], oldFold);
|
||||
|
||||
session.expandFold(fold);
|
||||
assert.equal(foldData.length, 2);
|
||||
assert.equal(foldData[0].folds.length, 1);
|
||||
assert.equal(foldData[0].folds[0], oldFold);
|
||||
assert.equal(fold.subFolds.length, 0);
|
||||
|
||||
session.unfold(null, true);
|
||||
fold = session.addFold("fold0", new AceAjax.Range(0, 0, 0, 21));
|
||||
session.addFold("fold0", new AceAjax.Range(0, 1, 0, 5));
|
||||
session.addFold("fold0", new AceAjax.Range(0, 6, 0, 8));
|
||||
assert.equal(fold.subFolds.length, 2);
|
||||
} ,
|
||||
|
||||
"test row cache": function() {
|
||||
var session = createFoldTestSession();
|
||||
|
||||
session.screenToDocumentPosition(2, 3);
|
||||
|
||||
session.screenToDocumentPosition(5, 3);
|
||||
|
||||
session.screenToDocumentPosition(0, 3);
|
||||
|
||||
var pos = session.screenToDocumentPosition(0, 0);
|
||||
assert.equal(pos.row, 0);
|
||||
|
||||
session.screenToDocumentPosition(1, 0);
|
||||
|
||||
|
||||
session.screenToDocumentPosition(1, 3);
|
||||
|
||||
session.screenToDocumentPosition(5, 3);
|
||||
|
||||
session = new AceAjax.EditSession(new Array(30).join("\n"));
|
||||
session.documentToScreenPosition(2, 0);
|
||||
session.documentToScreenPosition(2, 0);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var exports = {
|
||||
|
||||
setUp: function(next) {
|
||||
this.session1 = new AceAjax.EditSession(["abc", "def"]);
|
||||
this.session2 = new AceAjax.EditSession(["ghi", "jkl"]);
|
||||
|
||||
|
||||
var editor = new AceAjax.Editor(null);
|
||||
next();
|
||||
} ,
|
||||
|
||||
"test: change document": function() {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.setSession(this.session1);
|
||||
assert.equal(editor.getSession(), this.session1);
|
||||
|
||||
editor.setSession(this.session2);
|
||||
assert.equal(editor.getSession(), this.session2);
|
||||
} ,
|
||||
|
||||
"test: only changes to the new document should have effect": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
var called = false;
|
||||
editor.onDocumentChange = function () {
|
||||
called = true;
|
||||
};
|
||||
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
|
||||
this.session1.duplicateLines(0, 0);
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.duplicateLines(0, 0);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use cursor of new document": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
this.session1.getSelection().moveCursorTo(0, 1);
|
||||
this.session2.getSelection().moveCursorTo(1, 0);
|
||||
|
||||
editor.setSession(this.session1);
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
} ,
|
||||
|
||||
"test: only changing the cursor of the new doc should not have an effect": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.onCursorChange = function () {
|
||||
called = true;
|
||||
};
|
||||
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
|
||||
var called = false;
|
||||
this.session1.getSelection().moveCursorTo(0, 1);
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.getSelection().moveCursorTo(1, 1);
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use selection of new document": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
this.session1.getSelection().selectTo(0, 1);
|
||||
this.session2.getSelection().selectTo(1, 0);
|
||||
|
||||
editor.setSession(this.session1);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 1);
|
||||
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
} ,
|
||||
|
||||
"test: only changing the selection of the new doc should not have an effect": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.onSelectionChange = function () {
|
||||
called = true;
|
||||
};
|
||||
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
|
||||
var called = false;
|
||||
this.session1.getSelection().selectTo(0, 1);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.getSelection().selectTo(1, 1);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 1);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use mode of new document": function () {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
editor.onChangeMode = function () {
|
||||
called = true;
|
||||
};
|
||||
editor.setSession(this.session1);
|
||||
editor.setSession(this.session2);
|
||||
|
||||
var called = false;
|
||||
this.session1.setMode(new Text());
|
||||
assert.notOk(called);
|
||||
|
||||
this.session2.setMode(null);
|
||||
assert.ok(called);
|
||||
} ,
|
||||
|
||||
"test: should use stop worker of old document": function (next) {
|
||||
var editor = new AceAjax.Editor(null);
|
||||
|
||||
var self = this;
|
||||
|
||||
// 1. Open an editor and set the session to CssMode
|
||||
self.editor.setSession(self.session1);
|
||||
self.session1.setMode(null);
|
||||
|
||||
// 2. Add a line or two of valid CSS.
|
||||
self.session1.setValue("DIV { color: red; }");
|
||||
|
||||
// 3. Clear the session value.
|
||||
self.session1.setValue("");
|
||||
|
||||
// 4. Set the session to HtmlMode
|
||||
self.session1.setMode(null);
|
||||
|
||||
// 5. Try to type valid HTML
|
||||
self.session1.insert({ row: 0, column: 0 }, "<html></html>");
|
||||
|
||||
setTimeout(function () {
|
||||
assert.equal(Object.keys(self.session1.getAnnotations()).length, 0);
|
||||
next();
|
||||
}, 600);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,217 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var lipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " +
|
||||
"Mauris at arcu mi, eu lobortis mauris. Quisque ut libero eget " +
|
||||
"diam congue vehicula. Quisque ut odio ut mi aliquam tincidunt. " +
|
||||
"Duis lacinia aliquam lorem eget eleifend. Morbi eget felis mi. " +
|
||||
"Duis quam ligula, consequat vitae convallis volutpat, blandit " +
|
||||
"nec neque. Nulla facilisi. Etiam suscipit lorem ac justo " +
|
||||
"sollicitudin tristique. Phasellus ut posuere nunc. Aliquam " +
|
||||
"scelerisque mollis felis non gravida. Vestibulum lacus sem, " +
|
||||
"posuere non bibendum id, luctus non dolor. Aenean id metus " +
|
||||
"lorem, vel dapibus est. Donec gravida feugiat augue nec " +
|
||||
"accumsan.Lorem ipsum dolor sit amet, consectetur adipiscing " +
|
||||
"elit. Nulla vulputate, velit vitae tincidunt congue, nunc " +
|
||||
"augue accumsan velit, eu consequat turpis lectus ac orci. " +
|
||||
"Pellentesque ornare dolor feugiat dui auctor eu varius nulla " +
|
||||
"fermentum. Sed aliquam odio at velit lacinia vel fermentum " +
|
||||
"felis sodales. In dignissim magna eget nunc lobortis non " +
|
||||
"fringilla nibh ullamcorper. Donec facilisis malesuada elit " +
|
||||
"at egestas. Etiam bibendum, diam vitae tempor aliquet, dui " +
|
||||
"libero vehicula odio, eget bibendum mauris velit eu lorem.\n" +
|
||||
"consectetur";
|
||||
|
||||
function callHighlighterUpdate(session: AceAjax.IEditSession, firstRow: number, lastRow: number) {
|
||||
var rangeCount = 0;
|
||||
var mockMarkerLayer = { drawSingleLineMarker: function () { rangeCount++; } }
|
||||
return rangeCount;
|
||||
}
|
||||
|
||||
var assert: any;
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
|
||||
var exports = {
|
||||
setUp: function(next) {
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
var selection = session.getSelection();
|
||||
next();
|
||||
} ,
|
||||
|
||||
"test: highlight selected words by default": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
assert.equal(editor.getHighlightSelectedWord(), true);
|
||||
} ,
|
||||
|
||||
"test: highlight a word": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 9);
|
||||
selection.selectWord();
|
||||
|
||||
var highlighter = null;
|
||||
assert.ok(highlighter != null);
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "ipsum");
|
||||
assert.equal(highlighter.cache.length, 0);
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 2);
|
||||
} ,
|
||||
|
||||
"test: highlight a word and clear highlight": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 8);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "ipsum");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 2);
|
||||
|
||||
session.highlight("");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: highlight another word": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolor");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 4);
|
||||
} ,
|
||||
|
||||
"test: no selection, no highlight": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.clearSelection();
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: select a word, no highlight": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
|
||||
editor.setHighlightSelectedWord(false);
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolor");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: select a word with no matches": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.setHighlightSelectedWord(true);
|
||||
|
||||
var currentOptions = this.search.getOptions();
|
||||
var newOptions = {
|
||||
wrap: true,
|
||||
wholeWord: true,
|
||||
caseSensitive: true,
|
||||
needle: "Mauris"
|
||||
};
|
||||
this.search.set(newOptions);
|
||||
|
||||
var match = this.search.find(session);
|
||||
assert.notEqual(match, null, "found a match for 'Mauris'");
|
||||
|
||||
this.search.set(currentOptions);
|
||||
|
||||
selection.setSelectionRange(match);
|
||||
|
||||
assert.equal(session.getTextRange(match), "Mauris");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 1);
|
||||
} ,
|
||||
|
||||
"test: partial word selection 1": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
selection.selectLeft();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolo");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: partial word selection 2": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 13);
|
||||
selection.selectWord();
|
||||
selection.selectRight();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "dolor ");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: partial word selection 3": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.selectWord();
|
||||
selection.selectLeft();
|
||||
selection.shiftSelection(1);
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.equal(session.getTextRange(range), "olor");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 0), 0);
|
||||
} ,
|
||||
|
||||
"test: select last word": function () {
|
||||
var selection = session.getSelection();
|
||||
var session = new AceAjax.EditSession(lipsum);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
selection.moveCursorTo(0, 1);
|
||||
|
||||
var currentOptions = this.search.getOptions();
|
||||
var newOptions = {
|
||||
wrap: true,
|
||||
wholeWord: true,
|
||||
caseSensitive: true,
|
||||
backwards: true,
|
||||
needle: "consectetur"
|
||||
};
|
||||
this.search.set(newOptions);
|
||||
|
||||
var match = this.search.find(session);
|
||||
assert.notEqual(match, null, "found a match for 'consectetur'");
|
||||
assert.position(match.start, 1, 0);
|
||||
|
||||
this.search.set(currentOptions);
|
||||
|
||||
selection.setSelectionRange(match);
|
||||
|
||||
assert.equal(session.getTextRange(match), "consectetur");
|
||||
assert.equal(callHighlighterUpdate(session, 0, 1), 3);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
var exports = {
|
||||
createEditSession: function (rows, cols) {
|
||||
var line = new Array(cols + 1).join("a");
|
||||
var text = new Array(rows).join(line + "\n") + line;
|
||||
return new AceAjax.EditSession(text);
|
||||
},
|
||||
|
||||
"test: navigate to end of file should scroll the last line into view": function () {
|
||||
var doc = this.createEditSession(200, 10);
|
||||
var editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.navigateFileEnd();
|
||||
var cursor = editor.getCursorPosition();
|
||||
|
||||
assert.ok(editor.getFirstVisibleRow() <= cursor.row);
|
||||
assert.ok(editor.getLastVisibleRow() >= cursor.row);
|
||||
},
|
||||
|
||||
"test: navigate to start of file should scroll the first row into view": function () {
|
||||
var doc = this.createEditSession(200, 10);
|
||||
var editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.moveCursorTo(editor.getLastVisibleRow() + 20);
|
||||
editor.navigateFileStart();
|
||||
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
},
|
||||
|
||||
"test: goto hidden line should scroll the line into the middle of the viewport": function () {
|
||||
var editor = new AceAjax.Editor(renderer, this.createEditSession(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(101);
|
||||
assert.position(editor.getCursorPosition(), 100, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 89);
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(11);
|
||||
assert.position(editor.getCursorPosition(), 10, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(6);
|
||||
assert.position(editor.getCursorPosition(), 5, 0);
|
||||
assert.equal(0, editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(100, 0);
|
||||
editor.gotoLine(1);
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(191);
|
||||
assert.position(editor.getCursorPosition(), 190, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 179);
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(196);
|
||||
assert.position(editor.getCursorPosition(), 195, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 180);
|
||||
},
|
||||
|
||||
"test: goto visible line should only move the cursor and not scroll": function () {
|
||||
var editor = new AceAjax.Editor(renderer, this.createEditSession(200, 5));
|
||||
|
||||
editor.navigateTo(0, 0);
|
||||
editor.gotoLine(12);
|
||||
assert.position(editor.getCursorPosition(), 11, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 0);
|
||||
|
||||
editor.navigateTo(30, 0);
|
||||
editor.gotoLine(33);
|
||||
assert.position(editor.getCursorPosition(), 32, 0);
|
||||
assert.equal(editor.getFirstVisibleRow(), 30);
|
||||
},
|
||||
|
||||
"test: navigate from the end of a long line down to a short line and back should maintain the curser column": function () {
|
||||
var editor = new AceAjax.Editor(renderer, new AceAjax.EditSession(["123456", "1"]));
|
||||
|
||||
editor.navigateTo(0, 6);
|
||||
assert.position(editor.getCursorPosition(), 0, 6);
|
||||
|
||||
editor.navigateDown();
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
editor.navigateUp();
|
||||
assert.position(editor.getCursorPosition(), 0, 6);
|
||||
},
|
||||
|
||||
"test: reset desired column on navigate left or right": function () {
|
||||
var editor = new AceAjax.Editor(renderer, new AceAjax.EditSession(["123456", "12"]));
|
||||
|
||||
editor.navigateTo(0, 6);
|
||||
assert.position(editor.getCursorPosition(), 0, 6);
|
||||
|
||||
editor.navigateDown();
|
||||
assert.position(editor.getCursorPosition(), 1, 2);
|
||||
|
||||
editor.navigateLeft();
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
|
||||
editor.navigateUp();
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
},
|
||||
|
||||
"test: typing text should update the desired column": function () {
|
||||
var editor = new AceAjax.Editor(renderer, new AceAjax.EditSession(["1234", "1234567890"]));
|
||||
|
||||
editor.navigateTo(0, 3);
|
||||
editor.insert("juhu");
|
||||
|
||||
editor.navigateDown();
|
||||
assert.position(editor.getCursorPosition(), 1, 7);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,501 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
var mode: any;
|
||||
var exports = {
|
||||
"test: delete line from the middle": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a\nc\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "a");
|
||||
assert.position(editor.getCursorPosition(), 0, 1);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
},
|
||||
|
||||
"test: delete multiple selected lines": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", "d"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nd");
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
},
|
||||
|
||||
"test: delete first line": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.removeLines();
|
||||
|
||||
assert.equal(session.toString(), "b\nc");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
},
|
||||
|
||||
"test: delete last should also delete the new line of the previous line": function () {
|
||||
var session = new AceAjax.EditSession(["a", "b", "c", ""].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(3, 0);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb\nc");
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.removeLines();
|
||||
assert.equal(session.toString(), "a\nb");
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
},
|
||||
|
||||
"test: indent block": function () {
|
||||
var session = new AceAjax.EditSession(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 3);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
|
||||
assert.equal(["a12345", " b12345", " c12345"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 7);
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 1, 7);
|
||||
assert.position(range.end, 2, 7);
|
||||
},
|
||||
|
||||
"test: indent selected lines": function () {
|
||||
var session = new AceAjax.EditSession(["a12345", "b12345", "c12345"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.indent();
|
||||
assert.equal(["a12345", " b12345", "c12345"].join("\n"), session.toString());
|
||||
},
|
||||
|
||||
"test: no auto indent if cursor is before the {": function () {
|
||||
var session = new AceAjax.EditSession("{",mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.onTextInput("\n");
|
||||
assert.equal(["", "{"].join("\n"), session.toString());
|
||||
},
|
||||
|
||||
"test: outdent block": function () {
|
||||
var session = new AceAjax.EditSession([" a12345", " b12345", " c12345"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), [" a12345", "b12345", " c12345"].join("\n"));
|
||||
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 1);
|
||||
assert.position(range.end, 2, 1);
|
||||
|
||||
editor.blockOutdent();
|
||||
assert.equal(session.toString(), ["a12345", "b12345", "c12345"].join("\n"));
|
||||
|
||||
var range = editor.getSelectionRange();
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 2, 0);
|
||||
},
|
||||
|
||||
"test: outent without a selection should update cursor": function () {
|
||||
var session = new AceAjax.EditSession(" 12");
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 3);
|
||||
editor.blockOutdent(" ");
|
||||
|
||||
assert.equal(session.toString(), " 12");
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
},
|
||||
|
||||
"test: comment lines should perserve selection": function () {
|
||||
var session = new AceAjax.EditSession([" abc", "cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 2);
|
||||
editor.getSelection().selectDown();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal(["// abc", "//cde"].join("\n"), session.toString());
|
||||
|
||||
var selection = editor.getSelectionRange();
|
||||
assert.position(selection.start, 0, 4);
|
||||
assert.position(selection.end, 1, 4);
|
||||
},
|
||||
|
||||
"test: uncomment lines should perserve selection": function () {
|
||||
var session = new AceAjax.EditSession(["// abc", "//cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectRight();
|
||||
editor.getSelection().selectRight();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde"].join("\n"), session.toString());
|
||||
assert.range(editor.getSelectionRange(), 0, 0, 1, 1);
|
||||
},
|
||||
|
||||
"test: toggle comment lines twice should return the original text": function () {
|
||||
var session = new AceAjax.EditSession([" abc", "cde", "fg"], mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
editor.toggleCommentLines();
|
||||
|
||||
assert.equal([" abc", "cde", "fg"].join("\n"), session.toString());
|
||||
},
|
||||
|
||||
|
||||
"test: comment lines - if the selection end is at the line start it should stay there": function () {
|
||||
//select down
|
||||
var session = new AceAjax.EditSession(["abc", "cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
|
||||
// select up
|
||||
var session = new AceAjax.EditSession(["abc", "cde"].join("\n"),mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectUp();
|
||||
|
||||
editor.toggleCommentLines();
|
||||
assert.range(editor.getSelectionRange(), 0, 2, 1, 0);
|
||||
},
|
||||
|
||||
"test: move lines down should select moved lines": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(0, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "11", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
|
||||
// moving again should have no effect
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["33", "44", "11", "22"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 2);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 2, 0);
|
||||
},
|
||||
|
||||
"test: move lines up should select moved lines": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(2, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["11", "33", "44", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(session.toString(), ["33", "44", "11", "22"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 0, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 2, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 0, 0);
|
||||
},
|
||||
|
||||
"test: move line without active selection should not move cursor relative to the moved line": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesDown();
|
||||
assert.equal(["11", "33", "22", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 2, 1);
|
||||
|
||||
editor.clearSelection();
|
||||
|
||||
editor.moveLinesUp();
|
||||
assert.equal(["11", "22", "33", "44"].join("\n"), session.toString());
|
||||
assert.position(editor.getCursorPosition(), 1, 1);
|
||||
},
|
||||
|
||||
"test: copy lines down should select lines and place cursor at the selection start": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesDown();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 5, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 3, 0);
|
||||
},
|
||||
|
||||
"test: copy lines up should select lines and place cursor at the selection start": function () {
|
||||
var session = new AceAjax.EditSession(["11", "22", "33", "44"].join("\n"));
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectDown();
|
||||
|
||||
editor.copyLinesUp();
|
||||
assert.equal(["11", "22", "33", "22", "33", "44"].join("\n"), session.toString());
|
||||
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
assert.position(editor.getSelection().getSelectionAnchor(), 3, 0);
|
||||
assert.position(editor.getSelection().getSelectionLead(), 1, 0);
|
||||
},
|
||||
|
||||
"test: input a tab with soft tab should convert it to spaces": function () {
|
||||
var session = new AceAjax.EditSession("");
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
session.setTabSize(2);
|
||||
session.setUseSoftTabs(true);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
|
||||
session.setTabSize(5);
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), " ");
|
||||
},
|
||||
|
||||
"test: input tab without soft tabs should keep the tab character": function () {
|
||||
var session = new AceAjax.EditSession("");
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
session.setUseSoftTabs(false);
|
||||
|
||||
editor.onTextInput("\t");
|
||||
assert.equal(session.toString(), "\t");
|
||||
},
|
||||
|
||||
"test: undo/redo for delete line": function () {
|
||||
var session = new AceAjax.EditSession(["111", "222", "333"]);
|
||||
var undoManager = new AceAjax.UndoManager();
|
||||
session.setUndoManager(undoManager);
|
||||
|
||||
var initialText = session.toString();
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
editor.removeLines();
|
||||
var step1 = session.toString();
|
||||
assert.equal(step1, "222\n333");
|
||||
|
||||
editor.removeLines();
|
||||
var step2 = session.toString();
|
||||
assert.equal(step2, "333");
|
||||
|
||||
editor.removeLines();
|
||||
var step3 = session.toString();
|
||||
assert.equal(step3, "");
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step2);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), step1);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), initialText);
|
||||
|
||||
undoManager.undo();
|
||||
assert.equal(session.toString(), initialText);
|
||||
},
|
||||
|
||||
"test: remove left should remove character left of the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "456"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n56");
|
||||
},
|
||||
|
||||
"test: remove left should remove line break if cursor is at line start": function () {
|
||||
var session = new AceAjax.EditSession(["123", "456"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123456");
|
||||
},
|
||||
|
||||
"test: remove left should remove tabsize spaces if cursor is on a tab stop and preceeded by spaces": function () {
|
||||
var session = new AceAjax.EditSession(["123", " 456"]);
|
||||
session.setUseSoftTabs(true);
|
||||
session.setTabSize(4);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 8);
|
||||
editor.remove("left");
|
||||
assert.equal(session.toString(), "123\n 456");
|
||||
},
|
||||
|
||||
"test: transpose at line start should be a noop": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose in line should swap the charaters before and after the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4657", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose at line end should swap the last two characters": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4576", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose with non empty selection should be a noop": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 1);
|
||||
editor.getSelection().selectRight();
|
||||
editor.transposeLetters();
|
||||
|
||||
assert.equal(session.getValue(), ["123", "4567", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transpose should move the cursor behind the last swapped character": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.transposeLetters();
|
||||
assert.position(editor.getCursorPosition(), 1, 3);
|
||||
},
|
||||
|
||||
"test: remove to line end": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 2);
|
||||
editor.removeToLineEnd();
|
||||
assert.equal(session.getValue(), ["123", "45", "89"].join("\n"));
|
||||
},
|
||||
|
||||
"test: remove to line end at line end should remove the new line": function () {
|
||||
var session = new AceAjax.EditSession(["123", "4567", "89"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 4);
|
||||
editor.removeToLineEnd();
|
||||
assert.position(editor.getCursorPosition(), 1, 4);
|
||||
assert.equal(session.getValue(), ["123", "456789"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform selection to uppercase": function () {
|
||||
var session = new AceAjax.EditSession(["ajax", "dot", "org"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform word to uppercase": function () {
|
||||
var session = new AceAjax.EditSession(["ajax", "dot", "org"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toUpperCase()
|
||||
assert.equal(session.getValue(), ["ajax", "DOT", "org"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
},
|
||||
|
||||
"test: transform selection to lowercase": function () {
|
||||
var session = new AceAjax.EditSession(["AJAX", "DOT", "ORG"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.getSelection().selectLineEnd();
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
},
|
||||
|
||||
"test: transform word to lowercase": function () {
|
||||
var session = new AceAjax.EditSession(["AJAX", "DOT", "ORG"]);
|
||||
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
editor.moveCursorTo(1, 0);
|
||||
editor.toLowerCase()
|
||||
assert.equal(session.getValue(), ["AJAX", "dot", "ORG"].join("\n"));
|
||||
assert.position(editor.getCursorPosition(), 1, 0);
|
||||
}
|
||||
};
|
||||
@@ -1,114 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var editor: any;
|
||||
var renderer: any;
|
||||
var exec = function (name?, times?, args?) {
|
||||
do {
|
||||
editor.commands.exec(name, editor, args);
|
||||
} while (times-- > 1)
|
||||
};
|
||||
var testRanges = function (str) {
|
||||
assert.equal(editor.selection.getAllRanges() + "", str + "");
|
||||
}
|
||||
|
||||
var exports = {
|
||||
|
||||
name: "ACE multi_select.js",
|
||||
|
||||
"test: multiselect editing": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.w"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.navigateFileEnd();
|
||||
exec("selectMoreBefore", 3);
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
assert.equal(editor.selection.getAllRanges().length, 4);
|
||||
|
||||
var newLine = editor.session.getDocument().getNewLineCharacter();
|
||||
var copyText = "wwww".split("").join(newLine);
|
||||
assert.equal(editor.getCopyText(), copyText);
|
||||
exec("insertstring", 1, "a");
|
||||
exec("backspace", 2);
|
||||
assert.equal(editor.session.getValue(), "w1.w2\ntt\ntt");
|
||||
assert.equal(editor.selection.getAllRanges().length, 4);
|
||||
|
||||
exec("selectall");
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
//assert.equal(editor.selection.getAllRanges().length, 1);
|
||||
} ,
|
||||
|
||||
"test: multiselect navigation": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.we"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.selectMoreLines(1);
|
||||
testRanges("Range: [0/0] -> [0/0],Range: [1/0] -> [1/0]");
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
|
||||
exec("golinedown");
|
||||
exec("gotolineend");
|
||||
testRanges("Range: [1/9] -> [1/9],Range: [2/10] -> [2/10]");
|
||||
exec("selectwordleft");
|
||||
|
||||
testRanges("Range: [1/8] -> [1/9],Range: [2/8] -> [2/10]");
|
||||
exec("golinedown", 2);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
} ,
|
||||
|
||||
"test: multiselect session change": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.w"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
editor.selectMoreLines(1)
|
||||
testRanges("Range: [0/0] -> [0/0],Range: [1/0] -> [1/0]");
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
|
||||
var doc2 = new AceAjax.EditSession(["w1"]);
|
||||
editor.setSession(doc2);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
|
||||
editor.setSession(doc);
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
} ,
|
||||
|
||||
"test: multiselect addRange": function() {
|
||||
var doc = new AceAjax.EditSession([
|
||||
"w1.w2",
|
||||
" wtt.w",
|
||||
" wtt.w"
|
||||
]);
|
||||
editor = new AceAjax.Editor(renderer, doc);
|
||||
|
||||
var selection = editor.selection;
|
||||
|
||||
var range1 = new AceAjax.Range(0, 2, 0, 4);
|
||||
editor.selection.fromOrientedRange(range1);
|
||||
|
||||
var range2 = new AceAjax.Range(0, 3, 0, 4);
|
||||
selection.addRange(range2);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
assert.ok(range2.isEqual(editor.selection.getRange()));
|
||||
|
||||
var range3 = new AceAjax.Range(0, 1, 0, 1);
|
||||
selection.addRange(range3);
|
||||
assert.ok(editor.inMultiSelectMode);
|
||||
testRanges([range3, range2]);
|
||||
|
||||
var range4 = new AceAjax.Range(0, 0, 4, 0);
|
||||
selection.addRange(range4);
|
||||
assert.ok(!editor.inMultiSelectMode);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var renderer: AceAjax.VirtualRenderer;
|
||||
var mode: any;
|
||||
var exports = {
|
||||
|
||||
"test: simple at the end appending of text": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.insert('b');
|
||||
assert.equal(session.doc.getValue(), "var ab = 10;\nconsole.log(ab, ab);");
|
||||
editor.insert('cd');
|
||||
assert.equal(session.doc.getValue(), "var abcd = 10;\nconsole.log(abcd, abcd);");
|
||||
editor.remove('left');
|
||||
editor.remove('left');
|
||||
editor.remove('left');
|
||||
assert.equal(session.doc.getValue(), "var a = 10;\nconsole.log(a, a);");
|
||||
},
|
||||
|
||||
"test: inserting text outside placeholder": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);\n", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(2, 0);
|
||||
editor.insert('b');
|
||||
assert.equal(session.doc.getValue(), "var a = 10;\nconsole.log(a, a);\nb");
|
||||
},
|
||||
|
||||
"test: insertion at the beginning": function (next) {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 4);
|
||||
editor.insert('$');
|
||||
assert.equal(session.doc.getValue(), "var $a = 10;\nconsole.log($a, $a);");
|
||||
editor.moveCursorTo(0, 4);
|
||||
// Have to put this in a setTimeout because the anchor is only fixed later.
|
||||
setTimeout(function () {
|
||||
editor.insert('v');
|
||||
assert.equal(session.doc.getValue(), "var v$a = 10;\nconsole.log(v$a, v$a);");
|
||||
next();
|
||||
}, 10);
|
||||
},
|
||||
|
||||
"test: detaching placeholder": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.insert('b');
|
||||
assert.equal(session.doc.getValue(), "var ab = 10;\nconsole.log(ab, ab);");
|
||||
p.detach();
|
||||
editor.insert('cd');
|
||||
assert.equal(session.doc.getValue(), "var abcd = 10;\nconsole.log(ab, ab);");
|
||||
},
|
||||
|
||||
"test: events": function () {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
var entered = false;
|
||||
var left = false;
|
||||
p.on("cursorEnter", function () {
|
||||
entered = true;
|
||||
});
|
||||
p.on("cursorLeave", function () {
|
||||
left = true;
|
||||
});
|
||||
|
||||
editor.moveCursorTo(0, 0);
|
||||
editor.moveCursorTo(0, 4);
|
||||
p.onCursorChange(); // Have to do this by hand because moveCursorTo doesn't trigger the event
|
||||
assert.ok(entered);
|
||||
editor.moveCursorTo(1, 0);
|
||||
p.onCursorChange(); // Have to do this by hand because moveCursorTo doesn't trigger the event
|
||||
assert.ok(left);
|
||||
},
|
||||
|
||||
"test: cancel": function (next) {
|
||||
var session = new AceAjax.EditSession("var a = 10;\nconsole.log(a, a);", mode);
|
||||
session.setUndoManager(new AceAjax.UndoManager());
|
||||
var editor = new AceAjax.Editor(renderer, session);
|
||||
var p = new AceAjax.PlaceHolder(session, 1, { row: 0, column: 4 }, [{ row: 1, column: 12 }, { row: 1, column: 15 }]);
|
||||
|
||||
editor.moveCursorTo(0, 5);
|
||||
editor.insert('b');
|
||||
editor.insert('cd');
|
||||
editor.remove('left');
|
||||
assert.equal(session.doc.getValue(), "var abc = 10;\nconsole.log(abc, abc);");
|
||||
// Wait a little for the changes to enter the undo stack
|
||||
setTimeout(function () {
|
||||
p.cancel();
|
||||
assert.equal(session.doc.getValue(), "var a = 10;\nconsole.log(a, a);");
|
||||
next();
|
||||
}, 80);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var exports = {
|
||||
|
||||
name: "ACE range.js",
|
||||
|
||||
"test: create range": function () {
|
||||
var range = new AceAjax.Range(1, 2, 3, 4);
|
||||
|
||||
assert.equal(range.start.row, 1);
|
||||
assert.equal(range.start.column, 2);
|
||||
assert.equal(range.end.row, 3);
|
||||
assert.equal(range.end.column, 4);
|
||||
},
|
||||
|
||||
"test: create from points": function () {
|
||||
var range = AceAjax.Range.fromPoints({ row: 1, column: 2 }, { row: 3, column: 4 });
|
||||
|
||||
assert.equal(range.start.row, 1);
|
||||
assert.equal(range.start.column, 2);
|
||||
assert.equal(range.end.row, 3);
|
||||
assert.equal(range.end.column, 4);
|
||||
},
|
||||
|
||||
"test: clip to rows": function () {
|
||||
assert.range(new AceAjax.Range(0, 20, 100, 30).clipRows(10, 30), 10, 0, 31, 0);
|
||||
assert.range(new AceAjax.Range(0, 20, 30, 10).clipRows(10, 30), 10, 0, 30, 10);
|
||||
|
||||
var range = new AceAjax.Range(0, 20, 3, 10);
|
||||
var range = range.clipRows(10, 30);
|
||||
|
||||
assert.ok(range.isEmpty());
|
||||
assert.range(range, 10, 0, 10, 0);
|
||||
},
|
||||
|
||||
"test: isEmpty": function () {
|
||||
var range = new AceAjax.Range(1, 2, 1, 2);
|
||||
assert.ok(range.isEmpty());
|
||||
|
||||
var range = new AceAjax.Range(1, 2, 1, 6);
|
||||
assert.notOk(range.isEmpty());
|
||||
},
|
||||
|
||||
"test: is multi line": function () {
|
||||
var range = new AceAjax.Range(1, 2, 1, 6);
|
||||
assert.notOk(range.isMultiLine());
|
||||
|
||||
var range = new AceAjax.Range(1, 2, 2, 6);
|
||||
assert.ok(range.isMultiLine());
|
||||
},
|
||||
|
||||
"test: clone": function () {
|
||||
var range = new AceAjax.Range(1, 2, 3, 4);
|
||||
var clone = range.clone();
|
||||
|
||||
assert.position(clone.start, 1, 2);
|
||||
assert.position(clone.end, 3, 4);
|
||||
|
||||
clone.start.column = 20;
|
||||
assert.position(range.start, 1, 2);
|
||||
|
||||
clone.end.column = 20;
|
||||
assert.position(range.end, 3, 4);
|
||||
},
|
||||
|
||||
"test: contains for multi line ranges": function () {
|
||||
var range = new AceAjax.Range(1, 10, 5, 20);
|
||||
|
||||
assert.ok(range.contains(1, 10));
|
||||
assert.ok(range.contains(2, 0));
|
||||
assert.ok(range.contains(3, 100));
|
||||
assert.ok(range.contains(5, 19));
|
||||
assert.ok(range.contains(5, 20));
|
||||
|
||||
assert.notOk(range.contains(1, 9));
|
||||
assert.notOk(range.contains(0, 0));
|
||||
assert.notOk(range.contains(5, 21));
|
||||
},
|
||||
|
||||
"test: contains for single line ranges": function () {
|
||||
var range = new AceAjax.Range(1, 10, 1, 20);
|
||||
|
||||
assert.ok(range.contains(1, 10));
|
||||
assert.ok(range.contains(1, 15));
|
||||
assert.ok(range.contains(1, 20));
|
||||
|
||||
assert.notOk(range.contains(0, 9));
|
||||
assert.notOk(range.contains(2, 9));
|
||||
assert.notOk(range.contains(1, 9));
|
||||
assert.notOk(range.contains(1, 21));
|
||||
},
|
||||
|
||||
"test: extend range": function () {
|
||||
var range = new AceAjax.Range(2, 10, 2, 30);
|
||||
|
||||
var range = range.extend(2, 5);
|
||||
assert.range(range, 2, 5, 2, 30);
|
||||
|
||||
var range = range.extend(2, 35);
|
||||
assert.range(range, 2, 5, 2, 35);
|
||||
|
||||
var range = range.extend(2, 15);
|
||||
assert.range(range, 2, 5, 2, 35);
|
||||
|
||||
var range = range.extend(1, 4);
|
||||
assert.range(range, 1, 4, 2, 35);
|
||||
|
||||
var range = range.extend(6, 10);
|
||||
assert.range(range, 1, 4, 6, 10);
|
||||
},
|
||||
|
||||
"test: collapse rows": function () {
|
||||
var range = new AceAjax.Range(0, 2, 1, 2);
|
||||
assert.range(range.collapseRows(), 0, 0, 1, 0);
|
||||
|
||||
var range = new AceAjax.Range(2, 2, 3, 1);
|
||||
assert.range(range.collapseRows(), 2, 0, 3, 0);
|
||||
|
||||
var range = new AceAjax.Range(2, 2, 3, 0);
|
||||
assert.range(range.collapseRows(), 2, 0, 2, 0);
|
||||
|
||||
var range = new AceAjax.Range(2, 0, 2, 0);
|
||||
assert.range(range.collapseRows(), 2, 0, 2, 0);
|
||||
},
|
||||
|
||||
"test: to screen range": function () {
|
||||
var session = new AceAjax.EditSession([
|
||||
"juhu",
|
||||
"12\t\t34",
|
||||
"ぁぁa",
|
||||
"\t\t34",
|
||||
]);
|
||||
|
||||
var range = new AceAjax.Range(0, 0, 0, 3);
|
||||
assert.range(range.toScreenRange(session), 0, 0, 0, 3);
|
||||
|
||||
var range = new AceAjax.Range(1, 1, 1, 3);
|
||||
assert.range(range.toScreenRange(session), 1, 1, 1, 4);
|
||||
|
||||
var range = new AceAjax.Range(2, 1, 2, 2);
|
||||
assert.range(range.toScreenRange(session), 2, 2, 2, 4);
|
||||
|
||||
var range = new AceAjax.Range(3, 0, 3, 4);
|
||||
assert.range(range.toScreenRange(session), 3, 0, 3, 10);
|
||||
}
|
||||
};
|
||||
@@ -1,118 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
function flatten(rangeList) {
|
||||
var points = [];
|
||||
rangeList.ranges.forEach(function (r) {
|
||||
points.push(r.start.row, r.start.column, r.end.row, r.end.column)
|
||||
})
|
||||
return points;
|
||||
}
|
||||
function testRangeList(rangeList, points) {
|
||||
assert.equal("" + flatten(rangeList), "" + points);
|
||||
}
|
||||
|
||||
var exports = {
|
||||
|
||||
name: "ACE range_list.js",
|
||||
|
||||
"test: rangeList pointIndex": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.ranges = [
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(8, 8, 9, 9)
|
||||
];
|
||||
|
||||
assert.equal(rangeList.pointIndex({ row: 0, column: 1 }), -1);
|
||||
assert.equal(rangeList.pointIndex({ row: 1, column: 2 }), 0);
|
||||
assert.equal(rangeList.pointIndex({ row: 1, column: 3 }), 0);
|
||||
assert.equal(rangeList.pointIndex({ row: 3, column: 4 }), 0);
|
||||
assert.equal(rangeList.pointIndex({ row: 4, column: 1 }), -2);
|
||||
assert.equal(rangeList.pointIndex({ row: 5, column: 1 }), 1);
|
||||
assert.equal(rangeList.pointIndex({ row: 8, column: 9 }), 2);
|
||||
assert.equal(rangeList.pointIndex({ row: 18, column: 9 }), -4);
|
||||
} ,
|
||||
|
||||
"test: rangeList add": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.addList([
|
||||
new AceAjax.Range(9, 0, 9, 1),
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(8, 8, 9, 9),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(3, 20, 3, 24),
|
||||
new AceAjax.Range(6, 6, 7, 7)
|
||||
]);
|
||||
assert.equal(rangeList.ranges.length, 5);
|
||||
|
||||
rangeList.add(new AceAjax.Range(1, 2, 3, 5));
|
||||
assert.range(rangeList.ranges[0], 1, 2, 3, 5);
|
||||
assert.equal(rangeList.ranges.length, 5);
|
||||
|
||||
rangeList.add(new AceAjax.Range(7, 7, 7, 7));
|
||||
assert.range(rangeList.ranges[3], 7, 7, 7, 7);
|
||||
rangeList.add(new AceAjax.Range(7, 8, 7, 8));
|
||||
assert.range(rangeList.ranges[4], 7, 8, 7, 8);
|
||||
} ,
|
||||
|
||||
"test: rangeList add empty": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.addList([
|
||||
new AceAjax.Range(7, 10, 7, 10),
|
||||
new AceAjax.Range(9, 10, 9, 10),
|
||||
new AceAjax.Range(8, 10, 8, 10)
|
||||
]);
|
||||
assert.equal(rangeList.ranges.length, 3);
|
||||
|
||||
rangeList.add(new AceAjax.Range(9, 10, 9, 10));
|
||||
testRangeList(rangeList, [7, 10, 7, 10, 8, 10, 8, 10, 9, 10, 9, 10]);
|
||||
} ,
|
||||
|
||||
"test: rangeList merge": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
rangeList.addList([
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(6, 6, 7, 7),
|
||||
new AceAjax.Range(8, 8, 9, 9)
|
||||
]);
|
||||
var removed = [];
|
||||
|
||||
assert.equal(rangeList.ranges.length, 4);
|
||||
|
||||
rangeList.ranges[1].end.row = 7;
|
||||
removed = rangeList.merge();
|
||||
assert.equal(removed.length, 1);
|
||||
assert.range(rangeList.ranges[1], 4, 2, 7, 7);
|
||||
assert.equal(rangeList.ranges.length, 3);
|
||||
|
||||
rangeList.ranges[0].end.row = 10;
|
||||
removed = rangeList.merge();
|
||||
assert.range(rangeList.ranges[0], 1, 2, 10, 4);
|
||||
assert.equal(removed.length, 2);
|
||||
assert.equal(rangeList.ranges.length, 1);
|
||||
|
||||
rangeList.ranges.push(new AceAjax.Range(10, 10, 10, 10));
|
||||
rangeList.ranges.push(new AceAjax.Range(10, 10, 10, 10));
|
||||
removed = rangeList.merge();
|
||||
assert.equal(rangeList.ranges.length, 2);
|
||||
} ,
|
||||
|
||||
"test: rangeList remove": function() {
|
||||
var rangeList = new AceAjax.RangeList();
|
||||
var list = [
|
||||
new AceAjax.Range(1, 2, 3, 4),
|
||||
new AceAjax.Range(4, 2, 5, 4),
|
||||
new AceAjax.Range(6, 6, 7, 7),
|
||||
new AceAjax.Range(8, 8, 9, 9)
|
||||
];
|
||||
rangeList.addList(list);
|
||||
assert.equal(rangeList.ranges.length, 4);
|
||||
rangeList.substractPoint({ row: 1, column: 2 });
|
||||
assert.equal(rangeList.ranges.length, 3);
|
||||
rangeList.substractPoint({ row: 6, column: 7 });
|
||||
assert.equal(rangeList.ranges.length, 2);
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,417 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var exports = {
|
||||
"test: configure the search object": function () {
|
||||
var search = new AceAjax.Search();
|
||||
search.set({
|
||||
needle: "juhu"
|
||||
});
|
||||
},
|
||||
|
||||
"test: find simple text in document": function () {
|
||||
var session = new AceAjax.EditSession(["juhu kinners 123", "456"]);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 12);
|
||||
},
|
||||
|
||||
"test: find simple text in next line": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: find text starting at cursor position": function () {
|
||||
var session = new AceAjax.EditSession(["juhu kinners", "juhu kinners 123"]);
|
||||
session.getSelection().moveCursorTo(0, 6);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: wrap search is on by default": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners"
|
||||
});
|
||||
|
||||
assert.notEqual(search.find(session), null);
|
||||
},
|
||||
|
||||
"test: wrap search should wrap at file end": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: wrap search should find needle even if it starts inside it": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(6, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: wrap search with no match should return 'null'": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
session.getSelection().moveCursorTo(2, 1);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "xyz",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
assert.equal(search.find(session), null);
|
||||
},
|
||||
|
||||
"test: case sensitive is by default off": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "JUHU"
|
||||
});
|
||||
|
||||
assert.range(search.find(session), 1, 0, 1, 4);
|
||||
},
|
||||
|
||||
"test: case sensitive search": function () {
|
||||
var session = new AceAjax.EditSession(["abc", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "KINNERS",
|
||||
caseSensitive: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.equal(range, null);
|
||||
},
|
||||
|
||||
"test: whole word search should not match inside of words": function () {
|
||||
var session = new AceAjax.EditSession(["juhukinners", "juhu kinners 123", "456"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "kinners",
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 5);
|
||||
assert.position(range.end, 1, 12);
|
||||
},
|
||||
|
||||
"test: find backwards": function () {
|
||||
var session = new AceAjax.EditSession(["juhu juhu juhu juhu"]);
|
||||
session.getSelection().moveCursorTo(0, 10);
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
backwards: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 9);
|
||||
},
|
||||
|
||||
"test: find in selection": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
session.getSelection().setSelectionAnchor(1, 0);
|
||||
session.getSelection().selectTo(3, 5);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 0);
|
||||
assert.position(range.end, 1, 4);
|
||||
|
||||
search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(3, 2);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 0);
|
||||
assert.position(range.end, 1, 4);
|
||||
},
|
||||
|
||||
"test: find backwards in selection": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(3, 2);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
backwards: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 2, 0);
|
||||
assert.position(range.end, 2, 4);
|
||||
|
||||
search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(1, 2);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 1, 0);
|
||||
assert.position(range.end, 1, 4);
|
||||
},
|
||||
|
||||
"test: edge case - match directly before the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "123", "juhu"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(2, 5);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 2, 0);
|
||||
assert.position(range.end, 2, 4);
|
||||
},
|
||||
|
||||
"test: edge case - match backwards directly after the cursor": function () {
|
||||
var session = new AceAjax.EditSession(["123", "123", "juhu"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu",
|
||||
wrap: true,
|
||||
backwards: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(2, 0);
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 2, 0);
|
||||
assert.position(range.end, 2, 4);
|
||||
},
|
||||
|
||||
"test: find using a regular expression": function () {
|
||||
var session = new AceAjax.EditSession(["abc123 123 cd", "abc"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "\\d+",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 3);
|
||||
assert.position(range.end, 0, 6);
|
||||
},
|
||||
|
||||
"test: find using a regular expression and whole word": function () {
|
||||
var session = new AceAjax.EditSession(["abc123 123 cd", "abc"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "\\d+\\b",
|
||||
regExp: true,
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 7);
|
||||
assert.position(range.end, 0, 10);
|
||||
},
|
||||
|
||||
"test: use regular expressions with capture groups": function () {
|
||||
var session = new AceAjax.EditSession([" ab: 12px", " <h1 abc"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "(\\d+)",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
var range = search.find(session);
|
||||
assert.position(range.start, 0, 6);
|
||||
assert.position(range.end, 0, 8);
|
||||
},
|
||||
|
||||
"test: find all matches in selection": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
session.getSelection().setSelectionAnchor(0, 2);
|
||||
session.getSelection().selectTo(3, 2);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "uh",
|
||||
wrap: true,
|
||||
range: session.getSelection().getRange()
|
||||
});
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 2);
|
||||
assert.position(ranges[0].start, 1, 1);
|
||||
assert.position(ranges[0].end, 1, 3);
|
||||
assert.position(ranges[1].start, 2, 1);
|
||||
assert.position(ranges[1].end, 2, 3);
|
||||
},
|
||||
|
||||
|
||||
"test: find all multiline matches": function () {
|
||||
var session = new AceAjax.EditSession(["juhu", "juhu", "juhu", "juhu"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "hu\nju",
|
||||
wrap: true
|
||||
});
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 3);
|
||||
assert.position(ranges[0].start, 0, 2);
|
||||
assert.position(ranges[0].end, 1, 2);
|
||||
assert.position(ranges[1].start, 1, 2);
|
||||
assert.position(ranges[1].end, 2, 2);
|
||||
},
|
||||
|
||||
"test: replace() should return the replacement if the input matches the needle": function () {
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "juhu"
|
||||
});
|
||||
|
||||
assert.equal(search.replace("juhu", "kinners"), "kinners");
|
||||
assert.equal(search.replace("", "kinners"), null);
|
||||
assert.equal(search.replace(" juhu", "kinners"), null);
|
||||
|
||||
// case sensitivity
|
||||
assert.equal(search.replace("Juhu", "kinners"), "kinners");
|
||||
search.set({ caseSensitive: true });
|
||||
assert.equal(search.replace("Juhu", "kinners"), null);
|
||||
|
||||
// regexp replacement
|
||||
},
|
||||
|
||||
"test: replace with a RegExp search": function () {
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "\\d+",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
assert.equal(search.replace("123", "kinners"), "kinners");
|
||||
assert.equal(search.replace("01234", "kinners"), "kinners");
|
||||
assert.equal(search.replace("", "kinners"), null);
|
||||
assert.equal(search.replace("a12", "kinners"), null);
|
||||
assert.equal(search.replace("12a", "kinners"), null);
|
||||
},
|
||||
|
||||
"test: replace with RegExp match and capture groups": function () {
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "ab(\\d\\d)",
|
||||
regExp: true
|
||||
});
|
||||
|
||||
assert.equal(search.replace("ab12", "cd$1"), "cd12");
|
||||
assert.equal(search.replace("ab12", "-$&-"), "-ab12-");
|
||||
assert.equal(search.replace("ab12", "$$"), "$");
|
||||
},
|
||||
|
||||
"test: find all using regular expresion containing $": function () {
|
||||
var session = new AceAjax.EditSession(["a", " b", "c ", "d"]);
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "[ ]+$",
|
||||
regExp: true,
|
||||
wrap: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(1, 2);
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 1);
|
||||
assert.position(ranges[0].start, 2, 1);
|
||||
assert.position(ranges[0].end, 2, 2);
|
||||
},
|
||||
|
||||
"test: find all matches in a line": function () {
|
||||
var session = new AceAjax.EditSession("foo bar foo baz foobar foo");
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "foo",
|
||||
wrap: true,
|
||||
wholeWord: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(0, 4);
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 3);
|
||||
assert.position(ranges[0].start, 0, 0);
|
||||
assert.position(ranges[0].end, 0, 3);
|
||||
assert.position(ranges[1].start, 0, 8);
|
||||
assert.position(ranges[1].end, 0, 11);
|
||||
assert.position(ranges[2].start, 0, 23);
|
||||
assert.position(ranges[2].end, 0, 26);
|
||||
},
|
||||
|
||||
"test: find all matches in a line backwards": function () {
|
||||
var session = new AceAjax.EditSession("foo bar foo baz foobar foo");
|
||||
|
||||
var search = new AceAjax.Search().set({
|
||||
needle: "foo",
|
||||
wrap: true,
|
||||
wholeWord: true,
|
||||
backwards: true
|
||||
});
|
||||
|
||||
session.getSelection().moveCursorTo(0, 13);
|
||||
|
||||
var ranges = search.findAll(session);
|
||||
|
||||
assert.equal(ranges.length, 3);
|
||||
assert.position(ranges[2].start, 0, 23);
|
||||
assert.position(ranges[2].end, 0, 26);
|
||||
assert.position(ranges[1].start, 0, 8);
|
||||
assert.position(ranges[1].end, 0, 11);
|
||||
assert.position(ranges[0].start, 0, 0);
|
||||
assert.position(ranges[0].end, 0, 3);
|
||||
},
|
||||
};
|
||||
@@ -1,412 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var exports = {
|
||||
createSession: function (rows, cols) {
|
||||
var line = new Array(cols + 1).join("a");
|
||||
var text = new Array(rows).join(line + "\n") + line;
|
||||
return new AceAjax.EditSession(text);
|
||||
},
|
||||
|
||||
"test: move cursor to end of file should place the cursor on last row and column": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorFileEnd();
|
||||
assert.position(selection.getCursor(), 199, 10);
|
||||
},
|
||||
|
||||
"test: moveCursor to start of file should place the cursor on the first row and column": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorFileStart();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: move selection lead to end of file": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileEnd();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 100, 5);
|
||||
assert.position(range.end, 199, 10);
|
||||
},
|
||||
|
||||
"test: move selection lead to start of file": function () {
|
||||
var session = this.createSession(200, 10);
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(100, 5);
|
||||
selection.selectFileStart();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 100, 5);
|
||||
},
|
||||
|
||||
"test: move cursor word right": function () {
|
||||
var session = new AceAjax.EditSession([
|
||||
"ab",
|
||||
" Juhu Kinners (abc, 12)",
|
||||
" cde"
|
||||
].join("\n"));
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
assert.position(selection.getCursor(), 1, 0);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 5);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 13);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 18);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 1, 22);
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 2, 4);
|
||||
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 2, 4);
|
||||
},
|
||||
|
||||
"test: select word right if cursor in word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 2);
|
||||
selection.moveCursorWordRight();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 4);
|
||||
},
|
||||
|
||||
"test: moveCursor word left": function () {
|
||||
var session = new AceAjax.EditSession([
|
||||
"ab",
|
||||
" Juhu Kinners (abc, 12)",
|
||||
" cde"
|
||||
].join("\n"));
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorDown();
|
||||
selection.moveCursorLineEnd();
|
||||
assert.position(selection.getCursor(), 1, 23);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 20);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 15);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 6);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 1, 1);
|
||||
|
||||
// wrap line
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: moveCursor word left with umlauts": function () {
|
||||
var session = new AceAjax.EditSession(" Fuß Füße");
|
||||
|
||||
var selection = session.getSelection();
|
||||
selection.moveCursorTo(0, 9)
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 5);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 1);
|
||||
},
|
||||
|
||||
"test: select word left if cursor in word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 5);
|
||||
},
|
||||
|
||||
"test: select word right and select": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 0);
|
||||
selection.selectWordRight();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 0, 4);
|
||||
},
|
||||
|
||||
"test: select word left and select": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 3);
|
||||
selection.selectWordLeft();
|
||||
|
||||
var range = selection.getRange();
|
||||
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 0, 3);
|
||||
},
|
||||
|
||||
"test: select word with cursor in word should select the word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners 123");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 12);
|
||||
},
|
||||
|
||||
"test: select word with cursor in word including right whitespace should select the word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners 123");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 8);
|
||||
selection.selectAWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 18);
|
||||
},
|
||||
|
||||
"test: select word with cursor betwen white space and word should select the word": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 0);
|
||||
assert.position(range.end, 0, 4);
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 5);
|
||||
assert.position(range.end, 0, 12);
|
||||
},
|
||||
|
||||
"test: select word with cursor in white space should select white space": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
selection.selectWord();
|
||||
|
||||
var range = selection.getRange();
|
||||
assert.position(range.start, 0, 4);
|
||||
assert.position(range.end, 0, 6);
|
||||
},
|
||||
|
||||
"test: moving cursor should fire a 'changeCursor' event": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
|
||||
var called = false;
|
||||
selection.addEventListener("changeCursor", function () {
|
||||
called = true;
|
||||
});
|
||||
|
||||
selection.moveCursorTo(0, 6);
|
||||
assert.ok(called);
|
||||
},
|
||||
|
||||
"test: calling setCursor with the same position should not fire an event": function () {
|
||||
var session = new AceAjax.EditSession("Juhu Kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
|
||||
var called = false;
|
||||
selection.addEventListener("changeCursor", function () {
|
||||
called = true;
|
||||
});
|
||||
|
||||
selection.moveCursorTo(0, 5);
|
||||
assert.notOk(called);
|
||||
},
|
||||
|
||||
"test: moveWordright should move past || and [": function () {
|
||||
var session = new AceAjax.EditSession("||foo[");
|
||||
var selection = session.getSelection();
|
||||
|
||||
// Move behind ||foo
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 0, 5);
|
||||
|
||||
// Move behind [
|
||||
selection.moveCursorWordRight();
|
||||
assert.position(selection.getCursor(), 0, 6);
|
||||
},
|
||||
|
||||
"test: moveWordLeft should move past || and [": function () {
|
||||
var session = new AceAjax.EditSession("||foo[");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 6);
|
||||
|
||||
// Move behind [foo
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 2);
|
||||
|
||||
// Move behind ||
|
||||
selection.moveCursorWordLeft();
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: move cursor to line start should move cursor to end of the indentation first": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 6);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
"test: move cursor to line start when the cursor is at the end of the indentation should move cursor to column 0": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 4);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 0);
|
||||
},
|
||||
|
||||
"test: move cursor to line start when the cursor is at column 0 should move cursor to the end of the indentation": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 0);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
// Eclipse style
|
||||
"test: move cursor to line start when the cursor is before the initial indentation should move cursor to the end of the indentation": function () {
|
||||
var session = new AceAjax.EditSession("12\n Juhu\n12");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 2);
|
||||
selection.moveCursorLineStart();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
"test go line up when in the middle of the first line should go to document start": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.moveCursorUp();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
"test: (wrap) go line up when in the middle of the first line should go to document start": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
session.setWrapLimitRange(5, 5);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.moveCursorUp();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 0);
|
||||
},
|
||||
|
||||
|
||||
"test go line down when in the middle of the last line should go to document end": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 4);
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 12);
|
||||
},
|
||||
|
||||
"test (wrap) go line down when in the middle of the last line should go to document end": function () {
|
||||
var session = new AceAjax.EditSession("juhu kinners");
|
||||
session.setWrapLimitRange(8, 8);
|
||||
session.adjustWrapLimit(80);
|
||||
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 10);
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 0, 12);
|
||||
},
|
||||
|
||||
"test go line up twice and then once down when in the second should go back to the previous column": function () {
|
||||
var session = new AceAjax.EditSession("juhu\nkinners");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(1, 4);
|
||||
selection.moveCursorUp();
|
||||
selection.moveCursorUp();
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
},
|
||||
|
||||
"test (keyboard navigation) when curLine is not EOL and targetLine is all whitespace new column should be current column": function () {
|
||||
var session = new AceAjax.EditSession("function (a) {\n\
|
||||
\n\
|
||||
}");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(2, 0);
|
||||
selection.moveCursorUp();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 0);
|
||||
},
|
||||
|
||||
"test (keyboard navigation) when curLine is EOL and targetLine is shorter dan current column, new column should be targetLine's EOL": function () {
|
||||
var session = new AceAjax.EditSession("function (a) {\n\
|
||||
\n\
|
||||
}");
|
||||
var selection = session.getSelection();
|
||||
|
||||
selection.moveCursorTo(0, 14);
|
||||
selection.moveCursorDown();
|
||||
|
||||
assert.position(selection.getCursor(), 1, 4);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var mode: any;
|
||||
var exports = {
|
||||
"test: token iterator initialization in JavaScript document": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
assert.equal(iterator.getCurrentToken().value, "function");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
iterator.stepForward();
|
||||
assert.equal(iterator.getCurrentToken().value, " ");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 8);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 4);
|
||||
assert.equal(iterator.getCurrentToken().value, "function");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
iterator.stepForward();
|
||||
assert.equal(iterator.getCurrentToken().value, " ");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 8);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 2, 18);
|
||||
assert.equal(iterator.getCurrentToken().value, "items");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 2);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 14);
|
||||
|
||||
iterator.stepForward();
|
||||
assert.equal(iterator.getCurrentToken().value, "[");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 2);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 19);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 4, 0);
|
||||
assert.equal(iterator.getCurrentToken().value, "}");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 4);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
iterator.stepBackward();
|
||||
assert.equal(iterator.getCurrentToken().value, "// Real Tab.");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 3);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 6);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 5, 0);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator initialization in text document": function () {
|
||||
var lines = [
|
||||
"Lorem ipsum dolor sit amet, consectetur adipisicing elit,",
|
||||
"sed do eiusmod tempor incididunt ut labore et dolore magna",
|
||||
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation",
|
||||
"ullamco laboris nisi ut aliquip ex ea commodo consequat."
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"));
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[0]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 4);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[0]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 2, 18);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[2]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 2);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 3, lines[3].length - 1);
|
||||
assert.equal(iterator.getCurrentToken().value, lines[3]);
|
||||
assert.equal(iterator.getCurrentTokenRow(), 3);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 0);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 4, 0);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator step forward in JavaScript document": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var tokens = [];
|
||||
var len = session.getLength();
|
||||
for (var i = 0; i < len; i++)
|
||||
tokens = tokens.concat(session.getTokens(i));
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
for (var i = 1; i < tokens.length; i++)
|
||||
assert.equal(iterator.stepForward(), tokens[i]);
|
||||
assert.equal(iterator.stepForward(), null);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator step backward in JavaScript document": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var tokens = [];
|
||||
var len = session.getLength();
|
||||
for (var i = 0; i < len; i++)
|
||||
tokens = tokens.concat(session.getTokens(i));
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 4, 0);
|
||||
for (var i = tokens.length - 2; i >= 0; i--)
|
||||
assert.equal(iterator.stepBackward(), tokens[i]);
|
||||
assert.equal(iterator.stepBackward(), null);
|
||||
assert.equal(iterator.getCurrentToken(), null);
|
||||
},
|
||||
|
||||
"test: token iterator reports correct row and column": function () {
|
||||
var lines = [
|
||||
"function foo(items) {",
|
||||
" for (var i=0; i<items.length; i++) {",
|
||||
" alert(items[i] + \"juhu\");",
|
||||
" } // Real Tab.",
|
||||
"}"
|
||||
];
|
||||
var session = new AceAjax.EditSession(lines.join("\n"),mode);
|
||||
|
||||
var iterator = new AceAjax.TokenIterator(session, 0, 0);
|
||||
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
|
||||
assert.equal(iterator.getCurrentToken().value, "foo");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 0);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 9);
|
||||
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
iterator.stepForward();
|
||||
|
||||
assert.equal(iterator.getCurrentToken().value, "for");
|
||||
assert.equal(iterator.getCurrentTokenRow(), 1);
|
||||
assert.equal(iterator.getCurrentTokenColumn(), 4);
|
||||
}
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/// <reference path="../ace.d.ts" />
|
||||
|
||||
var assert: any;
|
||||
var exports = {
|
||||
"test: screen2text the column should be rounded to the next character edge": function () {
|
||||
var el = document.createElement("div");
|
||||
|
||||
if (!el.getBoundingClientRect) {
|
||||
console.log("Skipping test: This test only runs in the browser");
|
||||
return;
|
||||
}
|
||||
|
||||
el.style.left = "20px";
|
||||
el.style.top = "30px";
|
||||
el.style.width = "300px";
|
||||
el.style.height = "100px";
|
||||
document.body.appendChild(el);
|
||||
|
||||
var renderer = new AceAjax.VirtualRenderer(el);
|
||||
renderer.setPadding(0);
|
||||
renderer.setSession(new AceAjax.EditSession("1234"));
|
||||
|
||||
var r = renderer.scroller.getBoundingClientRect();
|
||||
function testPixelToText(x, y, row, column) {
|
||||
assert.position(renderer.screenToTextCoordinates(x + r.left, y + r.top), row, column);
|
||||
}
|
||||
|
||||
renderer.characterWidth = 10;
|
||||
renderer.lineHeight = 15;
|
||||
|
||||
testPixelToText(4, 0, 0, 0);
|
||||
testPixelToText(5, 0, 0, 1);
|
||||
testPixelToText(9, 0, 0, 1);
|
||||
testPixelToText(10, 0, 0, 1);
|
||||
testPixelToText(14, 0, 0, 1);
|
||||
testPixelToText(15, 0, 0, 2);
|
||||
document.body.removeChild(el);
|
||||
}
|
||||
|
||||
// change tab size after setDocument (for text layer)
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": false,
|
||||
"noImplicitThis": false,
|
||||
"strictNullChecks": false,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"test/anchor.ts",
|
||||
"test/background_tokenizer.ts",
|
||||
"test/default.ts",
|
||||
"test/document.ts",
|
||||
"test/edit_session.ts",
|
||||
"test/editor1.ts",
|
||||
"test/editor_highlight_selected_word.ts",
|
||||
"test/editor_navigation.ts",
|
||||
"test/editor_text_edit.ts",
|
||||
"test/multi_select.ts",
|
||||
"test/placeholder.ts",
|
||||
"test/range.ts",
|
||||
"test/range_list.ts",
|
||||
"test/search.ts",
|
||||
"test/selection.ts",
|
||||
"test/token_iterator.ts",
|
||||
"test/virtual_renderer.ts"
|
||||
]
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/// <reference path='acl.d.ts'/>
|
||||
|
||||
// https://github.com/OptimalBits/node_acl/blob/master/Readme.md
|
||||
import Acl = require('acl');
|
||||
import mongodb = require('mongodb');
|
||||
|
||||
var db: mongodb.Db;
|
||||
|
||||
// Using the mongo db backend
|
||||
var acl = new Acl(new Acl.mongodbBackend(db, 'acl_', true));
|
||||
|
||||
// guest is allowed to view blogs
|
||||
acl.allow('guest', 'blogs', 'view');
|
||||
|
||||
// allow function accepts arrays as any parameter
|
||||
acl.allow('member', 'blogs', ['edit','view', 'delete']);
|
||||
@@ -1,16 +0,0 @@
|
||||
/// <reference path='acl.d.ts'/>
|
||||
|
||||
// https://github.com/OptimalBits/node_acl/blob/master/Readme.md
|
||||
import Acl = require('acl');
|
||||
import redis = require('redis');
|
||||
|
||||
var client: redis.RedisClient;
|
||||
|
||||
// Using the redis backend
|
||||
var acl = new Acl(new Acl.redisBackend(client, 'acl_'));
|
||||
|
||||
// guest is allowed to view blogs
|
||||
acl.allow('guest', 'blogs', 'view');
|
||||
|
||||
// allow function accepts arrays as any parameter
|
||||
acl.allow('member', 'blogs', ['edit','view', 'delete']);
|
||||
@@ -1,65 +0,0 @@
|
||||
/// <reference path='acl.d.ts'/>
|
||||
|
||||
// Sample code from
|
||||
// https://github.com/OptimalBits/node_acl/blob/master/Readme.md
|
||||
import Acl = require('acl');
|
||||
|
||||
var report = <T>(err: Error, value: T) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
console.info(value);
|
||||
};
|
||||
|
||||
// Using the memory backend
|
||||
var acl = new Acl(new Acl.memoryBackend());
|
||||
|
||||
// guest is allowed to view blogs
|
||||
acl.allow('guest', 'blogs', 'view');
|
||||
|
||||
// allow function accepts arrays as any parameter
|
||||
acl.allow('member', 'blogs', ['edit','view', 'delete']);
|
||||
|
||||
acl.addUserRoles('joed', 'guest');
|
||||
|
||||
acl.addRoleParents('baz', ['foo','bar']);
|
||||
|
||||
acl.allow('foo', ['blogs','forums','news'], ['view', 'delete']);
|
||||
|
||||
acl.allow('admin', ['blogs','forums'], '*');
|
||||
|
||||
acl.allow([
|
||||
{
|
||||
roles:['guest','special-member'],
|
||||
allows:[
|
||||
{resources:'blogs', permissions:'get'},
|
||||
{resources:['forums','news'], permissions:['get','put','delete']}
|
||||
]
|
||||
},
|
||||
{
|
||||
roles:['gold','silver'],
|
||||
allows:[
|
||||
{resources:'cash', permissions:['sell','exchange']},
|
||||
{resources:['account','deposit'], permissions:['put','delete']}
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
||||
acl.isAllowed('joed', 'blogs', 'view', (err, res) => {
|
||||
if (res) {
|
||||
console.log("User joed is allowed to view blogs");
|
||||
}
|
||||
});
|
||||
|
||||
acl.isAllowed('jsmith', 'blogs', ['edit','view','delete'])
|
||||
.then((result) => {
|
||||
console.dir('jsmith is allowed blogs ' + result);
|
||||
acl.addUserRoles('jsmith', 'member');
|
||||
}).then(() =>
|
||||
acl.isAllowed('jsmith', 'blogs', ['edit','view','delete'])
|
||||
).then((result) =>
|
||||
console.dir('jsmith is allowed blogs ' + result)
|
||||
).then(() => {
|
||||
acl.allowedPermissions('james', ['blogs','forums'], report);
|
||||
acl.allowedPermissions('jsmith', ['blogs','forums'], report);
|
||||
});
|
||||
Vendored
-150
@@ -1,150 +0,0 @@
|
||||
// Type definitions for node_acl 0.4.7
|
||||
// Project: https://github.com/optimalbits/node_acl
|
||||
// Definitions by: Qubo <https://github.com/tkQubo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../bluebird/bluebird.d.ts" />
|
||||
/// <reference path='../node/node.d.ts'/>
|
||||
|
||||
/// <reference path='../redis/redis.d.ts'/>
|
||||
/// <reference path="../mongodb/mongodb-1.4.9.d.ts" />
|
||||
|
||||
declare module "acl" {
|
||||
import http = require('http');
|
||||
import Promise = require("bluebird");
|
||||
|
||||
type strings = string|string[];
|
||||
type Value = string|number;
|
||||
type Values = Value|Value[];
|
||||
type Action = () => any;
|
||||
type Callback = (err: Error) => any;
|
||||
type AnyCallback = (err: Error, obj: any) => any;
|
||||
type AllowedCallback = (err: Error, allowed: boolean) => any;
|
||||
type GetUserId = (req: http.ServerRequest, res: http.ServerResponse) => Value;
|
||||
|
||||
interface AclStatic {
|
||||
new (backend: Backend<any>, logger: Logger, options: Option): Acl;
|
||||
new (backend: Backend<any>, logger: Logger): Acl;
|
||||
new (backend: Backend<any>): Acl;
|
||||
memoryBackend: MemoryBackendStatic;
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
debug: (msg: string)=>any;
|
||||
}
|
||||
|
||||
interface Acl {
|
||||
addUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
removeUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
userRoles: (userId: Value, cb?: (err: Error, roles: string[])=>any) => Promise<string[]>;
|
||||
roleUsers: (role: Value, cb?: (err: Error, users: Values)=>any) => Promise<any>;
|
||||
hasRole: (userId: Value, role: string, cb?: (err: Error, isInRole: boolean)=>any) => Promise<boolean>;
|
||||
addRoleParents: (role: string, parents: Values, cb?: Callback) => Promise<void>;
|
||||
removeRole: (role: string, cb?: Callback) => Promise<void>;
|
||||
removeResource: (resource: string, cb?: Callback) => Promise<void>;
|
||||
allow: {
|
||||
(roles: Values, resources: strings, permissions: strings, cb?: Callback): Promise<void>;
|
||||
(aclSets: AclSet|AclSet[]): Promise<void>;
|
||||
}
|
||||
removeAllow: (role: string, resources: strings, permissions: strings, cb?: Callback) => Promise<void>;
|
||||
removePermissions: (role: string, resources: strings, permissions: strings, cb?: Function) => Promise<void>;
|
||||
allowedPermissions: (userId: Value, resources: strings, cb?: AnyCallback) => Promise<void>;
|
||||
isAllowed: (userId: Value, resources: strings, permissions: strings, cb?: AllowedCallback) => Promise<boolean>;
|
||||
areAnyRolesAllowed: (roles: strings, resource: strings, permissions: strings, cb?: AllowedCallback) => Promise<any>;
|
||||
whatResources: (roles: strings, permissions: strings, cb?: AnyCallback) => Promise<any>;
|
||||
permittedResources: (roles: strings, permissions: strings, cb?: Function) => Promise<void>;
|
||||
middleware: (numPathComponents: number, userId: Value|GetUserId, actions: strings) => Promise<any>;
|
||||
}
|
||||
|
||||
interface Option {
|
||||
buckets?: BucketsOption;
|
||||
}
|
||||
|
||||
interface BucketsOption {
|
||||
meta?: string;
|
||||
parents?: string;
|
||||
permissions?: string;
|
||||
resources?: string;
|
||||
roles?: string;
|
||||
users?: string;
|
||||
}
|
||||
|
||||
interface AclSet {
|
||||
roles: strings;
|
||||
allows: AclAllow[];
|
||||
}
|
||||
|
||||
interface AclAllow {
|
||||
resources: strings;
|
||||
permissions: strings;
|
||||
}
|
||||
|
||||
interface MemoryBackend extends Backend<Action[]> { }
|
||||
interface MemoryBackendStatic {
|
||||
new(): MemoryBackend;
|
||||
}
|
||||
|
||||
//
|
||||
// For internal use
|
||||
//
|
||||
interface Backend<T> {
|
||||
begin: () => T;
|
||||
end: (transaction: T, cb?: Action) => void;
|
||||
clean: (cb?: Action) => void;
|
||||
get: (bucket: string, key: Value, cb?: Action) => void;
|
||||
union: (bucket: string, keys: Value[], cb?: Action) => void;
|
||||
add: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
del: (transaction: T, bucket: string, keys: Value[]) => void;
|
||||
remove: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
|
||||
endAsync: Function; //TODO: Give more specific function signature
|
||||
getAsync: Function;
|
||||
cleanAsync: Function;
|
||||
unionAsync: Function;
|
||||
}
|
||||
|
||||
interface Contract {
|
||||
(args: IArguments): Contract|NoOp;
|
||||
debug: boolean;
|
||||
fulfilled: boolean;
|
||||
args: any[];
|
||||
checkedParams: string[];
|
||||
params: (...types: string[]) => Contract|NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
interface NoOp {
|
||||
params: (...types: string[]) => NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
// for redis backend
|
||||
import redis = require('redis');
|
||||
|
||||
interface AclStatic {
|
||||
redisBackend: RedisBackendStatic;
|
||||
}
|
||||
|
||||
interface RedisBackend extends Backend<redis.RedisClient> { }
|
||||
interface RedisBackendStatic {
|
||||
new(redis: redis.RedisClient, prefix: string): RedisBackend;
|
||||
new(redis: redis.RedisClient): RedisBackend;
|
||||
}
|
||||
|
||||
// for mongodb backend
|
||||
import mongo = require('mongodb');
|
||||
|
||||
interface AclStatic {
|
||||
mongodbBackend: MongodbBackendStatic;
|
||||
}
|
||||
|
||||
interface MongodbBackend extends Backend<Callback> { }
|
||||
interface MongodbBackendStatic {
|
||||
new(db: mongo.Db, prefix: string, useSingle: boolean): MongodbBackend;
|
||||
new(db: mongo.Db, prefix: string): MongodbBackend;
|
||||
new(db: mongo.Db): MongodbBackend;
|
||||
}
|
||||
|
||||
var _: AclStatic;
|
||||
export = _;
|
||||
}
|
||||
Vendored
+147
@@ -0,0 +1,147 @@
|
||||
// Type definitions for node_acl 0.4.8
|
||||
// Project: https://github.com/optimalbits/node_acl
|
||||
// Definitions by: Qubo <https://github.com/tkQubo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="bluebird" />
|
||||
/// <reference types="node"/>
|
||||
/// <reference types="express"/>
|
||||
|
||||
import http = require('http');
|
||||
import Promise = require("bluebird");
|
||||
import express = require("express");
|
||||
|
||||
type strings = string|string[];
|
||||
type Value = string|number;
|
||||
type Values = Value|Value[];
|
||||
type Action = () => any;
|
||||
type Callback = (err: Error) => any;
|
||||
type AnyCallback = (err: Error, obj: any) => any;
|
||||
type AllowedCallback = (err: Error, allowed: boolean) => any;
|
||||
type GetUserId = (req: http.IncomingMessage, res: http.ServerResponse) => Value;
|
||||
|
||||
interface AclStatic {
|
||||
new (backend: Backend<any>, logger: Logger, options: Option): Acl;
|
||||
new (backend: Backend<any>, logger: Logger): Acl;
|
||||
new (backend: Backend<any>): Acl;
|
||||
memoryBackend: MemoryBackendStatic;
|
||||
}
|
||||
|
||||
interface Logger {
|
||||
debug: (msg: string) => any;
|
||||
}
|
||||
|
||||
interface Acl {
|
||||
addUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
removeUserRoles: (userId: Value, roles: strings, cb?: Callback) => Promise<void>;
|
||||
userRoles: (userId: Value, cb?: (err: Error, roles: string[]) => any) => Promise<string[]>;
|
||||
roleUsers: (role: Value, cb?: (err: Error, users: Values) => any) => Promise<any>;
|
||||
hasRole: (userId: Value, role: string, cb?: (err: Error, isInRole: boolean) => any) => Promise<boolean>;
|
||||
addRoleParents: (role: string, parents: Values, cb?: Callback) => Promise<void>;
|
||||
removeRole: (role: string, cb?: Callback) => Promise<void>;
|
||||
removeResource: (resource: string, cb?: Callback) => Promise<void>;
|
||||
allow: {
|
||||
(roles: Values, resources: strings, permissions: strings, cb?: Callback): Promise<void>;
|
||||
(aclSets: AclSet | AclSet[]): Promise<void>;
|
||||
}
|
||||
removeAllow: (role: string, resources: strings, permissions: strings, cb?: Callback) => Promise<void>;
|
||||
removePermissions: (role: string, resources: strings, permissions: strings, cb?: Function) => Promise<void>;
|
||||
allowedPermissions: (userId: Value, resources: strings, cb?: AnyCallback) => Promise<void>;
|
||||
isAllowed: (userId: Value, resources: strings, permissions: strings, cb?: AllowedCallback) => Promise<boolean>;
|
||||
areAnyRolesAllowed: (roles: strings, resource: strings, permissions: strings, cb?: AllowedCallback) => Promise<any>;
|
||||
whatResources: (roles: strings, permissions: strings, cb?: AnyCallback) => Promise<any>;
|
||||
permittedResources: (roles: strings, permissions: strings, cb?: Function) => Promise<void>;
|
||||
middleware: (numPathComponents?: number, userId?: Value | GetUserId, actions?: strings) => express.RequestHandler;
|
||||
}
|
||||
|
||||
interface Option {
|
||||
buckets?: BucketsOption;
|
||||
}
|
||||
|
||||
interface BucketsOption {
|
||||
meta?: string;
|
||||
parents?: string;
|
||||
permissions?: string;
|
||||
resources?: string;
|
||||
roles?: string;
|
||||
users?: string;
|
||||
}
|
||||
|
||||
interface AclSet {
|
||||
roles: strings;
|
||||
allows: AclAllow[];
|
||||
}
|
||||
|
||||
interface AclAllow {
|
||||
resources: strings;
|
||||
permissions: strings;
|
||||
}
|
||||
|
||||
interface MemoryBackend extends Backend<Action[]> { }
|
||||
interface MemoryBackendStatic {
|
||||
new (): MemoryBackend;
|
||||
}
|
||||
|
||||
//
|
||||
// For internal use
|
||||
//
|
||||
interface Backend<T> {
|
||||
begin: () => T;
|
||||
end: (transaction: T, cb?: Action) => void;
|
||||
clean: (cb?: Action) => void;
|
||||
get: (bucket: string, key: Value, cb?: Action) => void;
|
||||
union: (bucket: string, keys: Value[], cb?: Action) => void;
|
||||
add: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
del: (transaction: T, bucket: string, keys: Value[]) => void;
|
||||
remove: (transaction: T, bucket: string, key: Value, values: Values) => void;
|
||||
|
||||
endAsync: Function; //TODO: Give more specific function signature
|
||||
getAsync: Function;
|
||||
cleanAsync: Function;
|
||||
unionAsync: Function;
|
||||
}
|
||||
|
||||
interface Contract {
|
||||
(args: IArguments): Contract | NoOp;
|
||||
debug: boolean;
|
||||
fulfilled: boolean;
|
||||
args: any[];
|
||||
checkedParams: string[];
|
||||
params: (...types: string[]) => Contract | NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
interface NoOp {
|
||||
params: (...types: string[]) => NoOp;
|
||||
end: () => void;
|
||||
}
|
||||
|
||||
// for redis backend
|
||||
import redis = require('redis');
|
||||
|
||||
interface AclStatic {
|
||||
redisBackend: RedisBackendStatic;
|
||||
}
|
||||
|
||||
interface RedisBackend extends Backend<redis.RedisClient> { }
|
||||
interface RedisBackendStatic {
|
||||
new (redis: redis.RedisClient, prefix: string): RedisBackend;
|
||||
new (redis: redis.RedisClient): RedisBackend;
|
||||
}
|
||||
|
||||
// for mongodb backend
|
||||
import mongo = require('mongodb');
|
||||
|
||||
interface AclStatic {
|
||||
mongodbBackend: MongodbBackendStatic;
|
||||
}
|
||||
|
||||
interface MongodbBackend extends Backend<Callback> { }
|
||||
interface MongodbBackendStatic {
|
||||
new (db: mongo.Db, prefix: string, useSingle: boolean): MongodbBackend;
|
||||
new (db: mongo.Db, prefix: string): MongodbBackend;
|
||||
new (db: mongo.Db): MongodbBackend;
|
||||
}
|
||||
|
||||
declare var _: AclStatic;
|
||||
export = _;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user