EmEditor (text editor) Forum Index
   Questions and Answers about EmEditor Core
     Java Script Help
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
dmitryl
Posted on: 2/11/2012 4:16 am
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Java Script Help
I need a help for writing a JavaScript, which place a character (let's say the [] brackets) around the highlighted text.
Thank you!
ToadLoadin
Posted on: 2/11/2012 6:20 am
Just can't stay away
Joined: 7/4/2008
From: China
Posts: 119
Re: Java Script Help
Hi, I'm not a JavaScript geek, but I guess you could use code like:

charBefore = "[";
charAfter = "]";
strSelectedText = document.selection.Text;

document.selection.Text = charBefore + strSelectedText + charAfter;
Stefan
Posted on: 2/11/2012 6:42 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: Java Script Help
Yes i do it the same way:



#title = "Enclose selection";
#tooltip = "Enclose an selection with an sign";
// Select some text and execute this macro to put an sign 
// in front and at the end of the selected text;

//mySign = "%"
  mySign =  prompt( "Enter sign to enclose selection:", "%" );

  selText = document.selection.Text;
  outText = mySign + selText + mySign;


  //alert(outText);
  document.selection.Text = outText;



Should be easy to modify this code
and replace mySign with LeadingSign and TrailingSign
dmitryl
Posted on: 2/11/2012 7:29 am
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: Java Script Help
ToadLoadin & Stefan! Thanks a lot!
But now I need one more tip please
Does JavaScript supports Regular Expressions?
Let's say I need to replace a text, which matches the pattern ^(;[ ]\*[ ])(.*) with this one: \1\[\2\]
How would I do so?
Thank you!
Stefan
Posted on: 2/11/2012 12:06 pm
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 263
Re: Java Script Help

EmEditor Help - EmEditor Macro Reference - Tutorial > Using Regular Expressions

EmEditor Help - How to - Search > Regular Expression Syntax

dmitryl
Posted on: 2/11/2012 12:42 pm
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: Java Script Help
Stefan, the issue is not with the RegEx syntax, but how use the RegEx expressions inside of the Java Scripts (please see my previous post).
How should I let to Java know that I wrote a regular expression and not just a string?
Thank you!
dmitryl
Posted on: 2/11/2012 1:20 pm
Just can't stay away
Joined: 12/25/2009
From:
Posts: 73
Re: Java Script Help
Stefan,
I've got it!
Thanks!
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文