Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #28213
    Yang Yang
    Participant

    Hello, could you kindly give me an example of processing multiple selections in the macro? For example, suppose “abc” and “xyz” are selected in the document, and I want to change their text to “[abc]” and “[xyz]”, respectively. Thanks!

    #28214
    Yutaka Emura
    Keymaster

    If the Auto-Complete Brackets/Quotation Marks option is set, you can simply type [.

    However, I know you want to write a macro to process multiple selection scenarios. Here is an example:

    
    sInsertBefore = "[";
    sInsertAfter = "]";
    var axT = [];
    var ayT = [];
    var axB = [];
    var ayB = [];
    
    Redraw = false;
    CombineHistory = true;
    nCount = document.selection.Count;   // retrieves the number of selections
    for( i = 1; i <= nCount; ++i ) {     // loop through multiple selections
    	x = document.selection.GetTopPointX( eePosLogical, i );  // retrieve x of the left side of each selection
    	axT.push( x );
    	y = document.selection.GetTopPointY( eePosLogical, i );  // retrieve y of the left side of each selection
    	ayT.push( y );
    	x = document.selection.GetBottomPointX( eePosLogical, i );  // retrieve x of the right side of each selection
    	axB.push( x );
    	y = document.selection.GetBottomPointY( eePosLogical, i );  // retrieve y of the right side of each selection
    	ayB.push( y );
    }
    
    for( i = nCount - 1; i >= 0; --i ) {
    	document.selection.SetActivePoint( eePosLogical, axB[i], ayB[i] );   // set the cursor to the right side of each selection
    	document.selection.Text = sInsertAfter;    // insert ']'
    	document.selection.SetActivePoint( eePosLogical, axT[i], ayT[i] );   // set the cursor to the left side of each selection
    	document.selection.Text = sInsertBefore;   // insert '['
    }
    
    #28215
    Yang Yang
    Participant

    Thank you very much! More steps that I expected, honestly.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.