- AuthorPosts
- May 21, 2012 at 9:27 am #10372StefanParticipant
Hi Yutaka, i have an problem with replacing text
in an column/block selection from an macro.Tested with 11.0.5 and 11.1.7
My problem:
if i take the block selected text,
and manipulate it with an macro,
the macro works correct
but the text replacement in the document
replaces all selected lines
with the replacement of the first line only.Example:
Having an text like
First Line
Second Line
Third Lineand an code like
sel = document.selection.text;
Lines = sel.split("rn");
out = "";
for(L=0,E=Lines.length; L<E; L++){
line = Lines[L];
out += line.replace("i", "X") + "rn";
}
alert(out);
document.selection.text = out;
Test 1 – works fine:
– Select the whole text with line selection mode
First Line
Second Line
Third Line
– execute the macro
– the MsgBox shows the wanted result
– the lines are correct manipulated
FXrst Line
Second LXne
ThXrd LineTest 2 – my problem:
– Select only the first words in column selection mode
First Line
Second Line
Third Line
– execute the macro
– the MsgBox shows the wanted result
– BUT the lines in the selection are all replaced by the content of the first replacement:
FXrst Line
FXrstd Line
FXrst LineExpected was to get:
FXrst Line
Second Line
ThXrd LineQuestion:
what should i modify to let this work as indented?I can imagine workarounds like
– pos = get the right column pos of the selection
– process each line
– – – tempA = line.substring(0,pos)
– – – tempB = line.slice(pos)
– – – manipulate tempA
– out = tempA+tempB…but …is that really as indented ?
.
April 8, 2013 at 10:44 am #10918StefanParticipant
This is still the same with EmEditor v12.0.11.Since Yutaka didn’t response on this
I do not know if is this an bug?If yes, can this be improved please?
If No, what would be the indicated workaround please?
Stefan wrote:
Hi Yutaka, i have an problem with replacing text
in an column/block selection from an macro.Tested with 11.0.5 and 11.1.7
My problem:
if i take the block selected text,
and manipulate it with an macro,
the macro works correct
but the text replacement in the document
replaces all selected lines
with the replacement of the first line only.April 10, 2013 at 1:36 am #10924Yutaka EmuraKeymasterHello Stefan,
I am sincerely sorry for my delayed responses, but I am spending much of time these days to develop a new major version of EmEditor.
Currently, this is the specification because macros can’t paste text as a box format. The only way to work around this is using the Clipboard like this:
sel = document.selection.text;
Lines = sel.split("rn");
out = "";
for(L=0,E=Lines.length; L<E; L++){
line = Lines[L];
out += line.replace("i", "X") + "rn";
}
alert(out);
clipboardData.setData("BoxText", out);
document.selection.Paste(eeCopyUnicode);
I hope this helps.
Thanks!April 11, 2013 at 8:46 am #10943StefanParticipant
Woohoo :-DThat works! Many thanks.
But leads to next question:
how to determine between line and block selection?The answer I found in the help:
EmEditor Help – EmEditor Macro Reference – Selection Object
Mode PropertySo I can use code like this:
nMode = document.selection.Mode;
switch( nMode & eeModeMask ) {
case eeModeStream:
alert( "Stream selection mode.");
work();
document.selection.text = out;
break;
case eeModeLine:
alert( "Line selection mode." );
work();
document.selection.text = out;
break;
case eeModeBox:
alert( "Vertical selection mode.");
oldCB = clipboardData.getData("Text"); //store
work();
clipboardData.setData("BoxText", out);
document.selection.Paste(eeCopyUnicode);
clipboardData.setData("Text", oldCB); //re set
break;
}
if( nMode & eeModeKeyboard ) alert( "And also the keyboard selection mode." );
function work(){
sel = document.selection.text;
Lines = sel.split("rn");
out = "";
for(L=0,E=Lines.length; L<E; L++){
line = Lines[L];
out += line.replace("i", "X");
if(L<E-1)out += "rn";
}
alert(out);
}
Fun! 8-)
… I gonna try this now for my real work.
Thank you much Yutaka!
- AuthorPosts
- You must be logged in to reply to this topic.