Commit f819d96a authored by Antoine Thevenet's avatar Antoine Thevenet
Browse files

added a parameter in three functions to improve tabulation counting

parent bb69f356
Pipeline #14417 canceled with stages
......@@ -76,7 +76,7 @@ function insertPlugin(pluginContent) {
//remove the last \n
xmlToInsert = pluginContent.substring(0, pluginContent.length - 1);
var cursorPositionToInsert = [cursorPosition["row"], cursorPosition["column"]]
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert);
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert, "plugins");
//insert the formatted xml
var Range = ace.require('ace/range').Range;
editor.session.replace(new Range(cursorPosition["row"], cursorPosition["column"], cursorPosition["row"], cursorPosition["column"]), xmlToInsert);
......@@ -118,7 +118,7 @@ function insertPrimitive(primitiveType, pluginName, primitiveName, idPlugin) {
//delete the "\n added by format xml
xmlToInsert = xmlToInsert.substring(0, xmlToInsert.length - 1);
var cursorPositionToInsert = [cursorPosition["row"], cursorPosition["column"]]
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert);
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert, "behavior");
var Range = ace.require('ace/range').Range;
editor.session.replace(new Range(cursorPosition["row"], cursorPosition["column"], cursorPosition["row"], cursorPosition["column"]), xmlToInsert);
}
......@@ -195,7 +195,7 @@ function insertStatement(statementType, pluginName, testName, pluginId) {
//format the insertion
var cursorPositionToInsert = [cursorPosition["row"], cursorPosition["column"]]
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert);
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert, "behavior");
//insert the formatted xml
var Range = ace.require('ace/range').Range;
editor.session.replace(new Range(cursorPosition["row"], cursorPosition["column"], cursorPosition["row"], cursorPosition["column"]), xmlToInsert);
......@@ -240,7 +240,7 @@ function insertChoice() {
xmlToInsert = xmlToInsert.substring(0, xmlToInsert.length - 1);
//format the insertion
var cursorPositionToInsert = [cursorPosition["row"], cursorPosition["column"]]
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert);
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert, "behavior");
//insert the formatted xml
var Range = ace.require('ace/range').Range;
editor.session.replace(new Range(cursorPosition["row"], cursorPosition["column"], cursorPosition["row"], cursorPosition["column"]), xmlToInsert);
......@@ -264,7 +264,7 @@ function insertBehavior() {
xmlToInsert = xmlToInsert.substring(0, xmlToInsert.length - 1);
//format the insertion
var cursorPositionToInsert = [cursorPosition["row"], cursorPosition["column"]]
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert);
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert, "behaviors");
var Range = ace.require('ace/range').Range;
editor.session.replace(new Range(cursorPosition["row"], cursorPosition["column"], cursorPosition["row"], cursorPosition["column"]), xmlToInsert);
......@@ -291,7 +291,7 @@ function insertLoadprofile(behaviorName) {
xmlToInsert = xmlToInsert.substring(0, xmlToInsert.length - 1);
//format the insertion
var cursorPositionToInsert = [cursorPosition["row"], cursorPosition["column"]]
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert);
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert, "loadprofile");
//insert the formatted xml
var Range = ace.require('ace/range').Range;
editor.session.replace(new Range(cursorPosition["row"], cursorPosition["column"], cursorPosition["row"], cursorPosition["column"]), xmlToInsert);
......@@ -312,9 +312,10 @@ function removeAceContextMenu() {
*This function adds tabs to a formated xml String by checking the previous xml tags
*@param {String} xml - The formatted xml String
*@param {Array} cursorPositionInsert - The row and column where the xml must be inserted
*@param {String} - the type of xml text that will be inserted
*@returns {String} formatedXml - The xml with the inserted tabulation
*/
function formatInsertion(xml, cursorPositionToInsert) {
function formatInsertion(xml, cursorPositionToInsert, tagType) {
var formattedXml = "";
var cursorRow = cursorPositionToInsert[0];
var cursorColumn = cursorPositionToInsert[1];
......@@ -333,7 +334,7 @@ function formatInsertion(xml, cursorPositionToInsert) {
arrayCompleteText[i] += "\n";
}
var tabCount = countTabulation(arrayCompleteText, cursorRow);
var tabCount = countTabulation(arrayCompleteText, cursorRow, tagType);
//add tabs to each line
for (var i = 0; i < arrayXml.length; i++) {
......@@ -350,7 +351,7 @@ function formatInsertion(xml, cursorPositionToInsert) {
* @param arrayCompleteText {Array} - the text contained in the editor divided by line breaks
* @param cursorRow {number} - the cursor row number
**/
function countTabulation(arrayCompleteText, cursorRow) {
function countTabulation(arrayCompleteText, cursorRow, tagType) {
var validRow = false;
var count = cursorRow;
var tabCount = 0;
......@@ -384,12 +385,14 @@ function countTabulation(arrayCompleteText, cursorRow) {
}
charIndex++;
}
if (row.includes("scenario") || row.includes("behaviors") || row.includes("<plugins>") ||
row.includes("loadprofile") || row.includes("<behavior") || row.includes("then") ||
row.includes("else") || row.includes("choice")) {
tabCount++;
if (tagType != "behaviors") {
if (row.includes("<scenario>") || row.includes("<behaviors>") || row.includes("<plugins>") ||
row.includes("loadprofile") || row.includes("<behavior") || row.includes("then") ||
row.includes("else") || row.includes("choice")) {
tabCount++;
}
}
return tabCount;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment