<commit_before>/* global atom */
'use strict';
var autoprefixer = require('autoprefixer');
var plugin = module.exports;

function prefix() {
	var browsers = atom.config.get('autoprefixer.browsers');
	var editor = atom.workspace.getActiveEditor();
	var isCSS = editor.getGrammar().name === 'CSS';
	var text = '';
	var prefixed = '';

	if (!editor) {
		return;
	}

	// process the selected text only when not CSS
	text = isCSS ? editor.getText() : editor.getSelectedText();

	try {
		prefixed = autoprefixer.apply(autoprefixer, browsers).process(text).css;
	} catch (err) {
		console.error(err);
		atom.beep();
		return;
	}

	if (isCSS) {
		editor.setText(prefixed);
	} else {
		editor.setTextInBufferRange(editor.getSelectedBufferRange(), prefixed);
	}
}

plugin.configDefaults = {
	browsers: ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']
};

plugin.activate = function () {
	return atom.workspaceView.command('autoprefixer', prefix);
};<commit_msg>preserve cursor position - fixes #7<commit_after>'use strict';
var autoprefixer = require('autoprefixer');
var plugin = module.exports;

function prefix() {
	var browsers = atom.config.get('autoprefixer.browsers');
	var editor = atom.workspace.getActiveEditor();
	var isCSS = editor.getGrammar().name === 'CSS';

	if (!editor) {
		return;
	}

	// process the selected text only when not CSS
	var text = isCSS ? editor.getText() : editor.getSelectedText();
	var prefixed = '';

	try {
		prefixed = autoprefixer(browsers).process(text).css;
	} catch (err) {
		console.error(err);
		atom.beep();
		return;
	}

	var cursorPosition = editor.getCursorBufferPosition();

	if (isCSS) {
		editor.setText(prefixed);
	} else {
		editor.setTextInBufferRange(editor.getSelectedBufferRange(), prefixed);
	}

	editor.setCursorBufferPosition(cursorPosition);
}

plugin.configDefaults = {
	browsers: ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1']
};

plugin.activate = function () {
	return atom.workspaceView.command('autoprefixer', prefix);
};
{'fraction_non_alphanumeric': 0.1557336004006009, 'fraction_numerical': 0.005508262393590386, 'mean_word_length': 4.708571428571428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3445139', 'n_tokens_mistral': 707, 'n_tokens_neox': 676, 'n_words': 147}