Posted by ryanodor, Last update about 1 year ago

Script key: Select text between commas.


  • script

    // Select some text in between commas.
    // This key is useful in navigating CSV style files. 
    // Find the cursor
    var selRange = editor.getSelectedRange();
    var beg = selRange[0];
    var len = selRange[1];
    /* Find the first comma or end-of-line after the cursor till the end of the draft. This position is relative to the cursor */
    var findComma = /,|;|$/m;
    var firstCommaRelPos = findComma.exec(editor.getTextInRange(beg,editor.getText().length)).index;
    // Find second comma after cursor
    var secondCommaRelPos = findComma.exec(editor.getTextInRange(beg + firstCommaRelPos + 1, editor.getText().length)).index;
    // Set the absolute postions for the text after the first comma
    var firstCommaAbsPos = beg + firstCommaRelPos +1;
    var secondCommaAbsPos = beg + firstCommaRelPos + secondCommaRelPos + 1;
    // Get the selection length
    var selLen = secondCommaAbsPos - firstCommaAbsPos;
    // Update selection
    editor.setSelectedRange(firstCommaAbsPos, selLen);


  • After Success Nothing
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.