Action

Hard Wrap

Posted by agiletortoise, Last update about 5 hours ago

Hard wrap lines in the text selection. Configured with a default max line length of 62 characters, but action can be configured for other values (select “Configure” in context menu of the action).

Steps

  • configurationKey

    name
    Max Characters
    key
    maxCharacters
  • script

    // func to wrap string
    const wordWrap = (str, max, br = '\n') => str.replace(
    	new RegExp(`(?![^\\n]{1,${max}}$)([^\\n]{1,${max}})\\s`, 'g'), `$1${br}`
    )
    
    const maxChars = context.configuredValues["maxCharacters"]
    let sel = editor.getSelectedText()
    let [st, len] = editor.getSelectedRange()
    
    editor.setSelectedText(wordWrap(sel, maxChars))
    editor.setSelectedRange(st, wordWrap(sel, maxChars).length)

Options

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