- AuthorPosts
- October 13, 2014 at 4:38 am #19434Mr KTParticipant
Hello,
Is there a way to run a search/replace type macro with “In the selection Only” selected if any text/columns are highlighted before the macro is run, but run on the entire file if no text is highlighted when the macro is called?Could this functionality be added otherwise?
October 13, 2014 at 4:14 pm #19435Yutaka EmuraKeymasterHello Mr. KT,
You can replace text only in the selection by using (JavaScript):
document.selection.Replace( "find", "replace", eeReplaceSelOnly | eeReplaceAll );
For the “find”, please use EmEditor v14.6.0 beta 18 or later, and you can do this:
document.selection.Find( "find", eeFindNext | eeFindReplaceSelOnly );
I hope this helps.
Thank you!
October 14, 2014 at 2:59 am #19437Mr KTParticipantThanks Yutaka,
so to clarify – if I have a comma separated file as follows:
_______
A1,B1,
A2,B2,
A3,B3,
etc.
________is there a way to run a SINGLE macro so if no text is selected, it will run on the entire file & produce this (just a simple example, searching for regexp start of line ^, replace with “):
_______
“A1,B1,
“A2,B2,
“A3,B3,
etc.
_______BUT if I am in CSV Mode (so the file is now in columns), highlight Column “B” and run the same macro, it will produce this:
_______
A1,”B1,
A2,”B2,
A3,”B3,
etc.
_______It seems there needs to be some way for the single macro to know if text is highlighted or not, before it can run on the whole file or just selected text?
Would an additional flag that checks if text is selected first, then run the macro and it will work on that selection only, but if text isn’t selected, if will run on the whole file instead
(e.g. eeReplaceSelOnly_else_eeReplaceall)?Thank you for your efforts.
October 14, 2014 at 10:47 am #19442Yutaka EmuraKeymasterHello,
You can use the following code to check whether the selection exists…
// check whether selection exists if( !document.selection.IsEmpty() ) { // selection exists document.seleciton.Replace( ... ); }
October 14, 2014 at 10:56 am #19443Mr KTParticipantFantastic!
Thank you Yutaka. - AuthorPosts
- You must be logged in to reply to this topic.