Enables sections to wrapped around selected code

This commit is contained in:
Per Ploug
2016-12-15 13:55:45 +01:00
parent c8a92434af
commit 9ceb5305d5

View File

@@ -274,7 +274,7 @@
vm.sectionsOverlay = {
view: "templatesections",
isMasterTemplate: true,
hasMaster: vm.template.masterTemplateAlias,
submitButtonLabel: "Insert",
show: true,
submit: function(model) {
@@ -288,7 +288,7 @@
}
if (model.insertType === 'addSection') {
insert("@section " + model.sectionName + "\r\n{\r\n\r\n}\r\n");
wrap("@section " + model.sectionName + "\r\n{\r\n\r\n\t{0}\r\n\r\n}\r\n");
}
vm.sectionsOverlay.show = false;
@@ -393,12 +393,21 @@
vm.editor.navigateFileStart();
}
function insert(str) {
vm.editor.moveCursorToPosition(vm.currentPosition);
vm.editor.insert(str);
vm.editor.focus();
}
function wrap(str) {
var selectedContent = vm.editor.session.getTextRange(vm.editor.getSelectionRange());
str = str.replace("{0}", selectedContent);
vm.editor.insert(str);
vm.editor.focus();
}
function persistCurrentLocation() {
vm.currentPosition = vm.editor.getCursorPosition();
}