_.each(this.list(), /** @param {CSSEditProperty} p */ function(p) { p.styleBefore = source.substring(start, p.namePosition()); // a small hack here: // Sometimes users add empty lines before properties to logically // separate groups of properties. In this case, a blind copy of // characters between rules may lead to undesired behavior, // especially when current rule is duplicated or used as a donor // to create new rule. // To solve this issue, we‘ll take only last newline indentation var lines = utils.splitByLines(p.styleBefore); if (lines.length > 1) { p.styleBefore = '\n' + _.last(lines); } p.styleSeparator = source.substring(p.nameRange().end, p.valuePosition()); // graceful and naive comments removal p.styleBefore = _.last(p.styleBefore.split('*/')); p.styleSeparator = p.styleSeparator.replace(/\/\*.*?\*\//g, ''); start = p.range().end; });
require('actions').add('merge_lines', function(editor) { var matcher = require('htmlMatcher'); var utils = require('utils'); var editorUtils = require('editorUtils'); var info = editorUtils.outputInfo(editor); /** @type Range */ var selection = require('range').create(editor.getSelectionRange()); if (!selection.length()) { // find matching tag var pair = matcher.find(info.content, editor.getCaretPos()); if (pair) { selection = pair.outerRange; } } if (selection.length()) { // got range, merge lines var text = selection.substring(info.content); var lines = utils.splitByLines(text); for (var i = 1; i < lines.length; i++) { lines[i] = lines[i].replace(/^\s+/, ''); } 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 + textLen); return true; } return false; });