Permalink
Browse files

Preserve $ character in Merge Lines and Split/Join actions

  • Loading branch information...
sergeche committed Dec 13, 2012
1 parent 7077325 commit 15de322278c53f4ff030cd1692a037c5399fea9f
Showing with 23 additions and 16 deletions.
  1. +3 −1 javascript/actions/mergeLines.js
  2. +15 −10 javascript/actions/splitJoinTag.js
  3. +5 −5 javascript/unittest/tests/actions.js
@@ -30,8 +30,10 @@ emmet.exec(function(require, _) {
}
text = lines.join('').replace(/\s{2,}/, ' ');
+ var textLen = text.length;
+ text = utils.escapeText(text);
editor.replaceContent(text, selection.start, selection.end);
- editor.createSelection(selection.start, selection.start + text.length);
+ editor.createSelection(selection.start, selection.start + textLen);
return true;
}
@@ -21,15 +21,16 @@ emmet.exec(function(require, _) {
var slash = profile.selfClosing() || ' /';
var content = tag.open.range.substring(tag.source).replace(/\s*>$/, slash + '>');
- // add caret placeholder
- if (content.length + tag.outerRange.start < editor.getCaretPos())
- content += utils.getCaretPlaceholder();
- else {
- var d = editor.getCaretPos() - tag.outerRange.start;
- content = utils.replaceSubstring(content, utils.getCaretPlaceholder(), d);
+ var caretPos = editor.getCaretPos();
+
+ // update caret position
+ if (content.length + tag.outerRange.start < caretPos) {
+ caretPos = content.length + tag.outerRange.start;
}
+ content = utils.escapeText(content);
editor.replaceContent(content, tag.outerRange.start, tag.outerRange.end);
+ editor.setCaretPos(caretPos);
return true;
}
@@ -39,13 +40,17 @@ emmet.exec(function(require, _) {
var nl = utils.getNewline();
var pad = require('resources').getVariable('indentation');
- var caret = utils.getCaretPlaceholder();
+ var caretPos = editor.getCaretPos();
// define tag content depending on profile
- var tagContent = (profile.tag_nl === true) ? nl + pad + caret + nl : caret;
- var content = tag.outerContent().replace(/\s*\/>$/, '>') + tagContent + '</' + tag.open.name + '>';
-
+ var tagContent = (profile.tag_nl === true) ? nl + pad + nl : '';
+ var content = tag.outerContent().replace(/\s*\/>$/, '>');
+ caretPos = tag.outerRange.start + content.length;
+ content += tagContent + '</' + tag.open.name + '>';
+
+ content = utils.escapeText(content);
editor.replaceContent(content, tag.outerRange.start, tag.outerRange.end);
+ editor.setCaretPos(caretPos);
return true;
}
@@ -151,10 +151,10 @@
});
test('Merge lines', function() {
- editorStub.replaceContent('<b>\n\n${0}\n\n</b>');
+ editorStub.replaceContent('<b class="$test">\n\n${0}\n\n</b>');
run('merge_lines');
- equal(editorStub.getContent(), '<b></b>', 'Automatched and merged tag content');
+ equal(editorStub.getContent(), '<b class="$test"></b>', 'Automatched and merged tag content');
editorStub.replaceContent('a\nb\nc\nd\ne');
editorStub.createSelection(4, 9);
@@ -336,13 +336,13 @@
});
test('Split/join current tag', function() {
- editorStub.replaceContent('<span class="${0}sample"></span>');
+ editorStub.replaceContent('<span class="${0}\\$sample"></span>');
run('split_join_tag');
- equal(editorStub.getContent(), '<span class="sample" />', 'Inline tag is joined');
+ equal(editorStub.getContent(), '<span class="$sample" />', 'Inline tag is joined');
run('split_join_tag');
- equal(editorStub.getContent(), '<span class="sample"></span>', 'Inline tag is splitted');
+ equal(editorStub.getContent(), '<span class="$sample"></span>', 'Inline tag is splitted');
var oldProfile = editorStub.getProfileName();

0 comments on commit 15de322

Please sign in to comment.