This commit is contained in:
Resolver Developers 2011-02-17 10:44:19 +00:00
commit 51380ebb5e
17 changed files with 445 additions and 72 deletions

View file

@ -270,6 +270,10 @@ exports.launch = function(env) {
env.editor.setHighlightSelectedWord(checked);
});
bindCheckbox("show_hscroll", function(checked) {
env.editor.renderer.setHScrollBarAlwaysVisible(checked);
});
function bindCheckbox(id, callback) {
var el = document.getElementById(id);
var onCheck = function() {

View file

@ -62,6 +62,10 @@
<label for="show_hidden">Show Invisibles</label>
<input type="checkbox" name="show_hidden" id="show_hidden">
</td>
<td align="right">
<label for="show_hscroll">Persistent HScroll</label>
<input type="checkbox" name="show_hscroll" id="show_hscroll">
</td>
<td align="right" rowspan="2">
<img src="demo/logo.png">
</td>

View file

@ -174,39 +174,17 @@ var Document = function(text) {
if (this.getLength() <= 1)
this.$detectNewLine(text);
var newLines = this.$split(text);
var lines = this.$split(text);
var firstLine = lines.splice(0, 1)[0];
var lastLine = lines.length == 0 ? null : lines.splice(lines.length - 1, 1)[0];
if (this.isNewLine(text)) {
var end = this.insertNewLine(position);
position = this.insertInLine(position, firstLine);
if (lastLine !== null) {
position = this.insertNewLine(position); // terminate first line
position = this.insertLines(position.row, lines);
position = this.insertInLine(position, lastLine || "");
}
else if (newLines.length == 1) {
var end = this.insertInLine(position, text);
}
else {
if (newLines[0].length > 0) {
var end = this.insertInLine(position, newLines[0]);
this.insertNewLine(end);
}
// If we are inserting at the end of the document, we don't need to
// use insertInLine (concorde depends on this optimization!)
if (position.row + 1 == this.getLength()) {
this.insertLines(position.row + 1,
newLines.slice(1, newLines.length));
var end = {
row: position.row + newLines.length - 1,
column: position.column + newLines[newLines.length - 1].length
};
} else {
if (newLines.length > 2)
this.insertLines(position.row + 1,
newLines.slice(1, newLines.length - 1));
var end = this.insertInLine({
row: position.row + newLines.length - 1,
column: 0
}, newLines[newLines.length - 1]);
}
}
return end;
return position;
};
this.insertLines = function(row, lines) {

View file

@ -536,15 +536,7 @@ var EditSession = function(text, mode) {
this.doc.revertDeltas(deltas);
this.$fromUndo = false;
// update the selection
var firstDelta = deltas[0];
var lastDelta = deltas[deltas.length-1];
this.selection.clearSelection();
if (firstDelta.action == "insertText" || firstDelta.action == "insertLines")
this.selection.moveCursorToPosition(firstDelta.range.start);
if (firstDelta.action == "removeText" || firstDelta.action == "removeLines")
this.selection.setSelectionRange(Range.fromPoints(lastDelta.range.start, firstDelta.range.end));
this.$setUndoSelection(deltas, true);
},
this.redoChanges = function(deltas) {
@ -555,17 +547,55 @@ var EditSession = function(text, mode) {
this.doc.applyDeltas(deltas);
this.$fromUndo = false;
// update the selection
var firstDelta = deltas[0];
var lastDelta = deltas[deltas.length-1];
this.selection.clearSelection();
if (firstDelta.action == "insertText" || firstDelta.action == "insertLines")
this.selection.setSelectionRange(Range.fromPoints(firstDelta.range.start, lastDelta.range.end));
if (firstDelta.action == "removeText" || firstDelta.action == "removeLines")
this.selection.moveCursorToPosition(lastDelta.range.start);
this.$setUndoSelection(deltas, false);
},
this.$setUndoSelection = function(deltas, isUndo) {
// invert deltas is they are an undo
if (isUndo)
deltas = deltas.map(function(delta) {
var d = {
range: delta.range
}
if (delta.action == "insertText" || delta.action == "insertLines")
d.action = "removeText"
else
d.action = "insertText"
return d;
}).reverse();
var actions = [{}];
// collapse insert and remove operations
for (var i=0; i<deltas.length; i++) {
var delta = deltas[i];
var isInsert = delta.action == "insertText" || delta.action == "insertLines";
var action = actions[actions.length-1];
if (action.isInsert !== isInsert) {
actions.push({
isInsert: isInsert,
start: isInsert ? delta.range.start : delta.range.end,
end: isInsert ? delta.range.end : delta.range.start
})
}
else {
if (isInsert)
action.end = delta.range.end;
else
action.start = delta.range.start;
}
}
// update selection based on last operation
this.selection.clearSelection();
var action = actions[actions.length-1];
if (action.isInsert)
this.selection.setSelectionRange(Range.fromPoints(action.start, action.end));
else
this.selection.moveCursorToPosition(action.start);
},
this.replace = function(range, text) {
return this.doc.replace(range, text);
};
@ -1192,4 +1222,4 @@ var EditSession = function(text, mode) {
}).call(EditSession.prototype);
exports.EditSession = EditSession;
});
});

View file

@ -430,8 +430,10 @@ var Editor =function(renderer, session) {
this.moveCursorToPosition(end);
var lineState = this.bgTokenizer.getState(cursor.row);
// multi line insert
if (cursor.row !== end.row) {
// TODO disabled multiline auto indent
// possibly doing the indent before inserting the text
// if (cursor.row !== end.row) {
if (this.session.getDocument().isNewLine(text)) {
var size = this.session.getTabSize(),
minIndent = Number.MAX_VALUE;

View file

@ -94,22 +94,25 @@ var Mode = function() {
var startOuter = selection.start.column - 1;
var endOuter = selection.end.column + 1;
var line = session.getLine(selection.start.row);
var lineCols = line.length - 1;
var lineCols = line.length;
var needle = line.substring(Math.max(startOuter, 0),
Math.min(endOuter, lineCols));
// Make sure the outer characters are not part of the word.
if ((startOuter >= 0 && !/[^\w\d]/.test(needle.charAt(0))) ||
(endOuter <= lineCols && !/[^\w\d]/.test(needle.charAt(needle.length - 1))))
if ((startOuter >= 0 && /^[\w\d]/.test(needle)) ||
(endOuter <= lineCols && /[\w\d]$/.test(needle)))
return;
needle = line.substring(selection.start.column, selection.end.column);
if (!/^[\w\d]+$/.test(needle))
return;
var cursor = editor.getCursorPosition();
var newOptions = {
wrap: true,
wholeWord: true,
caseSensitive: true,
needle: needle
};
@ -117,9 +120,8 @@ var Mode = function() {
editor.$search.set(newOptions);
var ranges = editor.$search.findAll(session);
session.$selectionOccurrences = [];
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");
session.$selectionOccurrences.push(marker);
}
@ -135,6 +137,8 @@ var Mode = function() {
editor.session.$selectionOccurrences.forEach(function(marker) {
editor.session.removeMarker(marker);
});
editor.session.$selectionOccurrences = [];
};
}).call(Mode.prototype);

View file

@ -52,7 +52,7 @@ var ScrollBar = function(parent) {
parent.appendChild(this.element);
this.width = dom.scrollbarWidth();
this.element.style.width = this.width;
this.element.style.width = this.width + "px";
event.addListener(this.element, "scroll", this.onScroll.bind(this));
};
@ -69,7 +69,7 @@ var ScrollBar = function(parent) {
};
this.setHeight = function(height) {
this.element.style.height = Math.max(0, height - this.width) + "px";
this.element.style.height = height + "px";
};
this.setInnerHeight = function(height) {

View file

@ -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
*
* The contents of this file are subject to the Mozilla Public License Version
@ -20,6 +21,7 @@
*
* Contributor(s):
* 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
* 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 wrap = this.$options.wrap;
var inWrap = false;
function getLine(row) {
var line = session.getLine(row);
if (searchSelection && row == range.end.row) {
line = line.substring(0, range.end.column);
}
if (inWrap && row == start.row) {
line = line.substring(0, start.column);
}
return line;
}
@ -236,6 +242,7 @@ Search.SELECTION = 2;
var startIndex = start.column;
var stop = false;
inWrap = false;
while (!callback(line, startIndex, row)) {
@ -250,6 +257,7 @@ Search.SELECTION = 2;
if (wrap) {
row = firstRow;
startIndex = firstColumn;
inWrap = true;
} else {
return;
}
@ -283,6 +291,7 @@ Search.SELECTION = 2;
var line = session.getLine(row).substring(0, start.column);
var startIndex = 0;
var stop = false;
var inWrap = false;
while (!callback(line, startIndex, row)) {
@ -295,6 +304,7 @@ Search.SELECTION = 2;
if (row < firstRow) {
if (wrap) {
row = lastRow;
inWrap = true;
} else {
return;
}
@ -310,6 +320,9 @@ Search.SELECTION = 2;
else if (row == lastRow)
line = line.substring(0, range.end.column);
}
if (inWrap && row == start.row)
startIndex = start.column;
}
}
};

View file

@ -51,6 +51,7 @@ async.concat(
require("./search_test"),
require("./selection_test"),
require("./text_edit_test"),
require("./highlight_selected_word_test"),
require("./mode/css_test"),
require("./mode/css_tokenizer_test"),
require("./mode/html_test"),

View file

@ -20,6 +20,7 @@ async.concat(
require("./selection_test"),
require("./text_edit_test"),
require("./virtual_renderer_test"),
require("./highlight_selected_word_test"),
require("./mode/css_test"),
require("./mode/css_tokenizer_test"),
require("./mode/html_test"),
@ -72,4 +73,4 @@ async.concat(
].join("")
})
});
});

View file

@ -325,6 +325,20 @@ var Test = {
assert.equal(session.$wrapData.length, 2);
assert.equal(session.$wrapData[0].length, 1);
assert.equal(session.$wrapData[1].length, 1);
},
"test first line blank with wrap": function() {
var session = new EditSession("\nfoo");
session.setUseWrapMode(true);
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
},
"test first line blank with wrap 2" : function() {
var session = new EditSession("");
session.setUseWrapMode(true);
session.setValue("\nfoo");
assert.equal(session.doc.getValue(), ["", "foo"].join("\n"));
}
};

View 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()
}

View file

@ -20,6 +20,7 @@
*
* Contributor(s):
* 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
* 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", "-$&-"), "-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)

View file

@ -88,6 +88,10 @@ var VirtualRenderer = function(container, theme) {
this.$cursorLayer = new CursorLayer(this.content);
this.$cursorPadding = 8;
// Indicates whether the horizontal scrollbar is visible
this.$horizScroll = true;
this.$horizScrollAlwaysVisible = true;
this.scrollBar = new ScrollBar(container);
this.scrollBar.addEventListener("scroll", this.onScroll.bind(this));
@ -199,7 +203,7 @@ var VirtualRenderer = function(container, theme) {
this.$size.height = height;
this.scroller.style.height = height + "px";
this.scrollBar.setHeight(height);
this.scrollBar.setHeight(this.scroller.clientHeight);
if (this.session) {
this.scrollToY(this.getScrollTop());
@ -361,6 +365,14 @@ var VirtualRenderer = function(container, theme) {
this.$updatePrintMargin();
};
this.setHScrollBarAlwaysVisible = function(alwaysVisible) {
if (this.$horizScrollAlwaysVisible != alwaysVisible) {
this.$horizScrollAlwaysVisible = alwaysVisible;
if (!this.$horizScrollAlwaysVisible || !this.$horizScroll)
this.$loop.schedule(this.CHANGE_SCROLL);
}
}
this.onScroll = function(e) {
this.scrollToY(e.data);
};
@ -446,6 +458,12 @@ var VirtualRenderer = function(container, theme) {
var longestLine = this.$getLongestLine();
var widthChanged = !this.layerConfig ? true : (this.layerConfig.width != longestLine);
var horizScroll = this.$horizScrollAlwaysVisible || this.$size.scrollerWidth - longestLine < 0;
var horizScrollChanged = this.$horizScroll !== horizScroll;
this.$horizScroll = horizScroll;
if (horizScrollChanged)
this.scroller.style.overflowX = horizScroll ? "scroll" : "hidden";
var lineCount = Math.ceil(minHeight / this.lineHeight) - 1;
var firstRow = Math.max(0, Math.round((this.scrollTop - offset) / this.lineHeight));
var lastRow = firstRow + lineCount;
@ -480,6 +498,11 @@ var VirtualRenderer = function(container, theme) {
this.content.style.marginTop = (-offset) + "px";
this.content.style.width = longestLine + "px";
this.content.style.height = minHeight + "px";
// Horizontal scrollbar visibility may have changed, which changes
// the client height of the scroller
if (horizScrollChanged)
this.onResize(true);
};
this.$updateLines = function() {
@ -559,6 +582,10 @@ var VirtualRenderer = function(container, theme) {
};
this.scrollCursorIntoView = function() {
// the editor is not visible
if (this.$size.scrollerHeight === 0)
return;
var pos = this.$cursorLayer.getPixelPosition();
var left = pos.left + this.$padding;

@ -1 +1 @@
Subproject commit 3028dbabffa2f16cbfd45cd5709baa1c34e0ba4d
Subproject commit 6e1fbe1dfdff64020f15cd9e23ea72b7803cf406

View file

@ -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) {
var dom = require("pilot/dom");
var cssText = %css%;
// import CSS once
dom.importCssString(cssText);
return {
cssClass: "%cssClass%"
};
})
exports.cssClass = "%cssClass%";
});

View file

@ -159,17 +159,17 @@ function fillTemplate(template, replacements) {
}
function createTheme(name, styles, cssTemplate, jsTemplate) {
styles.cssClass = "ace" + hyphenate(name);
styles.cssClass = "ace-" + hyphenate(name);
var css = fillTemplate(cssTemplate, styles);
return fillTemplate(jsTemplate, {
name: name,
css: '"' + css.replace(/\\/, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\\n") + '"',
cssClass: "ace" + hyphenate(name)
cssClass: "ace-" + hyphenate(name)
});
};
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");
@ -192,5 +192,5 @@ for (var name in themes) {
var tmTheme = fs.readFileSync(__dirname + "/tmthemes/" + themes[name] + ".tmTheme", "utf8");
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));
}