Scratchpad per note #1613
Replies: 5 comments 9 replies
-
| 
         I've thrown together this scrappy script that adds a widget in the right sidebar which provides a scratchpad for every note. really, it is an editable view on a note label called #scratchpadContent EDIT: woops, there was a little bug in the one i posted yesterday. try pasting this into a note and adding the  let TPL = `
<style>
.scratchpad-widget {
    border: 1px solid var(--main-border-color);
    min-height: 10em;
    resize: vertical;
    width: 100%;
    font-family:var(--font-code); 
}
</style>
<textarea class="scratchpad scratchpad-widget">
</textarea>
`
class ScratchpadWidget extends api.CollapsibleWidget {
    get contentLabelName () {
        return "scratchpadContent"
    }
    
    get contentLabel () {
        return this.note.getLabel(this.contentLabelName)
    }
    
    get hasContentLabel () {
        return this.note.hasLabel(this.contentLabelName)
    }
    
    isEnabled() {
        return super.isEnabled() && !this.note.hasLabel("scratchpadWidgetDisabled")
    }
    get widgetTitle() {
        return "Scratchpad"
    }
    
    get parentWidget() {
        return "right-pane"
    }
    
    async setContent(content = "") {
        let result = await api.runOnBackend((noteId, value) => {
            api.getNote(noteId).setLabel("scratchpadContent", value)
        }, [this.note.noteId, content])
    }
    async doRenderBody() {
        this.$body.html(TPL);
        this.$scratchpad = this.$body.find(".scratchpad")
        this.$scratchpad.on("input", event => {
            // TODO debounce
            this.setContent(this.$scratchpad.prop("value"))
        })
    }
    async refreshWithNote(note) {
        if (this.hasContentLabel) {
            this.$scratchpad.text(this.contentLabel.value)
            this.$scratchpad.prop("value", this.contentLabel.value)
        } else {
            this.$scratchpad.text("")
            this.$scratchpad.prop("value", "")
        }
    }
    entitiesReloadedEvent({loadResults}) {
        if (loadResults.isNoteReloaded(this.noteId) || loadResults.isNoteContentReloaded(this.noteId)) {
            this.refresh();
        }
    }
}
module.exports = new ScratchpadWidget()it's a scrappy little go-getter  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         Thank you, @chee !  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         I am new to Trilium and not a developer. how do I mark it as #Widget? When I create a new note I select JAVA, with JS Frontend I am getting a parsing error right at the beginning "unexpected Token TPL at Line1.  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         You need to ad #widget to the "Owned Attributes" of the note. Once you do that, you need to reload the frontend.  | 
  
Beta Was this translation helpful? Give feedback.
-
| 
         An update for this ScratchPad Widget support close & reopen widget from right panel  | 
  
Beta Was this translation helpful? Give feedback.



Uh oh!
There was an error while loading. Please reload this page.
-
Sometimes when I'm writing a note I want to keep track of a few related things which, at the moment of writing, I can't yet find a proper spot for them. This could be a name, a word, a short sentence, an URL, and so on.
Let's say I'm writing an article for my blog. At some point, I need to mention something which is not fully organized in my mind. So, I write down these secondary bits of notes so to speak but I don't want to create sub-notes. Ideally, I'd rather store these bits of information on a side panel so I could quickly peek and at the right moment bring back what I need.
So, the idea is for a sort of scratchpad area where to store temporary information.
Beta Was this translation helpful? Give feedback.
All reactions