Action

Move cursor forward by word

Posted by agiletortoise, Last update over 6 years ago

Move cursor position forward one word at a time.

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
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.