mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Create setting to control if a new line will be indented or not
Currently pressing ENTER on a line that ends with ':', '[', '(' or '{' automaticaly indents the new line with 4 spaces. The variable added by this commit to settings.json allow an Etherpad instance to not have this behavior.
This commit is contained in:
parent
9d29b15def
commit
5deb06d589
5 changed files with 128 additions and 31 deletions
|
@ -131,6 +131,11 @@
|
||||||
// Allow Load Testing tools to hit the Etherpad Instance. Warning this will disable security on the instance.
|
// Allow Load Testing tools to hit the Etherpad Instance. Warning this will disable security on the instance.
|
||||||
"loadTest": false,
|
"loadTest": false,
|
||||||
|
|
||||||
|
// Disable indentation on new line when previous line ends with some special chars (':', '[', '(', '{')
|
||||||
|
/*
|
||||||
|
"indentationOnNewLine": false,
|
||||||
|
*/
|
||||||
|
|
||||||
/* The toolbar buttons configuration.
|
/* The toolbar buttons configuration.
|
||||||
"toolbar": {
|
"toolbar": {
|
||||||
"left": [
|
"left": [
|
||||||
|
|
|
@ -1231,6 +1231,7 @@ function handleClientReady(client, message)
|
||||||
"plugins": plugins.plugins,
|
"plugins": plugins.plugins,
|
||||||
"parts": plugins.parts,
|
"parts": plugins.parts,
|
||||||
},
|
},
|
||||||
|
"indentationOnNewLine": settings.indentationOnNewLine,
|
||||||
"initialChangesets": [] // FIXME: REMOVE THIS SHIT
|
"initialChangesets": [] // FIXME: REMOVE THIS SHIT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,11 @@ exports.disableIPlogging = false;
|
||||||
*/
|
*/
|
||||||
exports.loadTest = false;
|
exports.loadTest = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable indentation on new lines
|
||||||
|
*/
|
||||||
|
exports.indentationOnNewLine = true;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* log4js appender configuration
|
* log4js appender configuration
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1894,7 +1894,11 @@ function Ace2Inner(){
|
||||||
var prevLine = rep.lines.prev(thisLine);
|
var prevLine = rep.lines.prev(thisLine);
|
||||||
var prevLineText = prevLine.text;
|
var prevLineText = prevLine.text;
|
||||||
var theIndent = /^ *(?:)/.exec(prevLineText)[0];
|
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(
|
var cs = Changeset.builder(rep.lines.totalWidth()).keep(
|
||||||
rep.lines.offsetOfIndex(lineNum), lineNum).insert(
|
rep.lines.offsetOfIndex(lineNum), lineNum).insert(
|
||||||
theIndent, [
|
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() {
|
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 a new issue