Merge branch 'master' of github.com:ajaxorg/ace
This commit is contained in:
commit
8f005b9ed5
8 changed files with 330 additions and 16 deletions
|
|
@ -94,22 +94,25 @@ var Mode = function() {
|
||||||
var startOuter = selection.start.column - 1;
|
var startOuter = selection.start.column - 1;
|
||||||
var endOuter = selection.end.column + 1;
|
var endOuter = selection.end.column + 1;
|
||||||
var line = session.getLine(selection.start.row);
|
var line = session.getLine(selection.start.row);
|
||||||
var lineCols = line.length - 1;
|
var lineCols = line.length;
|
||||||
var needle = line.substring(Math.max(startOuter, 0),
|
var needle = line.substring(Math.max(startOuter, 0),
|
||||||
Math.min(endOuter, lineCols));
|
Math.min(endOuter, lineCols));
|
||||||
|
|
||||||
// Make sure the outer characters are not part of the word.
|
// Make sure the outer characters are not part of the word.
|
||||||
if ((startOuter >= 0 && !/[^\w\d]/.test(needle.charAt(0))) ||
|
if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
|
||||||
(endOuter <= lineCols && !/[^\w\d]/.test(needle.charAt(needle.length - 1))))
|
(endOuter <= lineCols && /[\w\d]$/.test(needle)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
needle = line.substring(selection.start.column, selection.end.column);
|
needle = line.substring(selection.start.column, selection.end.column);
|
||||||
if (!/^[\w\d]+$/.test(needle))
|
if (!/^[\w\d]+$/.test(needle))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
var cursor = editor.getCursorPosition();
|
||||||
|
|
||||||
var newOptions = {
|
var newOptions = {
|
||||||
wrap: true,
|
wrap: true,
|
||||||
wholeWord: true,
|
wholeWord: true,
|
||||||
|
caseSensitive: true,
|
||||||
needle: needle
|
needle: needle
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -117,9 +120,8 @@ var Mode = function() {
|
||||||
editor.$search.set(newOptions);
|
editor.$search.set(newOptions);
|
||||||
|
|
||||||
var ranges = editor.$search.findAll(session);
|
var ranges = editor.$search.findAll(session);
|
||||||
session.$selectionOccurrences = [];
|
|
||||||
ranges.forEach(function(range) {
|
ranges.forEach(function(range) {
|
||||||
if (!range.contains(selection.start.row, selection.start.column)) {
|
if (!range.contains(cursor.row, cursor.column)) {
|
||||||
var marker = session.addMarker(range, "ace_selected_word");
|
var marker = session.addMarker(range, "ace_selected_word");
|
||||||
session.$selectionOccurrences.push(marker);
|
session.$selectionOccurrences.push(marker);
|
||||||
}
|
}
|
||||||
|
|
@ -135,6 +137,8 @@ var Mode = function() {
|
||||||
editor.session.$selectionOccurrences.forEach(function(marker) {
|
editor.session.$selectionOccurrences.forEach(function(marker) {
|
||||||
editor.session.removeMarker(marker);
|
editor.session.removeMarker(marker);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
editor.session.$selectionOccurrences = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
}).call(Mode.prototype);
|
}).call(Mode.prototype);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
/* ***** BEGIN LICENSE BLOCK *****
|
/* vim:ts=4:sts=4:sw=4:
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
*
|
*
|
||||||
* The contents of this file are subject to the Mozilla Public License Version
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
|
@ -20,6 +21,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
|
* Mihai Sucan <mihai DOT sucan AT gmail DOT com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
|
@ -219,12 +221,16 @@ Search.SELECTION = 2;
|
||||||
var lastRow = searchSelection ? range.end.row : session.getLength() - 1;
|
var lastRow = searchSelection ? range.end.row : session.getLength() - 1;
|
||||||
|
|
||||||
var wrap = this.$options.wrap;
|
var wrap = this.$options.wrap;
|
||||||
|
var inWrap = false;
|
||||||
|
|
||||||
function getLine(row) {
|
function getLine(row) {
|
||||||
var line = session.getLine(row);
|
var line = session.getLine(row);
|
||||||
if (searchSelection && row == range.end.row) {
|
if (searchSelection && row == range.end.row) {
|
||||||
line = line.substring(0, range.end.column);
|
line = line.substring(0, range.end.column);
|
||||||
}
|
}
|
||||||
|
if (inWrap && row == start.row) {
|
||||||
|
line = line.substring(0, start.column);
|
||||||
|
}
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -236,6 +242,7 @@ Search.SELECTION = 2;
|
||||||
var startIndex = start.column;
|
var startIndex = start.column;
|
||||||
|
|
||||||
var stop = false;
|
var stop = false;
|
||||||
|
inWrap = false;
|
||||||
|
|
||||||
while (!callback(line, startIndex, row)) {
|
while (!callback(line, startIndex, row)) {
|
||||||
|
|
||||||
|
|
@ -250,6 +257,7 @@ Search.SELECTION = 2;
|
||||||
if (wrap) {
|
if (wrap) {
|
||||||
row = firstRow;
|
row = firstRow;
|
||||||
startIndex = firstColumn;
|
startIndex = firstColumn;
|
||||||
|
inWrap = true;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -283,6 +291,7 @@ Search.SELECTION = 2;
|
||||||
var line = session.getLine(row).substring(0, start.column);
|
var line = session.getLine(row).substring(0, start.column);
|
||||||
var startIndex = 0;
|
var startIndex = 0;
|
||||||
var stop = false;
|
var stop = false;
|
||||||
|
var inWrap = false;
|
||||||
|
|
||||||
while (!callback(line, startIndex, row)) {
|
while (!callback(line, startIndex, row)) {
|
||||||
|
|
||||||
|
|
@ -295,6 +304,7 @@ Search.SELECTION = 2;
|
||||||
if (row < firstRow) {
|
if (row < firstRow) {
|
||||||
if (wrap) {
|
if (wrap) {
|
||||||
row = lastRow;
|
row = lastRow;
|
||||||
|
inWrap = true;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -310,6 +320,9 @@ Search.SELECTION = 2;
|
||||||
else if (row == lastRow)
|
else if (row == lastRow)
|
||||||
line = line.substring(0, range.end.column);
|
line = line.substring(0, range.end.column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inWrap && row == start.row)
|
||||||
|
startIndex = start.column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ async.concat(
|
||||||
require("./search_test"),
|
require("./search_test"),
|
||||||
require("./selection_test"),
|
require("./selection_test"),
|
||||||
require("./text_edit_test"),
|
require("./text_edit_test"),
|
||||||
|
require("./highlight_selected_word_test"),
|
||||||
require("./mode/css_test"),
|
require("./mode/css_test"),
|
||||||
require("./mode/css_tokenizer_test"),
|
require("./mode/css_tokenizer_test"),
|
||||||
require("./mode/html_test"),
|
require("./mode/html_test"),
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ async.concat(
|
||||||
require("./selection_test"),
|
require("./selection_test"),
|
||||||
require("./text_edit_test"),
|
require("./text_edit_test"),
|
||||||
require("./virtual_renderer_test"),
|
require("./virtual_renderer_test"),
|
||||||
|
require("./highlight_selected_word_test"),
|
||||||
require("./mode/css_test"),
|
require("./mode/css_test"),
|
||||||
require("./mode/css_tokenizer_test"),
|
require("./mode/css_tokenizer_test"),
|
||||||
require("./mode/html_test"),
|
require("./mode/html_test"),
|
||||||
|
|
|
||||||
212
lib/ace/test/highlight_selected_word_test.js
Normal file
212
lib/ace/test/highlight_selected_word_test.js
Normal file
|
|
@ -0,0 +1,212 @@
|
||||||
|
/* vim:ts=4:sts=4:sw=4:
|
||||||
|
* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Ajax.org Code Editor (ACE).
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Mihai Sucan.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Mihai Sucan <mihai.sucan@gmail.com>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
|
var EditSession = require("ace/edit_session").EditSession,
|
||||||
|
Editor = require("../editor").Editor,
|
||||||
|
MockRenderer = require("./mockrenderer"),
|
||||||
|
TextMode = require("ace/mode/text").Mode,
|
||||||
|
assert = require("./assertions"),
|
||||||
|
async = require("asyncjs");
|
||||||
|
|
||||||
|
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";
|
||||||
|
|
||||||
|
var Test = {
|
||||||
|
setUp: function() {
|
||||||
|
this.session = new EditSession(lipsum);
|
||||||
|
this.editor = new Editor(new MockRenderer(), this.session);
|
||||||
|
this.selection = this.session.getSelection();
|
||||||
|
this.search = this.editor.$search;
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: highlight selected words by default": function() {
|
||||||
|
assert.equal(this.editor.getHighlightSelectedWord(), true);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: highlight a word": function() {
|
||||||
|
this.editor.moveCursorTo(0, 9);
|
||||||
|
this.selection.selectWord();
|
||||||
|
|
||||||
|
var range = this.selection.getRange();
|
||||||
|
assert.equal(this.session.getTextRange(range), "ipsum");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 1);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: highlight a word and clear highlight": function() {
|
||||||
|
this.editor.moveCursorTo(0, 8);
|
||||||
|
this.selection.selectWord();
|
||||||
|
|
||||||
|
var range = this.selection.getRange();
|
||||||
|
assert.equal(this.session.getTextRange(range), "ipsum");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 1);
|
||||||
|
|
||||||
|
this.session.getMode().clearSelectionHighlight(this.editor);
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: highlight another word": function() {
|
||||||
|
this.selection.moveCursorTo(0, 14);
|
||||||
|
this.selection.selectWord();
|
||||||
|
|
||||||
|
var range = this.selection.getRange();
|
||||||
|
assert.equal(this.session.getTextRange(range), "dolor");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 3);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: no selection, no highlight": function() {
|
||||||
|
this.selection.clearSelection();
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: select a word, no highlight": function() {
|
||||||
|
this.editor.setHighlightSelectedWord(false);
|
||||||
|
this.selection.moveCursorTo(0, 14);
|
||||||
|
this.selection.selectWord();
|
||||||
|
|
||||||
|
var range = this.selection.getRange();
|
||||||
|
assert.equal(this.session.getTextRange(range), "dolor");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: select a word with no matches": function() {
|
||||||
|
this.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(this.session);
|
||||||
|
assert.notEqual(match, null, "found a match for 'Mauris'");
|
||||||
|
|
||||||
|
this.search.set(currentOptions);
|
||||||
|
|
||||||
|
this.selection.setSelectionRange(match);
|
||||||
|
|
||||||
|
assert.equal(this.session.getTextRange(match), "Mauris");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: partial word selection 1": function() {
|
||||||
|
this.selection.moveCursorTo(0, 14);
|
||||||
|
this.selection.selectWord();
|
||||||
|
this.selection.selectLeft();
|
||||||
|
|
||||||
|
var range = this.selection.getRange();
|
||||||
|
assert.equal(this.session.getTextRange(range), "dolo");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: partial word selection 2": function() {
|
||||||
|
this.selection.moveCursorTo(0, 13);
|
||||||
|
this.selection.selectWord();
|
||||||
|
this.selection.selectRight();
|
||||||
|
|
||||||
|
var range = this.selection.getRange();
|
||||||
|
assert.equal(this.session.getTextRange(range), "dolor ");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: partial word selection 3": function() {
|
||||||
|
this.selection.moveCursorTo(0, 14);
|
||||||
|
this.selection.selectWord();
|
||||||
|
this.selection.selectLeft();
|
||||||
|
this.selection.shiftSelection(1);
|
||||||
|
|
||||||
|
var range = this.selection.getRange();
|
||||||
|
assert.equal(this.session.getTextRange(range), "olor");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: select last word": function() {
|
||||||
|
this.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(this.session);
|
||||||
|
assert.notEqual(match, null, "found a match for 'consectetur'");
|
||||||
|
assert.position(match.start, 1, 0);
|
||||||
|
|
||||||
|
this.search.set(currentOptions);
|
||||||
|
|
||||||
|
this.selection.setSelectionRange(match);
|
||||||
|
|
||||||
|
assert.equal(this.session.getTextRange(match), "consectetur");
|
||||||
|
assert.equal(this.session.$selectionOccurrences.length, 2);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = require("asyncjs/test").testcase(Test);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof module !== "undefined" && module === require.main) {
|
||||||
|
require("../../../support/paths");
|
||||||
|
exports.exec()
|
||||||
|
}
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Fabian Jakobs <fabian AT ajax DOT org>
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
|
* Mihai Sucan <mihai DOT sucan AT gmail DOT com>
|
||||||
*
|
*
|
||||||
* Alternatively, the contents of this file may be used under the terms of
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
|
@ -341,7 +342,52 @@ var Test = {
|
||||||
assert.equal(search.replace("ab12", "cd$1"), "cd12");
|
assert.equal(search.replace("ab12", "cd$1"), "cd12");
|
||||||
assert.equal(search.replace("ab12", "-$&-"), "-ab12-");
|
assert.equal(search.replace("ab12", "-$&-"), "-ab12-");
|
||||||
assert.equal(search.replace("ab12", "$$"), "$");
|
assert.equal(search.replace("ab12", "$$"), "$");
|
||||||
}
|
},
|
||||||
|
|
||||||
|
"test: find all matches in a line" : function() {
|
||||||
|
var session = new EditSession("foo bar foo baz foobar foo");
|
||||||
|
|
||||||
|
var search = new 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, 8);
|
||||||
|
assert.position(ranges[0].end, 0, 11);
|
||||||
|
assert.position(ranges[1].start, 0, 23);
|
||||||
|
assert.position(ranges[1].end, 0, 26);
|
||||||
|
assert.position(ranges[2].start, 0, 0);
|
||||||
|
assert.position(ranges[2].end, 0, 3);
|
||||||
|
},
|
||||||
|
|
||||||
|
"test: find all matches in a line backwards" : function() {
|
||||||
|
var session = new EditSession("foo bar foo baz foobar foo");
|
||||||
|
|
||||||
|
var search = new 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[0].start, 0, 8);
|
||||||
|
assert.position(ranges[0].end, 0, 11);
|
||||||
|
assert.position(ranges[1].start, 0, 0);
|
||||||
|
assert.position(ranges[1].end, 0, 3);
|
||||||
|
assert.position(ranges[2].start, 0, 23);
|
||||||
|
assert.position(ranges[2].end, 0, 26);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = require("asyncjs/test").testcase(Test)
|
module.exports = require("asyncjs/test").testcase(Test)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,48 @@
|
||||||
|
/* ***** BEGIN LICENSE BLOCK *****
|
||||||
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Mozilla Public License Version
|
||||||
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
* http://www.mozilla.org/MPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* License.
|
||||||
|
*
|
||||||
|
* The Original Code is Ajax.org Code Editor (ACE).
|
||||||
|
*
|
||||||
|
* The Initial Developer of the Original Code is
|
||||||
|
* Ajax.org B.V.
|
||||||
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||||
|
* the Initial Developer. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Contributor(s):
|
||||||
|
* Fabian Jakobs <fabian AT ajax DOT org>
|
||||||
|
*
|
||||||
|
* Alternatively, the contents of this file may be used under the terms of
|
||||||
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||||
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||||
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||||
|
* of those above. If you wish to allow use of your version of this file only
|
||||||
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||||
|
* use your version of this file under the terms of the MPL, indicate your
|
||||||
|
* decision by deleting the provisions above and replace them with the notice
|
||||||
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||||
|
* the provisions above, a recipient may use your version of this file under
|
||||||
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||||
|
*
|
||||||
|
* ***** END LICENSE BLOCK ***** */
|
||||||
|
|
||||||
define(function(require, exports, module) {
|
define(function(require, exports, module) {
|
||||||
|
|
||||||
var dom = require("pilot/dom");
|
var dom = require("pilot/dom");
|
||||||
|
|
||||||
var cssText = %css%;
|
var cssText = %css%;
|
||||||
|
|
||||||
// import CSS once
|
// import CSS once
|
||||||
dom.importCssString(cssText);
|
dom.importCssString(cssText);
|
||||||
|
|
||||||
return {
|
exports.cssClass = "%cssClass%";
|
||||||
cssClass: "%cssClass%"
|
});
|
||||||
};
|
|
||||||
})
|
|
||||||
|
|
@ -159,17 +159,17 @@ function fillTemplate(template, replacements) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTheme(name, styles, cssTemplate, jsTemplate) {
|
function createTheme(name, styles, cssTemplate, jsTemplate) {
|
||||||
styles.cssClass = "ace" + hyphenate(name);
|
styles.cssClass = "ace-" + hyphenate(name);
|
||||||
var css = fillTemplate(cssTemplate, styles);
|
var css = fillTemplate(cssTemplate, styles);
|
||||||
return fillTemplate(jsTemplate, {
|
return fillTemplate(jsTemplate, {
|
||||||
name: name,
|
name: name,
|
||||||
css: '"' + css.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"',
|
css: '"' + css.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"',
|
||||||
cssClass: "ace" + hyphenate(name)
|
cssClass: "ace-" + hyphenate(name)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function hyphenate(str) {
|
function hyphenate(str) {
|
||||||
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
return str.replace(/([A-Z])/g, "-$1").replace("_", "-").toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
var cssTemplate = fs.readFileSync(__dirname + "/Theme.tmpl.css", "utf8");
|
var cssTemplate = fs.readFileSync(__dirname + "/Theme.tmpl.css", "utf8");
|
||||||
|
|
@ -192,5 +192,5 @@ for (var name in themes) {
|
||||||
var tmTheme = fs.readFileSync(__dirname + "/tmthemes/" + themes[name] + ".tmTheme", "utf8");
|
var tmTheme = fs.readFileSync(__dirname + "/tmthemes/" + themes[name] + ".tmTheme", "utf8");
|
||||||
|
|
||||||
var styles = extractStyles(parseTheme(tmTheme));
|
var styles = extractStyles(parseTheme(tmTheme));
|
||||||
fs.writeFileSync(__dirname + "/../src/ace/theme/" + name + ".js", createTheme(name, styles, cssTemplate, jsTemplate));
|
fs.writeFileSync(__dirname + "/../lib/ace/theme/" + name + ".js", createTheme(name, styles, cssTemplate, jsTemplate));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue