Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

update codemirror to 5.24.0 #13116

Merged
merged 13 commits into from
Feb 28, 2017
10 changes: 8 additions & 2 deletions src/extensions/default/CSSCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,16 @@ define(function (require, exports, module) {
}

// Helper function for testing cursor position
function fixPos(pos) {
if (!("sticky" in pos)) {
pos.sticky = null;
}
return pos;
}
function expectCursorAt(pos) {
var selection = testEditor.getSelection();
expect(selection.start).toEqual(selection.end);
expect(selection.start).toEqual(pos);
expect(fixPos(selection.start)).toEqual(fixPos(selection.end));
expect(fixPos(selection.start)).toEqual(fixPos(pos));
}

// Helper function to
Expand Down
10 changes: 8 additions & 2 deletions src/extensions/default/HTMLCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,16 @@ define(function (require, exports, module) {
}

// Helper function for testing cursor position
function fixPos(pos) {
if (!("sticky" in pos)) {
pos.sticky = null;
}
return pos;
}
function expectCursorAt(pos) {
var selection = testEditor.getSelection();
expect(selection.start).toEqual(selection.end);
expect(selection.start).toEqual(pos);
expect(fixPos(selection.start)).toEqual(fixPos(selection.end));
expect(fixPos(selection.start)).toEqual(fixPos(pos));
}

it("should insert =\"\" after attribute", function () {
Expand Down
10 changes: 9 additions & 1 deletion src/extensions/default/HtmlEntityCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ define(function (require, exports, module) {
HTMLEntityHints = require("main").SpecialCharHints,
defaultContent = require("text!unittest-files/default.html");

// Helper function for testing cursor position
function fixPos(pos) {
if (!("sticky" in pos)) {
pos.sticky = null;
}
return pos;
}

describe("HTML Entity Hinting", function () {

var testEditorAndDoc,
Expand Down Expand Up @@ -150,7 +158,7 @@ define(function (require, exports, module) {

var hints = expectHints(hintProvider);
hintProvider.insertHint(hints[0]);
expect(testEditorAndDoc.editor.getCursorPos()).toEqual({line: 17, ch: 23});
expect(fixPos(testEditorAndDoc.editor.getCursorPos())).toEqual(fixPos({line: 17, ch: 23}));
});
});
});
Expand Down
32 changes: 27 additions & 5 deletions src/extensions/default/InlineColorEditor/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ define(function (require, exports, module) {
ColorEditor = require("ColorEditor").ColorEditor,
tinycolor = require("thirdparty/tinycolor-min");

// Helper functions for testing cursor position / selection range
function fixPos(pos) {
if (!("sticky" in pos)) {
pos.sticky = null;
}
return pos;
}
function fixSel(sel) {
fixPos(sel.start);
fixPos(sel.end);
if (!("reversed" in sel)) {
sel.reversed = false;
}
return sel;
}
function fixSels(sels) {
sels.forEach(function (sel) {
fixSel(sel);
});
return sels;
}

describe("Inline Color Editor - unit", function () {

var testDocument, testEditor, inline;
Expand Down Expand Up @@ -217,7 +239,7 @@ define(function (require, exports, module) {
runs(function () {
testDocument.replaceRange("", {line: 1, ch: 22}, {line: 1, ch: 24});
inline.colorEditor.setColorFromString("#c0c0c0");
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}});
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}}));
expect(testDocument.getRange({line: 1, ch: 16}, {line: 1, ch: 23})).toBe("#c0c0c0");
});
});
Expand All @@ -236,7 +258,7 @@ define(function (require, exports, module) {
// TODO (#2201): this assumes getColor() is a tinycolor, but sometimes it's a string
expect(inline.colorEditor.getColor().toHexString().toLowerCase()).toBe("#a0cdef");
expect(inline.close).not.toHaveBeenCalled();
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}});
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}}));
});
});

Expand All @@ -260,7 +282,7 @@ define(function (require, exports, module) {
testDocument.replaceRange("0", {line: 1, ch: 22}, {line: 1, ch: 22});
expect(inline._color).toBe("#abcde0");
expect(inline.close).not.toHaveBeenCalled();
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}});
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 23}}));
});
});

