diff --git a/static/js/ace2_inner.js b/static/js/ace2_inner.js index 015301194..356f9536b 100644 --- a/static/js/ace2_inner.js +++ b/static/js/ace2_inner.js @@ -2975,6 +2975,7 @@ function Ace2Inner(){ return str.replace(/[\n\r ]/g, ' ').replace(/\xa0/g, ' ').replace(/\t/g, ' '); } + //FIXME: duplicated with contentcollector.js var _blockElems = { //blocks and paragraphs "div": 1, @@ -5186,13 +5187,8 @@ function Ace2Inner(){ // -> title //"defaultLevel" => directly create at a given nesting level. This is especially // usefull for titles wich can be created at arbitrary level (h1->hx) - function doInsertList(type, defaultLevel) - { - if(!defaultLevel) - { - defaultLevel = 1; - } - + function doInsertList(type, requestLevel) + { if (!(rep.selStart && rep.selEnd)) { return; @@ -5202,30 +5198,56 @@ function Ace2Inner(){ firstLine = rep.selStart[0]; lastLine = Math.max(firstLine, rep.selEnd[0] - ((rep.selEnd[1] === 0) ? 1 : 0)); - var allLinesAreList = true; - for (var n = firstLine; n <= lastLine; n++) + var allLinesAreList = true && !requestLevel; + //if a specific level is requested, we do not care about the current status + if(!requestLevel) { - var listType = getLineListType(n); - if (!listType || listType.slice(0, type.length) != type) + for (var n = firstLine; n <= lastLine; n++) { - allLinesAreList = false; - break; + var listType = getLineListType(n); + if (!listType || listType.slice(0, type.length) != type) + { + allLinesAreList = false; + break; + } } } - + + //compute the modification to apply for each single line in the selection + //we try to do only what is requested and as such to preserve the indentation + //level in case of list type transformation even if the list is composed of + //several indentation levels + //In case a specific level is requested. Force it + //if all lines are already of this list type, we remove the list + //otherwise, we apply the new one var mods = []; for (var n = firstLine; n <= lastLine; n++) { var t = ''; var level = 0; var listType = /([a-z]+)([12345678])/.exec(getLineListType(n)); - if (listType) + if (listType)//already a list => read attributes { t = listType[1]; level = Number(listType[2]); } var t = getLineListType(n); - mods.push([n, allLinesAreList ? 'indent' + level : (t ? type + level : type + defaultLevel)]); + //apply the list type. If a specific level is requested, force it + if(requestLevel) + { + if(type+level == type+requestLevel) + { + type = 'indent'; + level = 0; + } + else + { + level = requestLevel; + } + } + + alert(allLinesAreList ? 'indent' + level : (t ? type + level : type + '1')); + mods.push([n, allLinesAreList ? 'indent' + level : (t ? type + level : type + '1')]); } setLineListTypes(mods); } diff --git a/static/js/contentcollector.js b/static/js/contentcollector.js index 96dc4b7dd..10f3772d5 100644 --- a/static/js/contentcollector.js +++ b/static/js/contentcollector.js @@ -74,11 +74,21 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class } }; + //FIXME: duplicated with ace2_inner.js and lower in this file ! var _blockElems = { + //blocks and paragraphs "div": 1, "p": 1, "pre": 1, - "li": 1 + //lists styles + "li": 1, + "ol": 1, + "ul": 1, + //titling styles + "h1": 1, + "h2": 1, + "h3": 1, + "h4": 1, }; function isBlockElement(n) @@ -163,10 +173,22 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class var selection, startPoint, endPoint; var selStart = [-1, -1], selEnd = [-1, -1]; - var blockElems = { + + //FIXME: duplicated with ace2_inner.js and even above ! + var _blockElems = { + //blocks and paragraphs "div": 1, "p": 1, - "pre": 1 + "pre": 1, + //lists styles + "li": 1, + "ol": 1, + "ul": 1, + //titling styles + "h1": 1, + "h2": 1, + "h3": 1, + "h4": 1, }; function _isEmpty(node, state) diff --git a/static/js/domline.js b/static/js/domline.js index 3074c9e93..8c1489512 100644 --- a/static/js/domline.js +++ b/static/js/domline.js @@ -104,16 +104,26 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) start = start?'start="'+Security.escapeHTMLAttribute(start[1])+'"':''; if (listType) { - if(listType.indexOf("number") < 0) - { - preHtml = '