Merge pull request #2805 from storytouch/indentationSetting
Create setting to control if a new line will be indented or not
This commit is contained in:
commit
50171a4c3c
|
@ -135,6 +135,11 @@
|
|||
// Allow Load Testing tools to hit the Etherpad Instance. Warning this will disable security on the instance.
|
||||
"loadTest": false,
|
||||
|
||||
// Disable indentation on new line when previous line ends with some special chars (':', '[', '(', '{')
|
||||
/*
|
||||
"indentationOnNewLine": false,
|
||||
*/
|
||||
|
||||
/* The toolbar buttons configuration.
|
||||
"toolbar": {
|
||||
"left": [
|
||||
|
|
|
@ -1231,6 +1231,7 @@ function handleClientReady(client, message)
|
|||
"plugins": plugins.plugins,
|
||||
"parts": plugins.parts,
|
||||
},
|
||||
"indentationOnNewLine": settings.indentationOnNewLine,
|
||||
"initialChangesets": [] // FIXME: REMOVE THIS SHIT
|
||||
}
|
||||
|
||||
|
|
|
@ -182,6 +182,11 @@ exports.disableIPlogging = false;
|
|||
*/
|
||||
exports.loadTest = false;
|
||||
|
||||
/**
|
||||
* Enable indentation on new lines
|
||||
*/
|
||||
exports.indentationOnNewLine = true;
|
||||
|
||||
/*
|
||||
* log4js appender configuration
|
||||
*/
|
||||
|
|
|
@ -1894,7 +1894,11 @@ function Ace2Inner(){
|
|||
var prevLine = rep.lines.prev(thisLine);
|
||||
var prevLineText = prevLine.text;
|
||||
var theIndent = /^ *(?:)/.exec(prevLineText)[0];
|
||||
if (/[\[\(\:\{]\s*$/.exec(prevLineText)) theIndent += THE_TAB;
|
||||
var shouldIndent = parent.parent.clientVars.indentationOnNewLine;
|
||||
if (shouldIndent && /[\[\(\:\{]\s*$/.exec(prevLineText))
|
||||
{
|
||||
theIndent += THE_TAB;
|
||||
}
|
||||
var cs = Changeset.builder(rep.lines.totalWidth()).keep(
|
||||
rep.lines.offsetOfIndex(lineNum), lineNum).insert(
|
||||
theIndent, [
|
||||
|
|
|
@ -68,6 +68,76 @@ describe("indentation button", function(){
|
|||
});
|
||||
});
|
||||
|
||||
it("indents text with spaces on enter if previous line ends with ':', '[', '(', or '{'", function(done){
|
||||
var inner$ = helper.padInner$;
|
||||
var chrome$ = helper.padChrome$;
|
||||
|
||||
//type a bit, make a line break and type again
|
||||
var $firstTextElement = inner$("div").first();
|
||||
$firstTextElement.sendkeys("line with ':'{enter}");
|
||||
$firstTextElement.sendkeys("line with '['{enter}");
|
||||
$firstTextElement.sendkeys("line with '('{enter}");
|
||||
$firstTextElement.sendkeys("line with '{{}'{enter}");
|
||||
|
||||
helper.waitFor(function(){
|
||||
return inner$("div span").first().text().indexOf("line with '{'") === -1;
|
||||
}).done(function(){
|
||||
// we validate bottom to top for easier implementation
|
||||
|
||||
// curly braces
|
||||
var $lineWithCurlyBraces = inner$("div").first().next().next().next();
|
||||
$lineWithCurlyBraces.sendkeys('{{}');
|
||||
pressEnter(); // cannot use sendkeys('{enter}') here, browser does not read the command properly
|
||||
var $lineAfterCurlyBraces = inner$("div").first().next().next().next().next();
|
||||
expect($lineAfterCurlyBraces.text()).to.match(/\s{4}/); // tab === 4 spaces
|
||||
|
||||
// parenthesis
|
||||
var $lineWithParenthesis = inner$("div").first().next().next();
|
||||
$lineWithParenthesis.sendkeys('(');
|
||||
pressEnter();
|
||||
var $lineAfterParenthesis = inner$("div").first().next().next().next();
|
||||
expect($lineAfterParenthesis.text()).to.match(/\s{4}/);
|
||||
|
||||
// bracket
|
||||
var $lineWithBracket = inner$("div").first().next();
|
||||
$lineWithBracket.sendkeys('[');
|
||||
pressEnter();
|
||||
var $lineAfterBracket = inner$("div").first().next().next();
|
||||
expect($lineAfterBracket.text()).to.match(/\s{4}/);
|
||||
|
||||
// colon
|
||||
var $lineWithColon = inner$("div").first();
|
||||
$lineWithColon.sendkeys(':');
|
||||
pressEnter();
|
||||
var $lineAfterColon = inner$("div").first().next();
|
||||
expect($lineAfterColon.text()).to.match(/\s{4}/);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it("appends indentation to the indent of previous line if previous line ends with ':', '[', '(', or '{'", function(done){
|
||||
var inner$ = helper.padInner$;
|
||||
var chrome$ = helper.padChrome$;
|
||||
|
||||
//type a bit, make a line break and type again
|
||||
var $firstTextElement = inner$("div").first();
|
||||
$firstTextElement.sendkeys(" line with some indentation and ':'{enter}");
|
||||
$firstTextElement.sendkeys("line 2{enter}");
|
||||
|
||||
helper.waitFor(function(){
|
||||
return inner$("div span").first().text().indexOf("line 2") === -1;
|
||||
}).done(function(){
|
||||
var $lineWithColon = inner$("div").first();
|
||||
$lineWithColon.sendkeys(':');
|
||||
pressEnter();
|
||||
var $lineAfterColon = inner$("div").first().next();
|
||||
expect($lineAfterColon.text()).to.match(/\s{6}/); // previous line indentation + regular tab (4 spaces)
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
it("makes text indented and outdented", function() {
|
||||
|
@ -203,3 +273,15 @@ describe("indentation button", function(){
|
|||
});*/
|
||||
|
||||
});
|
||||
|
||||
function pressEnter(){
|
||||
var inner$ = helper.padInner$;
|
||||
if(inner$(window)[0].bowser.firefox || inner$(window)[0].bowser.modernIE){ // if it's a mozilla or IE
|
||||
var evtType = "keypress";
|
||||
}else{
|
||||
var evtType = "keydown";
|
||||
}
|
||||
var e = inner$.Event(evtType);
|
||||
e.keyCode = 13; // enter :|
|
||||
inner$("#innerdocbody").trigger(e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue