A comment script for WebCoder

December 14, 2007

A potential customer wrote me an e-mail about his thoughts on WebCoder. One of the things he missed, was a way to insert comments around a piece of CSS code, using a keyboard shortcut. I wrote him back with a single line of scripting code, and advised him to put it in a User button, and then create a keyboard shortcut to that button. He wrote me back and told me that it would be great if this single script could be used both in CSS and HTML, and that it would be great to have a script for removing the comments again - doing stuff like this is handy for debugging purposes, as most of us know. Here is the script I wrote for him - hopefully someone else can use it as well, or at least learn something from it :). Here it is:

if((Editor.Document.Language.Key == "PHP") or (Editor.Document.Language.Key == "CSS")): 
	startTag = "/*"
	endTag = "*/"
if(Editor.Document.Language.Key == "HTML"):
	startTag = "<!--"
	endTag = "-->"
s = Editor.SelectedView.SelectedText
if(s != ""):
	if((s.StartsWith(startTag)) and (s.EndsWith(endTag))):
		Editor.SelectedView.SelectedText = s.Substring(startTag.Length, s.Length - startTag.Length - endTag.Length)
		ScriptUtils.InsertTags(startTag, endTag)
Kasper (TSW) @ 10:06 pm in TSW

Leave a Reply