Drafts Action Directory

Move cursor forward by word

Posted by agiletortoise, Last update 11 days ago

Move cursor position forward one word at a time.

Install

Steps

  • script

    // move cursor to last word break
    let [st, len] = editor.getSelectedRange();
    let text = editor.getText();
    let end = text.length - 1;
    
    let isWhitespace = (c) => {
    	return /\s/.test(c)
    }
    
    let f = () => {
    	let newSt = st;
    
    	if (end <= 0) { return; }
    	if (newSt == end) { return; }
    	let inFirstSpace = false;
    
    	while (newSt <= end) {
    		newSt += 1;
    		
    		if (isWhitespace(text.charAt(newSt))) {
    			if (!inFirstSpace) {
    				inFirstSpace = true;
    			}
    		}
    		else {
    			if (inFirstSpace) {
    				break;
    			}
    		}
    	}
    	editor.setSelectedRange(newSt, 0);
    }
    
    f();
    

Options

  • After Success Nothing
    Notification Error
    Log Level None

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.