mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge remote-tracking branch 'refs/remotes/DefinitelyTyped/master'
This commit is contained in:
+6
-1
@@ -9,7 +9,6 @@
|
||||
*.cs
|
||||
*.sln
|
||||
*.csproj
|
||||
*.txt
|
||||
*.map
|
||||
*.swp
|
||||
.DS_Store
|
||||
@@ -30,9 +29,15 @@ _infrastructure/tests/build
|
||||
*.iml
|
||||
*.js.map
|
||||
!*.js/
|
||||
!scripts/new-package.js
|
||||
!scripts/not-needed.js
|
||||
!scripts/lint.js
|
||||
|
||||
node_modules
|
||||
|
||||
.sublimets
|
||||
.settings/launch.json
|
||||
|
||||
.vs
|
||||
.vscode
|
||||
yarn.lock
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 4
|
||||
- 6.9.2
|
||||
|
||||
sudo: false
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/// <reference path="3d-bin-packing.d.ts" />
|
||||
|
||||
import packer = require("3d-bin-packing");
|
||||
import samchon = require("samchon-framework");
|
||||
|
||||
|
||||
Vendored
-1500
File diff suppressed because it is too large
Load Diff
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"
|
||||
]
|
||||
}
|
||||
+1
-1
@@ -1680,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,9 +0,0 @@
|
||||
/// <reference path="CybozuLabs-md5.d.ts" />
|
||||
|
||||
var hash: string;
|
||||
hash = CybozuLabs.MD5.calc("abc");
|
||||
hash = CybozuLabs.MD5.calc("abc", CybozuLabs.MD5.BY_ASCII);
|
||||
hash = CybozuLabs.MD5.calc("abc", CybozuLabs.MD5.BY_UTF16);
|
||||
|
||||
var version: string;
|
||||
version = CybozuLabs.MD5.VERSION;
|
||||
@@ -1,21 +0,0 @@
|
||||
/// <reference path="FileSaver.d.ts" />
|
||||
|
||||
import {saveAs as importedSaveAs} from "file-saver";
|
||||
function testImportedSaveAs() {
|
||||
var data: Blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
|
||||
var filename: string = 'hello world.txt';
|
||||
var disableAutoBOM = true;
|
||||
|
||||
importedSaveAs(data, filename, disableAutoBOM);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
-38
@@ -1,38 +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;
|
||||
|
||||
declare module "file-saver" {
|
||||
var fileSaver: { saveAs: typeof saveAs };
|
||||
export = 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
-29
@@ -1,29 +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;
|
||||
notBottom?:string;
|
||||
notTop?: string;
|
||||
pinned?: string;
|
||||
top?: string;
|
||||
unpinned?: 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,17 +1,27 @@
|
||||
Please fill in this template.
|
||||
|
||||
- [ ] Prefer to make your PR against the `types-2.0` branch.
|
||||
- [ ] Test the change in your own code.
|
||||
- [ ] Follow the advice from the [readme](https://github.com/DefinitelyTyped/DefinitelyTyped#make-a-pull-request).
|
||||
- [ ] Avoid [common mistakes](https://github.com/DefinitelyTyped/DefinitelyTyped#common-mistakes).
|
||||
- [ ] Run `npm run lint -- package-name` if a `tslint.json` is present.
|
||||
- [ ] 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.
|
||||
- [ ] Run `tsc` without errors.
|
||||
- [ ] Include the required [files](https://github.com/DefinitelyTyped/DefinitelyTyped#create-a-new-package) and header. Base these on the README, *not* on an existing project.
|
||||
- [ ] 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) => {});
|
||||
@@ -38,7 +38,7 @@ or just look for any ".d.ts" files in the package and manually include them with
|
||||
These can be used by TypeScript 1.0.
|
||||
|
||||
* [Typings](https://github.com/typings/typings)
|
||||
* [NuGet](http://nuget.org/Tpackages?q=DefinitelyTyped)
|
||||
* ~~[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).
|
||||
@@ -78,13 +78,7 @@ Once you've tested your definitions with real code, make a PR contributing the d
|
||||
|
||||
Once you've tested your package, you can share it on DefinitelyTyped.
|
||||
|
||||
First, [fork](https://guides.github.com/activities/forking/) this repository.
|
||||
Then inside your repository:
|
||||
|
||||
* `git checkout types-2.0`
|
||||
|
||||
New work should generally be done on the `types-2.0` branch.
|
||||
If you want your changes to be available to `typings` users, then you may edit `master` instead.
|
||||
First, [fork](https://guides.github.com/activities/forking/) this repository, install [node](https://nodejs.org/), and run `npm install`.
|
||||
|
||||
|
||||
#### Edit an existing package
|
||||
@@ -92,6 +86,7 @@ If you want your changes to be available to `typings` users, then you may edit `
|
||||
* `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.
|
||||
@@ -115,29 +110,25 @@ Your package should have this structure:
|
||||
| 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`.
|
||||
Generate these by running `npm run new-package -- --name my-package-name --template module`.
|
||||
(Other templates are `module-class`, `module-function`, `module-plugin`, `global`, `global-plugin`, and `global-modifying-module`.
|
||||
This just wraps [dts-gen](https://github.com/Microsoft/dts-gen), so it supports all options from that.)
|
||||
|
||||
You may edit the `tsconfig.json` to add new files or to add the `"jsx"` compiler option.
|
||||
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/types-2.0/base64-js).
|
||||
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. Also, always use semicolons, and use egyptian braces.
|
||||
* `interface X {}`: An empty interface is essentially the `{}` type: it places no constraints on an object.
|
||||
* `interface IFoo {}`: Don't add `I` to the front of an interface name.
|
||||
* 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.
|
||||
* `namespace foo {}`:
|
||||
Do not add a namespace just so that the `import * as foo` syntax will work.
|
||||
If it is commonJs module with a single export, you should use the `import foo = require("foo")` syntax.
|
||||
See more explanation [here](https://stackoverflow.com/questions/39415661/why-cant-i-import-a-class-or-function-with-import-as-x-from-y).
|
||||
* `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`.
|
||||
@@ -149,15 +140,16 @@ For a good example package, see [base64-js](https://github.com/DefinitelyTyped/D
|
||||
#### 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.
|
||||
Make a PR doing the following:
|
||||
* Delete the directory.
|
||||
* Add a new entry to `notNeededPackages.json`.
|
||||
- `libraryName`: Descriptive name of the library, e.g. "Angular 2" instead of "angular2". (May be identical to "typingsPackageName".)
|
||||
- `typingsPackageName`: This is the name of the directory you just deleted.
|
||||
- `sourceRepoURL`: This should point to the repository that contains the typings.
|
||||
- `asOfVersion`: A stub will be published to `@types/foo` with this version. Should be higher than any currently published version.
|
||||
* 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" }`.
|
||||
|
||||
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
|
||||
@@ -185,11 +177,9 @@ Test the linter by running `npm run lint -- package-name`. Do not use a globally
|
||||
|
||||
#### What exactly is the relationship between this repository and the `@types` packages on NPM?
|
||||
|
||||
The `types-2.0` branch is automatically published to the `@types` scope on NPM thanks to [types-publisher](https://github.com/Microsoft/types-publisher).
|
||||
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.
|
||||
|
||||
Changes to the `master` branch are also manually merged into the `types-2.0` branch, but this takes longer.
|
||||
|
||||
#### 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.
|
||||
@@ -203,23 +193,70 @@ If you're adding a new major version of a library, you can copy `index.d.ts` to
|
||||
#### 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/types-2.0/pikaday/package.json).
|
||||
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.
|
||||
|
||||
#### I notice some `tsconfig.json` are missing `"noImplicitAny": true` or `"strictNullChecks": true`.
|
||||
#### 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.
|
||||
|
||||
#### Definitions in types-2.0 seem written differently than in master.
|
||||
|
||||
If you're targeting types-2.0, write it like the types-2.0 definitions.
|
||||
If you're targeting master, we may change it to the new style when merging from master to types-2.0.
|
||||
|
||||
#### 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`.
|
||||
|
||||
|
||||
## 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;
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
import * as Ably from 'ably';
|
||||
|
||||
declare var console: { log(message: any): void };
|
||||
|
||||
const ApiKey = 'appId.keyId:secret';
|
||||
const client = new Ably.Realtime(ApiKey);
|
||||
const restClient = new Ably.Rest(ApiKey);
|
||||
|
||||
// Connection
|
||||
// Successful connection:
|
||||
|
||||
client.connection.on('connected', function() {
|
||||
// successful connection
|
||||
});
|
||||
|
||||
// Failed connection:
|
||||
|
||||
client.connection.on('failed', function() {
|
||||
// failed connection
|
||||
});
|
||||
|
||||
|
||||
// Subscribing to a channel
|
||||
|
||||
var channel = client.channels.get('test');
|
||||
channel.subscribe(function(message) {
|
||||
message.name; // 'greeting'
|
||||
message.data; // 'Hello World!'
|
||||
});
|
||||
|
||||
// Only certain events:
|
||||
|
||||
channel.subscribe('myEvent', function(message) {
|
||||
message.name; // 'myEvent'
|
||||
message.data; // 'myData'
|
||||
});
|
||||
|
||||
// Publishing to a channel
|
||||
|
||||
// Publish a single message with name and data
|
||||
channel.publish('greeting', 'Hello World!');
|
||||
|
||||
// Optionally, you can use a callback to be notified of success or failure
|
||||
channel.publish('greeting', 'Hello World!', function(err) {
|
||||
if(err) {
|
||||
console.log('publish failed with error ' + err);
|
||||
} else {
|
||||
console.log('publish succeeded');
|
||||
}
|
||||
})
|
||||
|
||||
// Publish several messages at once
|
||||
channel.publish([{name: 'greeting', data: 'Hello World!'}], function() { });
|
||||
|
||||
// Querying the History
|
||||
|
||||
channel.history(function(err, messagesPage) {
|
||||
messagesPage.items; // array of Message
|
||||
messagesPage.items[0].data; // payload for first message
|
||||
messagesPage.items.length; // number of messages in the current page of history
|
||||
messagesPage.hasNext(); // true if there are further pages
|
||||
messagesPage.isLast(); // true if this page is the last page
|
||||
messagesPage.next(function(nextPage) { nextPage; }); // retrieves the next page as PaginatedResult
|
||||
});
|
||||
|
||||
// Can optionally take an options param, see https://www.ably.io/documentation/rest-api/#message-history
|
||||
channel.history({ start: Date.now()-10000, end: Date.now(), limit: 100, direction: 'forwards'}, function(err, messagesPage) {
|
||||
console.log(messagesPage.items.length);
|
||||
});
|
||||
|
||||
|
||||
// Presence on a channel
|
||||
// Getting presence:
|
||||
|
||||
channel.presence.get(function(presenceSet) {
|
||||
presenceSet; // array of PresenceMessages
|
||||
});
|
||||
|
||||
// Note that presence#get on a realtime channel does not return a PaginatedResult, as the library maintains a local copy of the presence set.
|
||||
|
||||
// Entering (and leaving) the presence set:
|
||||
|
||||
channel.presence.enter('my status', function(err) {
|
||||
// now I am entered
|
||||
});
|
||||
|
||||
channel.presence.update('new status', function(err) {
|
||||
// my presence data is updated
|
||||
});
|
||||
|
||||
channel.presence.leave(null, function(err) {
|
||||
// I've left the presence set
|
||||
});
|
||||
|
||||
channel.presence.enterClient('myClientId', 'status', function(err) {
|
||||
});
|
||||
|
||||
// and similiarly, updateClient and leaveClient
|
||||
// Querying the Presence History
|
||||
|
||||
channel.presence.history(function(err, messagesPage) { // PaginatedResult
|
||||
messagesPage.items; // array of PresenceMessage
|
||||
messagesPage.items[0].data; // payload for first message
|
||||
messagesPage.items.length; // number of messages in the current page of history
|
||||
messagesPage.hasNext(); // true if there are further pages
|
||||
messagesPage.isLast(); // true if this page is the last page
|
||||
messagesPage.next(function(nextPage) { }); // retrieves the next page as PaginatedResult
|
||||
});
|
||||
|
||||
// Can optionally take an options param, see https://www.ably.io/documentation/rest-api/#message-history
|
||||
channel.history({ start: Date.now()-10000, end: Date.now(), limit: 100, direction: 'forwards' }, function(err, messagesPage) {});
|
||||
|
||||
// Symmetrical end-to-end encrypted payloads on a channel
|
||||
|
||||
// When a 128 bit or 256 bit key is provided to the library, the data attributes of all messages are encrypted and decrypted automatically using that key. The secret key is never transmitted to Ably. See https://www.ably.io/documentation/realtime/encryption
|
||||
|
||||
// Generate a random 256-bit key for demonstration purposes (in
|
||||
// practice you need to create one and distribute it to clients yourselves)
|
||||
Ably.Realtime.Crypto.generateRandomKey(function(err, key) {
|
||||
var channel = client.channels.get('channelName', { cipher: { key: key } });
|
||||
|
||||
channel.subscribe(function(message) {
|
||||
message.name; // 'name is not encrypted'
|
||||
message.data; // 'sensitive data is encrypted'
|
||||
});
|
||||
|
||||
channel.publish('name is not encrypted', 'sensitive data is encrypted');
|
||||
});
|
||||
|
||||
// You can also change the key on an existing channel using setOptions (which takes a callback which is called after the new encryption settings have taken effect):
|
||||
|
||||
channel.setOptions({cipher: {key: '<KEY>'}}, function() {
|
||||
// New encryption settings are in effect
|
||||
});
|
||||
|
||||
// Using the REST API
|
||||
|
||||
var restChannel = restClient.channels.get('test');
|
||||
|
||||
// Publishing to a channel
|
||||
|
||||
// Publish a single message with name and data
|
||||
restChannel.publish('greeting', 'Hello World!');
|
||||
|
||||
// Optionally, you can use a callback to be notified of success or failure
|
||||
restChannel.publish('greeting', 'Hello World!', function(err) {
|
||||
if(err) {
|
||||
console.log('publish failed with error ' + err);
|
||||
} else {
|
||||
console.log('publish succeeded');
|
||||
}
|
||||
})
|
||||
|
||||
// Publish several messages at once
|
||||
restChannel.publish([{name: 'greeting', data: 'Hello World!'}], function() {});
|
||||
|
||||
// Querying the History
|
||||
|
||||
restChannel.history(function(err, messagesPage) {
|
||||
messagesPage; // PaginatedResult
|
||||
messagesPage.items; // array of Message
|
||||
messagesPage.items[0].data; // payload for first message
|
||||
messagesPage.items.length; // number of messages in the current page of history
|
||||
messagesPage.hasNext(); // true if there are further pages
|
||||
messagesPage.isLast(); // true if this page is the last page
|
||||
messagesPage.next(function(nextPage) {}); // retrieves the next page as PaginatedResult
|
||||
});
|
||||
|
||||
// Can optionally take an options param, see https://www.ably.io/documentation/rest-api/#message-history
|
||||
restChannel.history({ start: Date.now()-10000, end: Date.now(), limit: 100, direction: 'forwards' }, function(err, messagesPage) {});
|
||||
|
||||
// Presence on a channel
|
||||
|
||||
restChannel.presence.get(function(err, presencePage) { // PaginatedResult
|
||||
presencePage.items; // array of PresenceMessage
|
||||
presencePage.items[0].data; // payload for first message
|
||||
presencePage.items.length; // number of messages in the current page of members
|
||||
presencePage.hasNext(); // true if there are further pages
|
||||
presencePage.isLast(); // true if this page is the last page
|
||||
presencePage.next(function(nextPage) {}); // retrieves the next page as PaginatedResult
|
||||
});
|
||||
|
||||
// Querying the Presence History
|
||||
|
||||
restChannel.presence.history(function(err, messagesPage) { // PaginatedResult
|
||||
messagesPage.items; // array of PresenceMessage
|
||||
messagesPage.items[0].data; // payload for first message
|
||||
messagesPage.items.length; // number of messages in the current page of history
|
||||
messagesPage.hasNext(); // true if there are further pages
|
||||
messagesPage.isLast(); // true if this page is the last page
|
||||
messagesPage.next(function(nextPage) { }); // retrieves the next page as PaginatedResult
|
||||
});
|
||||
|
||||
// Can optionally take an options param, see https://www.ably.io/documentation/rest-api/#message-history
|
||||
restChannel.history({ start: Date.now()-10000, end: Date.now(), limit: 100, direction: 'forwards' }, function(err, messagesPage) {});
|
||||
|
||||
|
||||
// Generate Token and Token Request
|
||||
// See https://www.ably.io/documentation/general/authentication for an explanation of Ably's authentication mechanism.
|
||||
|
||||
// Requesting a token:
|
||||
|
||||
client.auth.requestToken(function(err, tokenDetails) {
|
||||
// tokenDetails is instance of TokenDetails
|
||||
// see https://www.ably.io/documentation/rest/authentication/#token-details for its properties
|
||||
|
||||
// Now we have the token, we can send it to someone who can instantiate a client with it:
|
||||
var clientUsingToken = new Ably.Realtime(tokenDetails.token);
|
||||
});
|
||||
|
||||
// requestToken can take two optional params
|
||||
// tokenParams: https://www.ably.io/documentation/rest/authentication/#token-params
|
||||
// authOptions: https://www.ably.io/documentation/rest/authentication/#auth-options
|
||||
client.auth.requestToken({}, {}, function(err, tokenDetails) { });
|
||||
|
||||
// Creating a token request (for example, on a server in response to a request by a client using the authCallback or authUrl mechanisms):
|
||||
|
||||
client.auth.createTokenRequest(function(err, tokenRequest) {
|
||||
// now send the tokenRequest back to the client, which will
|
||||
// use it to request a token and connect to Ably
|
||||
});
|
||||
|
||||
// createTokenRequest can take two optional params
|
||||
// tokenParams: https://www.ably.io/documentation/rest/authentication/#token-params
|
||||
// authOptions: https://www.ably.io/documentation/rest/authentication/#auth-options
|
||||
client.auth.createTokenRequest({}, {}, function(err, tokenRequest) { });
|
||||
|
||||
// Fetching your application's stats
|
||||
|
||||
client.stats({ limit: 50 }, function(err, statsPage) { // statsPage as PaginatedResult
|
||||
statsPage.items; // array of Stats
|
||||
statsPage.items[0].inbound.rest.messages.count; // total messages published over REST
|
||||
statsPage.items.length; // number of stats in the current page of history
|
||||
statsPage.hasNext(); // true if there are further pages
|
||||
statsPage.isLast(); // true if this page is the last page
|
||||
statsPage.next(function(nextPage) {}); // retrieves the next page as PaginatedResult
|
||||
});
|
||||
|
||||
// Fetching the Ably service time
|
||||
|
||||
client.time({}, function(err, time) {}); // time is in ms since epoch
|
||||
|
||||
// Getting decoded Message objects from JSON
|
||||
var messages = Ably.Realtime.Message.fromEncodedArray([{ id: 'foo' }]);
|
||||
console.log(messages[0].id);
|
||||
|
||||
var message = Ably.Rest.Message.fromEncoded({ id: 'foo' });
|
||||
console.log(message.id);
|
||||
|
||||
// Getting decoded PresenceMessage objects from JSON
|
||||
var presenceMessages = Ably.Realtime.PresenceMessage.fromEncodedArray([{ id: 'foo' }]);
|
||||
console.log(presenceMessages[0].action);
|
||||
|
||||
var presenceMessage = Ably.Rest.PresenceMessage.fromEncoded({ id: 'foo' });
|
||||
console.log(presenceMessage.action);
|
||||
Vendored
+471
@@ -0,0 +1,471 @@
|
||||
// Type definitions for Ably Realtime and Rest client library 0.9
|
||||
// Project: https://www.ably.io/
|
||||
// Definitions by: Ably <https://github.com/ably/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace ablyLib {
|
||||
namespace ChannelState {
|
||||
type INITIALIZED = 'initialized';
|
||||
type ATTACHING = 'attaching';
|
||||
type ATTACHED = "attached";
|
||||
type DETACHING = "detaching";
|
||||
type DETACHED = "detached";
|
||||
type SUSPENDED = "suspended";
|
||||
type FAILED = "failed";
|
||||
}
|
||||
type ChannelState = ChannelState.FAILED | ChannelState.INITIALIZED | ChannelState.SUSPENDED | ChannelState.ATTACHED | ChannelState.ATTACHING | ChannelState.DETACHED | ChannelState.DETACHING;
|
||||
|
||||
namespace ConnectionState {
|
||||
type INITIALIZED = "initialized";
|
||||
type CONNECTING = "connecting";
|
||||
type CONNECTED = "connected";
|
||||
type DISCONNECTED = "disconnected";
|
||||
type SUSPENDED = "suspended";
|
||||
type CLOSING = "closing";
|
||||
type CLOSED = "closed";
|
||||
type FAILED = "failed";
|
||||
}
|
||||
type ConnectionState = ConnectionState.INITIALIZED | ConnectionState.CONNECTED | ConnectionState.CONNECTING | ConnectionState.DISCONNECTED | ConnectionState.SUSPENDED | ConnectionState.CLOSED | ConnectionState.CLOSING | ConnectionState.FAILED;
|
||||
|
||||
namespace ConnectionEvent {
|
||||
type INITIALIZED = "initialized";
|
||||
type CONNECTING = "connecting";
|
||||
type CONNECTED = "connected";
|
||||
type DISCONNECTED = "disconnected";
|
||||
type SUSPENDED = "suspended";
|
||||
type CLOSING = "closing";
|
||||
type CLOSED = "closed";
|
||||
type FAILED = "failed";
|
||||
type UPDATE = "update";
|
||||
}
|
||||
type ConnectionEvent = ConnectionEvent.INITIALIZED | ConnectionEvent.CONNECTED | ConnectionEvent.CONNECTING | ConnectionEvent.DISCONNECTED | ConnectionEvent.SUSPENDED | ConnectionEvent.CLOSED | ConnectionEvent.CLOSING | ConnectionEvent.FAILED | ConnectionEvent.UPDATE;
|
||||
|
||||
namespace PresenceAction {
|
||||
type ABSENT = "absent";
|
||||
type PRESENT = "present";
|
||||
type ENTER = "enter";
|
||||
type LEAVE = "leave";
|
||||
type UPDATE = "update";
|
||||
}
|
||||
type PresenceAction = PresenceAction.ABSENT | PresenceAction.PRESENT | PresenceAction.ENTER | PresenceAction.LEAVE | PresenceAction.UPDATE;
|
||||
|
||||
namespace StatsIntervalGranularity {
|
||||
type MINUTE = "minute";
|
||||
type HOUR = "hour";
|
||||
type DAY = "day";
|
||||
type MONTH = "month";
|
||||
}
|
||||
type StatsIntervalGranularity = StatsIntervalGranularity.MINUTE | StatsIntervalGranularity.HOUR | StatsIntervalGranularity.DAY | StatsIntervalGranularity.MONTH;
|
||||
|
||||
namespace HTTPMethods {
|
||||
type POST = "POST";
|
||||
type GET = "GET";
|
||||
}
|
||||
type HTTPMethods = HTTPMethods.GET | HTTPMethods.POST;
|
||||
|
||||
// Interfaces
|
||||
interface ClientOptions extends AuthOptions {
|
||||
/**
|
||||
* When true will automatically connect to Ably when library is instanced. This is true by default
|
||||
*/
|
||||
autoConnect?: boolean;
|
||||
|
||||
/**
|
||||
* Optional clientId that can be used to specify the identity for this client. In most cases
|
||||
* it is preferable to instead specift a clientId in the token issued to this client.
|
||||
*/
|
||||
clientId?: string;
|
||||
|
||||
defaultTokenParams?: TokenParams;
|
||||
|
||||
/**
|
||||
* When true, messages published on channels by this client will be echoed back to this client.
|
||||
* This is true by default
|
||||
*/
|
||||
echoMessages?: boolean;
|
||||
|
||||
/**
|
||||
* Use this only if you have been provided a dedicated environment by Ably
|
||||
*/
|
||||
environment?: string;
|
||||
|
||||
/**
|
||||
* Logger configuration
|
||||
*/
|
||||
log?: LogInfo;
|
||||
port?: number;
|
||||
|
||||
/**
|
||||
* When true, messages will be queued whilst the connection is disconnected. True by default.
|
||||
*/
|
||||
queueMessages?: boolean;
|
||||
|
||||
restHost?: string;
|
||||
realtimeHost?: string;
|
||||
fallbackHosts?: string[];
|
||||
|
||||
/**
|
||||
* Can be used to explicitly recover a connection.
|
||||
* See https://www.ably.io/documentation/realtime/connection#connection-state-recovery
|
||||
*/
|
||||
recover?: standardCallback | string;
|
||||
|
||||
/**
|
||||
* Use a non-secure connection connection. By default, a TLS connection is used to connect to Ably
|
||||
*/
|
||||
tls?: boolean;
|
||||
tlsPort?: number;
|
||||
|
||||
/**
|
||||
* When true, the more efficient MsgPack binary encoding is used.
|
||||
* When false, JSON text encoding is used.
|
||||
*/
|
||||
useBinaryProtocol?: boolean;
|
||||
}
|
||||
|
||||
interface AuthOptions {
|
||||
/**
|
||||
* A function which is called when a new token is required.
|
||||
* The role of the callback is to either generate a signed TokenRequest which may then be submitted automatically
|
||||
* by the library to the Ably REST API requestToken; or to provide a valid token in as a TokenDetails object.
|
||||
**/
|
||||
authCallback?: (data: TokenParams, callback: (error: ErrorInfo | string, tokenRequestOrDetails: TokenDetails | TokenRequest | string) => void) => void;
|
||||
authHeaders?: { [index: string]: string };
|
||||
authMethod?: HTTPMethods;
|
||||
authParams?: { [index: string]: string };
|
||||
|
||||
/**
|
||||
* A URL that the library may use to obtain a token string (in plain text format), or a signed TokenRequest or TokenDetails (in JSON format).
|
||||
**/
|
||||
authUrl?: string;
|
||||
key?: string;
|
||||
queryTime?: boolean;
|
||||
token?: TokenDetails | string;
|
||||
tokenDetails?: TokenDetails;
|
||||
useTokenAuth?: boolean;
|
||||
}
|
||||
|
||||
interface TokenParams {
|
||||
capability?: string;
|
||||
clientId?: string;
|
||||
nonce?: string;
|
||||
timestamp?: number;
|
||||
ttl?: number;
|
||||
}
|
||||
|
||||
interface CipherParams {
|
||||
algorithm: string;
|
||||
key: any;
|
||||
keyLength: number;
|
||||
mode: string;
|
||||
}
|
||||
|
||||
interface ErrorInfo {
|
||||
code: number;
|
||||
message: string;
|
||||
statusCode: number;
|
||||
}
|
||||
|
||||
interface StatsMessageCount {
|
||||
count: number;
|
||||
data: number;
|
||||
}
|
||||
|
||||
interface StatsMessageTypes {
|
||||
all: StatsMessageCount;
|
||||
messages: StatsMessageCount;
|
||||
presence: StatsMessageCount;
|
||||
}
|
||||
|
||||
interface StatsRequestCount {
|
||||
failed: number;
|
||||
refused: number;
|
||||
succeeded: number;
|
||||
}
|
||||
|
||||
interface StatsResourceCount {
|
||||
mean: number;
|
||||
min: number;
|
||||
opened: number;
|
||||
peak: number;
|
||||
refused: number;
|
||||
}
|
||||
|
||||
interface StatsConnectionTypes {
|
||||
all: StatsResourceCount;
|
||||
plain: StatsResourceCount;
|
||||
tls: StatsResourceCount;
|
||||
}
|
||||
|
||||
interface StatsMessageTraffic {
|
||||
all: StatsMessageTypes;
|
||||
realtime: StatsMessageTypes;
|
||||
rest: StatsMessageTypes;
|
||||
webhook: StatsMessageTypes;
|
||||
}
|
||||
|
||||
interface TokenDetails {
|
||||
capability: string;
|
||||
clientId?: string;
|
||||
expires: number;
|
||||
issued: number;
|
||||
token: string;
|
||||
}
|
||||
|
||||
interface TokenRequest {
|
||||
capability: string;
|
||||
clientId?: string;
|
||||
keyName: string;
|
||||
mac: string;
|
||||
nonce: string;
|
||||
timestamp: number;
|
||||
ttl?: number;
|
||||
}
|
||||
|
||||
interface ChannelOptions {
|
||||
cipher: any;
|
||||
}
|
||||
|
||||
interface RestPresenceHistoryParams {
|
||||
start?: number;
|
||||
end?: number;
|
||||
direction?: string;
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
interface RestPresenceParams {
|
||||
limit?: number;
|
||||
clientId?: string;
|
||||
connectionId?: string;
|
||||
}
|
||||
|
||||
interface RealtimePresenceParams {
|
||||
waitForSync?: boolean;
|
||||
clientId?: string;
|
||||
connectionId?: string;
|
||||
}
|
||||
|
||||
interface RealtimePresenceHistoryParams {
|
||||
start?: number;
|
||||
end?: number;
|
||||
direction?: string;
|
||||
limit?: number;
|
||||
untilAttach?: boolean;
|
||||
}
|
||||
|
||||
interface LogInfo {
|
||||
/**
|
||||
* A number controlling the verbosity of the output. Valid values are: 0 (no logs), 1 (errors only),
|
||||
* 2 (errors plus connection and channel state changes), 3 (high-level debug output), and 4 (full debug output).
|
||||
**/
|
||||
level?: number;
|
||||
|
||||
/**
|
||||
* A function to handle each line of log output. If handler is not specified, console.log is used.
|
||||
**/
|
||||
handler?: (...args: any[]) => void;
|
||||
}
|
||||
|
||||
interface ChannelEvent {
|
||||
state: ChannelState;
|
||||
}
|
||||
|
||||
interface ChannelStateChange {
|
||||
current: ChannelState;
|
||||
previous: ChannelState;
|
||||
reason?: ErrorInfo;
|
||||
resumed: boolean;
|
||||
}
|
||||
|
||||
interface ConnectionStateChange {
|
||||
current: ConnectionState;
|
||||
previous: ConnectionState;
|
||||
reason?: ErrorInfo;
|
||||
retryIn?: number;
|
||||
}
|
||||
|
||||
// Common Listeners
|
||||
type paginatedResultCallback<T> = (error: ErrorInfo, results: PaginatedResult<T> ) => void;
|
||||
type standardCallback = (error: ErrorInfo, results: any) => void;
|
||||
type messageCallback<T> = (message: T) => void;
|
||||
type errorCallback = (error: ErrorInfo) => void;
|
||||
type channelEventCallback = (channelEvent: ChannelEvent, changeStateChange: ChannelStateChange) => void;
|
||||
type connectionEventCallback = (connectionEvent: ConnectionEvent, connectionStateChange: ConnectionStateChange) => void;
|
||||
type timeCallback = (error: ErrorInfo, time: number) => void;
|
||||
type realtimePresenceGetCallback = (error: ErrorInfo, messages: PresenceMessage[]) => void;
|
||||
type tokenDetailsCallback = (error: ErrorInfo, Results: TokenDetails) => void;
|
||||
type tokenRequestCallback = (error: ErrorInfo, Results: TokenRequest) => void;
|
||||
type fromEncoded<T> = (JsonObject: any, channelOptions?: ChannelOptions) => T;
|
||||
type fromEncodedArray<T> = (JsonArray: any[], channelOptions?: ChannelOptions) => T[];
|
||||
|
||||
// Internal Classes
|
||||
class EventEmitter<T> {
|
||||
on: (eventOrCallback: string | T, callback?: T) => void;
|
||||
once: (eventOrCallback: string | T, callback?: T) => void;
|
||||
off: (eventOrCallback?: string | T, callback?: T) => void;
|
||||
}
|
||||
|
||||
// Classes
|
||||
class Auth {
|
||||
clientId: string;
|
||||
authorize: (tokenParams?: TokenParams | tokenDetailsCallback, authOptions?: AuthOptions | tokenDetailsCallback, callback?: tokenDetailsCallback) => void;
|
||||
createTokenRequest: (tokenParams?: TokenParams | tokenRequestCallback, authOptions?: AuthOptions | tokenRequestCallback, callback?: tokenRequestCallback) => void;
|
||||
requestToken: (TokenParams?: TokenParams | tokenDetailsCallback, authOptions?: AuthOptions | tokenDetailsCallback, callback?: tokenDetailsCallback) => void;
|
||||
}
|
||||
|
||||
class Presence {
|
||||
get: (params: RestPresenceParams | paginatedResultCallback<PresenceMessage>, callback?: paginatedResultCallback<PresenceMessage>) => void;
|
||||
history: (params: RestPresenceHistoryParams | paginatedResultCallback<PresenceMessage>, callback?: paginatedResultCallback<PresenceMessage>) => void;
|
||||
}
|
||||
|
||||
class RealtimePresence {
|
||||
syncComplete: () => boolean;
|
||||
get: (Params: realtimePresenceGetCallback | RealtimePresenceParams, callback?: realtimePresenceGetCallback) => void;
|
||||
history: (ParamsOrCallback: RealtimePresenceHistoryParams | paginatedResultCallback<PresenceMessage>, callback?: paginatedResultCallback<PresenceMessage>) => void;
|
||||
subscribe: (presenceOrCallback: PresenceAction | messageCallback<PresenceMessage>, listener?: messageCallback<PresenceMessage>) => void;
|
||||
unsubscribe: (presence?: PresenceAction, listener?: messageCallback<PresenceMessage>) => void;
|
||||
enter: (data?: errorCallback | any, callback?: errorCallback) => void;
|
||||
update: (data?: errorCallback | any, callback?: errorCallback) => void;
|
||||
leave: (data?: errorCallback | any, callback?: errorCallback) => void;
|
||||
enterClient: (clientId: string, data?: errorCallback | any, callback?: errorCallback) => void;
|
||||
updateClient: (clientId: string, data?: errorCallback | any, callback?: errorCallback) => void;
|
||||
leaveClient: (clientId: string, data?: errorCallback | any, callback?: errorCallback) => void;
|
||||
}
|
||||
|
||||
class Channel {
|
||||
name: string;
|
||||
presence: Presence;
|
||||
history: (paramsOrCallback?: RestPresenceHistoryParams | paginatedResultCallback<Message>, callback?: paginatedResultCallback<Message>) => void;
|
||||
publish: (messagesOrName: any, messagedataOrCallback?: errorCallback | any, callback?: errorCallback) => void;
|
||||
}
|
||||
|
||||
class RealtimeChannel extends EventEmitter<channelEventCallback> {
|
||||
name: string;
|
||||
errorReason: ErrorInfo;
|
||||
state: ChannelState;
|
||||
presence: RealtimePresence;
|
||||
attach: (callback?: standardCallback) => void;
|
||||
detach: (callback?: standardCallback) => void;
|
||||
history: (paramsOrCallback?: RealtimePresenceHistoryParams | paginatedResultCallback<Message>, callback?: paginatedResultCallback<Message>) => void;
|
||||
subscribe: (eventOrCallback: messageCallback<Message> | string, listener?: messageCallback<Message>) => void;
|
||||
unsubscribe: (eventOrCallback?: messageCallback<Message> | string, listener?: messageCallback<Message>) => void;
|
||||
publish: (messagesOrName: any, messageDataOrCallback?: errorCallback | any, callback?: errorCallback) => void;
|
||||
setOptions: (options: any, callback?: errorCallback) => void;
|
||||
}
|
||||
|
||||
class Channels<T> {
|
||||
get: (name: string, channelOptions?: ChannelOptions) => T;
|
||||
release: (name: string) => void;
|
||||
}
|
||||
|
||||
class Message {
|
||||
constructor();
|
||||
static fromEncoded: fromEncoded<Message>;
|
||||
static fromEncodedArray: fromEncodedArray<Message>;
|
||||
clientId: string;
|
||||
connectionId: string;
|
||||
data: any;
|
||||
encoding: string;
|
||||
extras: any;
|
||||
id: string;
|
||||
name: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
interface MessageStatic {
|
||||
fromEncoded: fromEncoded<Message>;
|
||||
fromEncodedArray: fromEncodedArray<Message>;
|
||||
}
|
||||
|
||||
class PresenceMessage {
|
||||
constructor();
|
||||
static fromEncoded: fromEncoded<PresenceMessage>;
|
||||
static fromEncodedArray: fromEncodedArray<PresenceMessage>;
|
||||
action: PresenceAction;
|
||||
clientId: string;
|
||||
connectionId: string;
|
||||
data: any;
|
||||
encoding: string;
|
||||
id: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
interface PresenceMessageStatic {
|
||||
fromEncoded: fromEncoded<PresenceMessage>;
|
||||
fromEncodedArray: fromEncodedArray<PresenceMessage>;
|
||||
}
|
||||
|
||||
interface Crypto {
|
||||
generateRandomKey: (callback: (error: ErrorInfo, key: string) => void) => void;
|
||||
}
|
||||
|
||||
class Connection extends EventEmitter<connectionEventCallback> {
|
||||
errorReason: ErrorInfo;
|
||||
id: string;
|
||||
key: string;
|
||||
recoveryKey: string;
|
||||
serial: number;
|
||||
state: ConnectionState;
|
||||
close: () => void;
|
||||
connect: () => void;
|
||||
ping: (callback?: (error: ErrorInfo, responseTime: number ) => void ) => void;
|
||||
}
|
||||
|
||||
class Stats {
|
||||
all: StatsMessageTypes;
|
||||
apiRequests: StatsRequestCount;
|
||||
channels: StatsResourceCount;
|
||||
connections: StatsConnectionTypes;
|
||||
inbound: StatsMessageTraffic;
|
||||
intervalId: string;
|
||||
outbound: StatsMessageTraffic;
|
||||
persisted: StatsMessageTypes;
|
||||
tokenRequests: StatsRequestCount;
|
||||
}
|
||||
|
||||
class PaginatedResult<T> {
|
||||
items: T[];
|
||||
first: (results: paginatedResultCallback<T>) => void;
|
||||
next: (results: paginatedResultCallback<T>) => void;
|
||||
current: (results: paginatedResultCallback<T>) => void;
|
||||
hasNext: () => boolean;
|
||||
isLast: () => boolean;
|
||||
}
|
||||
|
||||
class HttpPaginatedResponse extends PaginatedResult<any> {
|
||||
items: string[];
|
||||
statusCode: number;
|
||||
success: boolean;
|
||||
errorCode: number;
|
||||
errorMessage: string;
|
||||
headers: any;
|
||||
}
|
||||
}
|
||||
|
||||
export declare class Rest {
|
||||
constructor(options: ablyLib.ClientOptions | string);
|
||||
static Crypto: ablyLib.Crypto;
|
||||
static Message: ablyLib.MessageStatic;
|
||||
static PresenceMessage: ablyLib.PresenceMessageStatic;
|
||||
auth: ablyLib.Auth;
|
||||
channels: ablyLib.Channels<ablyLib.Channel>;
|
||||
request: (method: string, path: string, params?: any, body?: any[] | any, headers?: any, callback?: (error: ablyLib.ErrorInfo, response: ablyLib.HttpPaginatedResponse) => void) => void;
|
||||
stats: (paramsOrCallback?: ablyLib.paginatedResultCallback<ablyLib.Stats> | any, callback?: ablyLib.paginatedResultCallback<ablyLib.Stats>) => void;
|
||||
time: (paramsOrCallback?: ablyLib.timeCallback | any, callback?: ablyLib.timeCallback) => void;
|
||||
}
|
||||
|
||||
export declare class Realtime {
|
||||
constructor(options: ablyLib.ClientOptions | string);
|
||||
static Crypto: ablyLib.Crypto;
|
||||
static Message: ablyLib.MessageStatic;
|
||||
static PresenceMessage: ablyLib.PresenceMessageStatic;
|
||||
auth: ablyLib.Auth;
|
||||
channels: ablyLib.Channels<ablyLib.RealtimeChannel>;
|
||||
clientId: string;
|
||||
connection: ablyLib.Connection;
|
||||
request: (method: string, path: string, params?: any, body?: any[] | any, headers?: any, callback?: (error: ablyLib.ErrorInfo, response: ablyLib.HttpPaginatedResponse) => void) => void;
|
||||
stats: (paramsOrCallback?: ablyLib.paginatedResultCallback<ablyLib.Stats> | any, callback?: ablyLib.paginatedResultCallback<ablyLib.Stats>) => void;
|
||||
close: () => void;
|
||||
connect: () => void;
|
||||
time: (paramsOrCallback?: ablyLib.timeCallback | any, callback?: ablyLib.timeCallback) => void;
|
||||
}
|
||||
@@ -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",
|
||||
"ably-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
+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" }
|
||||
@@ -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
@@ -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,454 +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.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);
|
||||
@@ -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']);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user