Action

New draft from each selected line

Last update over 5 years ago

A new draft is created from each non-blank line selected in the current draft.

( If the selection is not extended, then drafts are created for all non-blank lines in the whole draft )

Steps

  • script

    (() => {
        'use strict';
    
        // main :: Drafts ()
        const main = () => draftsFromLines(
            selectedOrAllLines()
        );
    
        // selectedOrAllLines :: Editor () -> [String]
        const selectedOrAllLines = () => {
            const e = editor;
            return (
                e.getSelectedRange()[1] > 0 ? (
                    e.getTextInRange(
                        ...e.getSelectedLineRange()
                    )
                ) : draft.content
            ).split('\n');
        };
    
        // draftsFromLines :: [Strings] -> [UUID]
        const draftsFromLines = xs =>
    
            // Concatenation (of map result) purges empty lists
            // ( no new draft created from any blank line )
    
            concatMap(
                // Function applied ...
                s => s.length > 0 ? [
                    Object.assign(
                        Draft.create(), {
                            content: s
                        }
                    )
                ] : [],
    
                // ... to each item of this list.
                xs
            )
            .reverse() // Inbox order matching line order
            .map(x => (x.update(), x.uuid));
    
        // concatMap :: (a -> [b]) -> [a] -> [b]
        const concatMap = (f, xs) => [].concat(...xs.map(f));
    
        // MAIN ---
        const result = main();
        return (
            console.log(result),
            result
        );
    })();
    

Options

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