Action

add/goto pin

Posted by @FlohGro, Last update 7 months ago

UPDATES

7 months ago

Set after success setting to β€žnothingβ€œ

created by @FlohGro / more on my Blog

Adds a “πŸ“” emoji to the current cursor position. If there is another “πŸ“” emoji in the current draft the action scrolls to that position.

Why? If you take notes in (really) long drafts it could be annoying to always scroll to your last position when you open that draft again. This action is a simple solution to that, just run it once you finished taking notes to add a pin and run it when you’re back at it to scroll to that position

The action also supports multiple “πŸ“” emojis in a draft - so you can pin several positions in a draft. It will cycle between the different “πŸ“” emojis. To add a second (or more) you need to type the emoji manually to simplify it.

If you want to change the used “πŸ“” emoji you can replace it in the script step by editing the variable ‘pinEmoji’


If you find this useful and want to support me you can donate or buy me a coffee

Buy Me A Coffee

Steps

  • script

    // add/goto pin
    // created by @FlohGro@social.lol
    
    const pinEmoji = "πŸ“"
    
    let text = editor.getText()
    const currentPosition = editor.getSelectedRange()
    // -> move to end of selection if more charactesrs are selected
    let positionToUse = currentPosition[0] + currentPosition[1]
    
    if (text.includes(pinEmoji)) {
        // pin emoji is included check amount of pin emojies
        const firstIndex = text.indexOf(pinEmoji);
        const lastIndex = text.lastIndexOf(pinEmoji);
        if (firstIndex !== -1 && firstIndex === lastIndex) {
            // There's only one occurrence of the pin emoji
            if (positionToUse == firstIndex + pinEmoji.length) {
                // we already are at the pin -> remove the pin
                editor.setTextInRange(positionToUse - pinEmoji.length, pinEmoji.length, "")
                editor.setSelectedRange(positionToUse - pinEmoji.length, 0)
                app.displayInfoMessage("pin removed")
            } else {
                positionToUse = firstIndex + pinEmoji.length;
                editor.setSelectedRange(positionToUse, 0);
                app.displayInfoMessage("jumped to pin")
            }
        } else if (firstIndex !== -1 && firstIndex !== lastIndex) {
            // There are multiple occurrences of the pin emoji
            const nextIndex = text.indexOf(pinEmoji, positionToUse + pinEmoji.length);
            if (nextIndex !== -1) {
                positionToUse = nextIndex + pinEmoji.length;
            } else {
                positionToUse = firstIndex + pinEmoji.length;
            }
            app.displayInfoMessage("found several pins, jumped to next occurence")
            editor.setSelectedRange(positionToUse, 0);
        }
    
    } else {
        // pin emoji is not included, add it to current position of the cursor
        editor.setTextInRange(positionToUse, 0, pinEmoji)
        editor.setSelectedRange(positionToUse + pinEmoji.length, 0)
        app.displaySuccessMessage("pin added")
    }
    
    editor.activate()

Options

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