⌘⌥C Copy only the visible lines in a TaskPaper 3 selection

TaskPaper 3’s default ⌘C is an outline selection copy, which doesn’t abandon any folded or filter-hidden descendants which selected lines may have, and allows for outline copy-paste.

Here, as a less powerful supplement for more limited and particular uses, is a purely textual selection copy, for moments when you just want to capture a visual snapshot of a particular folding or filtering view of the TaskPaper 3 outline editor state (and don’t want to bring any hidden descendants into the clipboard).

JavaScript for Automation source:

// COPY ONLY THE SELECTED LINES WHICH ARE VISIBLE IN TASKPAPER 3
// (not copying lines which are folded or filtered out of view)

(function () {
    'use strict';

    // FUNCTION FOR TASKPAPER CONTEXT
    
    function TaskPaperContext(editor) {

        // Only the visible component of the selection

        return editor
            .selection
            .selectedItems
            .filter(function (item) {
                return editor.isDisplayed(item);
            })
            .map(function (item) {
                return Array(item.depth)
                    .join('\t') + item.bodyString;
            })
            .join('\n');

    }
    
    // JAVASCRIPT FOR AUTOMATION CONTEXT

    var ds = Application('com.hogbaysoftware.TaskPaper3')
        .documents,
        doc = ds.length ? ds[0] : undefined;

    if (doc) {

        // COPY ONLY THE VISIBLE LINES WHICH ARE SELECTED
        var a = Application.currentApplication(),
            sa = (a.includeStandardAdditions = true, a),
            
            strLines = doc.evaluate({
                script: TaskPaperContext.toString()
            });

        sa.setTheClipboardTo(
            strLines
        );

        return strLines;
    }

})();
4 Likes

LOVE IT - thank you!
I was just writing a post on this, not understanding what the heck was going on with my copy/paste functions. I believe this is the only time I have ever seen the suggested help (on any forum) have a relevant answer to a topic I was about to post (in a predictive fashion). Love it!

1 Like