﻿/*
HTMl, Javascript, Css format for Emeditor
---------------
  $Date: 2008-08-02 23:32:18
  Written by KevinYuan whyork@21cn.com
  You are free to use this in any way you want
feature:
1> Multiline support.
2> CSS, HTML, Javascript, C#, C-like, Java decomment are supported;
*/
function JS_deComment(code) {
	var reg = /(^[\s]*)([\/]{2,})/gm;
	return code.replace(reg, '$1');
}

function CSS_deComment(code) {
	var reg = /\/\*([\w\W]*?)\*\//gm;
	return code.replace(reg, '$1');
}

function HTML_deComment(code) {
	var reg = /<!--([\w\W]*?)-->/gm;
	return code.replace(reg, '$1');
} (function() {
	var word = document.selection.Text;
	var isCurrentLine = 0;
	//如果当前选择的文字为空,则选择光标当前行
	if (word == '') {
		//选择当前行
		document.selection.SelectLine();
		//获取当前行的文字
		word = document.selection.Text;
		isCurrentLine = 1;
	}
	//获取匹配当前文档的配置名如 html,htm,xml,css,js,c#	
	var Filetype = document.ConfigName.toLowerCase().replace(/ /g, '');
	if (Filetype.indexOf('htm') > -1 || Filetype.indexOf('ml') > -1) {
		word = HTML_deComment(word);
	} else if (Filetype.indexOf('css') > -1) {
		word = CSS_deComment(word);
	} else {
		word = JS_deComment(word);
	}

	document.selection.Text = word;
	//如果是当前行，则保证移动到当前行第一个词之前
	if (isCurrentLine) {
		document.selection.CharLeft(false, 2);
		document.selection.StartOfLine();
		document.selection.WordRight(false, 0);
	} else {
		document.selection.StartOfLine();
	}

})();