Tapatalk

ColumnInsert2Fit.js - Insert clipboard into columns without inserting additional white space

ColumnInsert2Fit.js - Insert clipboard into columns without inserting additional white space

326
Basic UserBasic User
326

    Feb 20, 2019#1

    This script will insert the current clipboard contents in "column paste" but not in a rectangular block but in a "line by line" basis - this will avoid pasting additional spaces avoiding the need to clean it up.

    Example, I often have something like this, | caret position

    <img src='|'
    <img src=''
    <img src=''
    <img src=''
    and I have this in my clipboard - as you can see various lengths:

    image-portrait.png
    image-landschape.png
    thumbnail.png
    next.jpg
    after running the script it will (should) look like this:

    <img src='|image-portrait.png'
    <img src='image-landschape.png'
    <img src='thumbnail.png'
    <img src='next.jpg'
    If you would paste it in column mode it would look like this - note the additional spaces added to make it a "rectangle":

    <img src='image-portrait.png  '
    <img src='image-landschape.png'
    <img src='thumbnail.png       '
    <img src='next.jpg            '
    Script:

    Code: Select all

    // -----------------------------------------------------------------------------------
    // Script:
    // - ColumnInsert2Fit.js
    //
    // Purpose:
    // - Insert clipboard into columns without inserting additional white space
    // 
    // example, before: | is caret postion
    // (column mode)
    // 
    // <a href='|'></a> 
    // <a href=''></a>
    // 
    // clipboard contents:
    // 
    // short-url.php
    // a-very-long-url.php?p=1
    // 
    // standard paste into column mode result:
    // 
    // <a href='|short-url.php         '></a> // now you would have to edit the link to remove the additional spaces
    // <a href='a-very-long-url.php?p=1'></a>
    // 
    // script result:
    // 
    // <a href='|short-url.php'></a>
    // <a href='a-very-long-url.php?p=1'></a>
    // 
    // Author / UE forum thread:
    // - hugov
    // - http://forums.ultraedit.com/columninsert2fit-js-insert-clipboard-into-columns--t18073.html
    //
    // History:
    // - v1.0 first version (February 2019)
    //
    // -----------------------------------------------------------------------------------
    
    if (UltraEdit.document.length > 0) // returns number of active documents
    {
       var LineNumber = UltraEdit.activeDocument.currentLineNum;
       var CurrentColumn = UltraEdit.activeDocument.currentColumnNum;
       var ctext = UltraEdit.clipboardContent;
       var c = ctext.split("\n");
       var arrayLength = c.length;
       var colmode = false;
       if (typeof(UltraEdit.columnMode) == "boolean") colmode = UltraEdit.columnMode;
       else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") colmode = UltraEdit.activeDocument.columnMode;
    
       UltraEdit.selectClipboard(1);
       if (typeof(UltraEdit.columnModeOn) == "function") UltraEdit.columnModeOn();
       else if (typeof(UltraEdit.activeDocument.columnModeOn) == "function") UltraEdit.activeDocument.columnModeOn();
       for (var i = 0; i < arrayLength; i++) {
          UltraEdit.clipboardContent = c[i].trim();
          UltraEdit.activeDocument.paste();
          UltraEdit.activeDocument.key("DOWN ARROW");
       }
       UltraEdit.selectClipboard(0);
       if (colmode == false) {
          if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
          else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
       }
       UltraEdit.activeDocument.gotoLine(LineNumber,CurrentColumn);
    }