Action
add/goto pin
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
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