Expand All @@ -269,7 +291,7 @@ define(function (require, exports, module) {
runs(function () {
testDocument.replaceRange("", {line: 1, ch: 22}, {line: 1, ch: 23});
expect(inline._color).toBe("#abcdef");
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}});
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}}));
});
});

Expand All @@ -278,7 +300,7 @@ define(function (require, exports, module) {
runs(function () {
testDocument.replaceRange("", {line: 1, ch: 22}, {line: 1, ch: 24});
expect(inline._color).toBe("#abcdef");
expect(inline.getCurrentRange()).toEqual({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}});
expect(fixSel(inline.getCurrentRange())).toEqual(fixSel({start: {line: 1, ch: 16}, end: {line: 1, ch: 22}}));
});
});

Expand Down
101 changes: 52 additions & 49 deletions src/extensions/default/JavaScriptCodeHints/ScopeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,65 +1169,68 @@ define(function (require, exports, module) {

ensurePreferences();
deferredPreferences.done(function () {
if (!file instanceof InMemoryFile) {
FileSystem.resolve(dir, function (err, directory) {
if (file instanceof InMemoryFile) {
initTernServer(pr, []);
var hintsPromise = primePump(path);
hintsPromise.done(function () {
addFilesDeferred.resolveWith(null, [_ternWorker]);
});
return;
}

FileSystem.resolve(dir, function (err, directory) {
if (err) {
console.error("Error resolving", dir);
addFilesDeferred.resolveWith(null);
return;
}

directory.getContents(function (err, contents) {
if (err) {
console.error("Error resolving", dir);
console.error("Error getting contents for", directory);
addFilesDeferred.resolveWith(null);
return;
}

directory.getContents(function (err, contents) {
if (err) {
console.error("Error getting contents for", directory);
addFilesDeferred.resolveWith(null);
return;
}
var files = contents
.filter(function (entry) {
return entry.isFile && !isFileExcluded(entry);
})
.map(function (entry) {
return entry.fullPath;
});

var files = contents
.filter(function (entry) {
return entry.isFile && !isFileExcluded(entry);
})
.map(function (entry) {
return entry.fullPath;
});
initTernServer(dir, files);

var hintsPromise = primePump(path);
hintsPromise.done(function () {
if (!usingModules()) {
// Read the subdirectories of the new file's directory.
// Read them first in case there are too many files to
// read in the project.
addAllFilesAndSubdirectories(dir, function () {
// If the file is in the project root, then read
// all the files under the project root.
var currentDir = (dir + "/");
if (projectRoot && currentDir !== projectRoot &&
currentDir.indexOf(projectRoot) === 0) {
addAllFilesAndSubdirectories(projectRoot, function () {
// prime the pump again but this time don't wait
// for completion.
primePump(path);

initTernServer(dir, files);

var hintsPromise = primePump(path);
hintsPromise.done(function () {
if (!usingModules()) {
// Read the subdirectories of the new file's directory.
// Read them first in case there are too many files to
// read in the project.
addAllFilesAndSubdirectories(dir, function () {
// If the file is in the project root, then read
// all the files under the project root.
var currentDir = (dir + "/");
if (projectRoot && currentDir !== projectRoot &&
currentDir.indexOf(projectRoot) === 0) {
addAllFilesAndSubdirectories(projectRoot, function () {
// prime the pump again but this time don't wait
// for completion.
primePump(path);

addFilesDeferred.resolveWith(null, [_ternWorker]);
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
} else {
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
});
} else {
initTernServer(pr, []);
primePump(path);
addFilesDeferred.resolveWith(null, [_ternWorker]);
}
});
});
}

Expand Down
25 changes: 17 additions & 8 deletions src/extensions/default/JavaScriptCodeHints/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ define(function (require, exports, module) {
});

describe("JavaScript Code Hinting", function () {

// Helper function for testing cursor position
function fixPos(pos) {
if (!("sticky" in pos)) {
pos.sticky = null;
}
return pos;
}

/*
* Ask provider for hints at current cursor position; expect it to
* return some
Expand Down Expand Up @@ -718,7 +727,7 @@ define(function (require, exports, module) {
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");

runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, end)).toEqual("A1.propA");
expect(testDoc.getLine(end.line).length).toEqual(8);
});
Expand All @@ -736,7 +745,7 @@ define(function (require, exports, module) {
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");

runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, endplus)).toEqual("A1.propAprop");
expect(testDoc.getLine(end.line).length).toEqual(12);
});
Expand All @@ -752,7 +761,7 @@ define(function (require, exports, module) {
var hintObj = expectHints(JSCodeHints.jsHintProvider);
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, end)).toEqual("A1.propA");
expect(testDoc.getLine(end.line).length).toEqual(8);
});
Expand All @@ -769,7 +778,7 @@ define(function (require, exports, module) {
var hintObj = expectHints(JSCodeHints.jsHintProvider);
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, endplus)).toEqual("A1.propApB");
expect(testDoc.getLine(end.line).length).toEqual(10);
});
Expand All @@ -787,7 +796,7 @@ define(function (require, exports, module) {
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");

runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, endplus)).toEqual("(A1.propAprop)");
expect(testDoc.getLine(endplus.line).length).toEqual(14);
});
Expand Down Expand Up @@ -1005,7 +1014,7 @@ define(function (require, exports, module) {
var hintObj = expectHints(JSCodeHints.jsHintProvider);
selectHint(JSCodeHints.jsHintProvider, hintObj, "my-key");
runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, end)).toEqual("arr[\"my-key\"]");
expect(testDoc.getLine(end.line).length).toEqual(13);
});
Expand All @@ -1021,7 +1030,7 @@ define(function (require, exports, module) {
var hintObj = expectHints(JSCodeHints.jsHintProvider);
selectHint(JSCodeHints.jsHintProvider, hintObj, "my-key");
runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, end)).toEqual("arr[\"my-key\"]");
expect(testDoc.getLine(end.line).length).toEqual(13);
});
Expand All @@ -1037,7 +1046,7 @@ define(function (require, exports, module) {
var hintObj = expectHints(JSCodeHints.jsHintProvider);
selectHint(JSCodeHints.jsHintProvider, hintObj, "for");
runs(function () {
expect(testEditor.getCursorPos()).toEqual(end);
expect(fixPos(testEditor.getCursorPos())).toEqual(fixPos(end));
expect(testDoc.getRange(start, end)).toEqual("arr.for");
expect(testDoc.getLine(end.line).length).toEqual(7);
});
Expand Down
14 changes: 11 additions & 3 deletions src/extensions/default/JavaScriptQuickEdit/unittests.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ define(function (require, exports, module) {
return result.promise();
}

// Helper function for testing cursor position
function fixPos(pos) {
if (!("sticky" in pos)) {
pos.sticky = null;
}
return pos;
}

/**
* Performs setup for an inline editor test. Parses offsets (saved to Spec.offsets) for all files in
* the test project (testPath) and saves files back to disk without offset markup.
Expand Down Expand Up @@ -237,7 +245,7 @@ define(function (require, exports, module) {
var inlinePos = inlineWidget.editor.getCursorPos();

// verify cursor position in inline editor
expect(inlinePos).toEqual(this.infos["test1inline.js"].offsets[0]);
expect(fixPos(inlinePos)).toEqual(fixPos(this.infos["test1inline.js"].offsets[0]));
});
});

Expand All @@ -249,7 +257,7 @@ define(function (require, exports, module) {
var inlinePos = inlineWidget.editor.getCursorPos();

// verify cursor position in inline editor
expect(inlinePos).toEqual(this.infos["test1inline.js"].offsets[1]);
expect(fixPos(inlinePos)).toEqual(fixPos(this.infos["test1inline.js"].offsets[1]));
});
});

Expand All @@ -261,7 +269,7 @@ define(function (require, exports, module) {
var inlinePos = inlineWidget.editor.getCursorPos();

// verify cursor position in inline editor
expect(inlinePos).toEqual(this.infos["test1inline.js"].offsets[2]);
expect(fixPos(inlinePos)).toEqual(fixPos(this.infos["test1inline.js"].offsets[2]));
});
});

Expand Down
Loading