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

Changed the process to format the statements inserted in the editor ace

parent 7bb0b51d
......@@ -99,7 +99,6 @@ function insertPrimitive(primitiveType, pluginName, primitiveName, idPlugin) {
//retrive the text to insert
var lowerCasePrimitiveType = primitiveType.toLowerCase();
var editor = ace.edit(getActiveEditor());
var completeText = editor.getValue();
var cache = localCache.get("pluginInfo");
var retrievedJson = retrievePrimitive(lowerCasePrimitiveType, pluginName, primitiveName, cache);
var cursorPosition = editor.getCursorPosition();
......@@ -297,7 +296,7 @@ function positionToInsert() {
function insertStatement(statementType, pluginName, testName, pluginId) {
var editor = ace.edit(getActiveEditor());
var completeText = editor.getValue();
var cursorPosition = editor.getCursorPosition();
var cache = localCache.get("pluginInfo");
var xmlConverted = "";
var retrievedJson = retrieveTest(pluginName, testName, cache);
......@@ -312,33 +311,30 @@ function insertStatement(statementType, pluginName, testName, pluginId) {
var endXml = "</" + statementType + ">"
var beginCondition = "<condition use=\"" + pluginId + "\" name=\"" + testName + "\">";
var endCondition = "</condition>"
var additionalTag = "<then></then><else></else>";
var additionalTag = "<then>" + "\n" + "</then>" + "\n" + "<else>" + "\n" + "</else>";
var beginParamsTag = "<params>";
var endParamsTag = "</params>";
var xml = beginXml + beginCondition;
var xmlToInsert = beginXml + beginCondition;
if (xmlConverted.length > 1) {
xml += beginParamsTag + xmlConverted + endParamsTag;
xmlToInsert += beginParamsTag + xmlConverted + endParamsTag;
}
xml += endCondition;
xmlToInsert += endCondition;
if (statementType == "if") {
xml += additionalTag;
}
xml += endXml;
var answerPositionToInsertPrimitive = positionToInsert();
var cursorPositionToInsert = answerPositionToInsertPrimitive[0];
editor.moveCursorTo(cursorPositionToInsert[1], cursorPositionToInsert[0]);
if (answerPositionToInsertPrimitive[1] == true) {
xml = "\n" + xml;
xmlToInsert += additionalTag;
}
xmlToInsert += endXml;
xmlToInsert = formatXml(xmlToInsert);
//delete the \n added by format xml
xmlToInsert = xmlToInsert.substring(0, xmlToInsert.length - 1);
//format the insertion
var cursorPositionToInsert = [cursorPosition["row"], cursorPosition["column"]]
xmlToInsert = formatInsertion(xmlToInsert, cursorPositionToInsert);
//insert the formatted xml
var Range = ace.require('ace/range').Range;
xml = formatXml(xml);
//xml = addTabXml(xml, cursorPositionToInsert, completeText);
xml = formatInsertion(xml, cursorPositionToInsert);
editor.session.replace(new Range(cursorPositionToInsert[1], cursorPositionToInsert[0], cursorPositionToInsert[1], cursorPositionToInsert[0]), xml);
editor.session.replace(new Range(cursorPosition["row"], cursorPosition["column"], cursorPosition["row"], cursorPosition["column"]), xmlToInsert);
}
......
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