Action

,←,

Posted by ryanodor, Last update over 1 year ago

Highlight text between commas in CSV format. Navigation is backwards.

Steps

  • script

    // This key is useful in navigating CSV (comma separated values) style documents. 
    
    // Find the cursor
    var selRange = editor.getSelectedRange();
    var beg = selRange[0];
    var len = selRange[1];
    
    /* Find the first comma or beginning-of-line after the cursor till the end of the draft. This position is relative to the cursor */
    
    var findComma = /$|,|;/m;
    
    // Get text before cursor so search
    
    var textBeforeCursor = editor.getTextInRange(0, beg);
    
    //Search backwards: requires reversing our text
    
    textBeforeCursor = textBeforeCursor.split('').reverse().join('');
    
    // Find the position of the first comma relative to the cursor
    
    var firstCommaRelPos = findComma.exec(textBeforeCursor).index;
    
    
    // Find second comma after cursor (backwards) and its relative position
    
    textBeforeCursor = editor.getTextInRange(0, beg - 1 - firstCommaRelPos);
    
    textBeforeCursor = textBeforeCursor.split('').reverse().join('');
    
    
    var secondCommaRelPos = findComma.exec(textBeforeCursor).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 = firstCommaAbsPos - secondCommaAbsPos;
    
    
    // Update selection
    editor.setSelectedRange(secondCommaAbsPos, selLen);
    

Options

  • 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.