Plugin: Resume Note [v0.2.3, 2024-11-17]

↺ Resume Note

A Joplin plugin to continue editing the last active note in each notebook, and go back to the last cursor position in the Markdown editor.

Features

  • Save and restore the last active note in each folder
  • Save and restore the cursor position in the Markdown editor for each note
    • Optionally use note properties to sync across devices and Joplin sessions
  • Set a home note or load the last active note on startup

sticky-note

5 Likes

OK, perhaps this wasn't the best name for the plugin. Let's try: "Resume Note" instead.

3 Likes

Very interesting, are you planning to support also the resume position when switching from Markdown editor to RTE (and viceversa) on the same note?

Ideally, yes, it should work for both. There is a way to get and set the cursor position in the RTE. I don't know if it's technically possible to do so via a Joplin plugin (I haven't tried).

It seems to be working with the RTE too.

However, it does not work when switching from RTE to MD (and viceversa) in the same note.

I like that a lot, thanks @shikuz!

As I'm switching a lot between multiple notes (especially via the Note Tabs plugin) I'd find it very helpful if not only the cursor position is saved but also the scroll position. Otherwise the resumed note still does not look exactly as I have left it.

Do you think this would be a possible feature for this extension?

It doesn't save after restart. And it the cursor position that it remembers jumps around quite a bit. Thank you for this plugin. It is a big time saver. Just needs some polish.

Good suggestion. I'll check.

1 Like

Check the settings. There's an experimental feature to save across restarts. Regarding "jumping around" I'm not sure what you mean by that, but perhaps setting the refresh interval to a lower value might help.

1 Like

It does two things. Across restarts AND across devices. That gave me pause. Not sure why, but it did.

The cursor will move by a line or two. I wonder it is has anything to do with some HTML mingled in the document. I will try to put together succinct example that can be replicated.

v0.2.0

  • added: save scroll position independently from cursor
  • added: save cursor selection (can be disabled in the settings)
  • improved: setScroll in content script
  • refactored: CodeMirror content script
1 Like

No. HTML doesn't seem to be the culprit. This is how I am testing now …

  1. Joplin 3.1.23, Desktop, Linux (Fedora specifically, but it is the AppImage)
  2. my custom userstyles.css and userchrome.css were removed
  3. I turned off all plugins except Persistent Editor Layout (to save a headache) and Resume Note
  4. I have scrolled to a spot and selected text
  5. I have scrolled to a spot and merely planted the cursor
  6. I switched between Default and VIM modes just to see what would happen.
  7. Markdown editor only.

What I have found.

Upon restart of Jopln:

  1. The only thing that survives a restart of Joplin is the note selected. This alone is a huge win, but the cursor is always kicked to the top and scrolled to the top and if something was selected, it is no longer selected
  2. The VIM mode shows you a flash of the cursor (helpful) whereas the the Default mode shows no cursor. The editor is not input-focused when you restart Joplin.

Switching between notes:

  1. It seems to work as designed. But only not when …
  2. With all plugins turned on, I get jumps in cursor location, scrolling, and selections do not retain.

Conclusion:

  1. the cursor location, selection, and scroll position is not retained upon restart, but the note selected is! Which is great.
  2. my issues with retained selection, cursor position, etc. is the result of some plugin conflict. I will try to narrow that down. So, far, I have eliminated a number of them.
1 Like

Interesting burble.

The set up:

  • I have test note 1 in position 1 in my notebook.
  • I have test note 2 in position 3 or 4 in my notebook.
  • I scroll then select some text in each (waiting the appropriate time for the plugin to record it).
  • I alternate between the notes to see that the positions are saved. They are.

The test:

  • I select test note 2.
  • I click Tools > Options
  • I click BACK

RESULT:

  • I am still on note 2 (good!)
  • Cursor moved to the top and nothing is selected (bad¡)
  • I click on note 1
  • Positions and selection are retained (good!)
1 Like

Conflicting plugins discovered thus far (all remove the selection; others also seem to fudge the positioning):

  • Favorites
  • Note Tabs
  • Outline — those three create a separate panel; related?
  • Note List (preview)
  • Folding in Code Mirror Editor
  • Whitespacer
  • Automatic Backlinks to note
  • Note overview

So far the Plugins that seem to play nice are:

  • Backup
  • Combine Notes
  • Conflict Resolution
  • Diff View
  • Hotfolder
  • Import Local CSS
  • Inline ToDo — not fully tested by actually creating an inline todo
  • Inline Tags
  • Kminder Mindmap
  • Markmap
  • Note Rename
  • Persistent Editor Layout
  • Quick Links
  • Space Indenter
  • Tagging
  • Templates

:slight_smile:

Hope this helps.

1 Like

Thanks @t0dd for the thorough testing!

I made some improvements in v0.2.1 to the scrolling method, cursor update, and how the data is stored (without sync / note properties) so that it is persistent across sessions. Hopefully these changes will improve the user experience and compatibility with other plugins.

That said, I have some of the aforementioned conflicting plugins, and I installed some of the others, and did not experience problems on my end. So I suspect that the issue may be related to the general impact of plugins on Joplin's speed and latency (this also obviously depends on your machine). To address this, I added a new setting that I encourage you to explore: Delay before setting cursor and scroll position (in ms). This delay is meant to ensure that the editor is fully loaded before trying to set the cursor. Some users may be able to decrease this setting for a smoother experience, while others may need to increase it in order for the plugin to work properly. Perhaps in the future I'll have a better solution for this (like getting a ping from the editor once it's loaded).

v0.2.1

  • added: save cursor position across sessions in settings data (default)
  • added: clear user data from notes when not using this method to save the cursor
  • added: commands: clearUserData, clearSettingsData
  • added: setting restoreDelay: Delay before setting cursor and scroll position (in ms)
  • improved: increased default restoreDelay to handle slower clients
  • improved: 2-step scroll
  • improved: update saveSelection on setting change
  • fixed: update cursor position only after restored previous cursor
2 Likes

Are you sure about that? I've tested the plugin in the Rich Text Editor, however to no avail. It doesn't seem to do anything for me, i.e. the note after switching back to it always starts at the beginning.

I do agree that having this plugin work for both editors and also when switching between the two would be perfect :pleading_face:.

Hmm. I get the behavior noted no matter how long I wait before switching to a different note. And if I disable all those top listed plugins, everything works appropriately.

The desktop I am testing all of this on is rather beefy: 5GHz CPU, 32GiB RAM.

My settings in Joplin:

Resume Note v0.2.1
Refresh interval for cursor and scroll position (ms): 2000
Delay before setting cursor and scroll position (in ms): 300
Save cursor selection
Sync data using note properties (Experimental)

Note. I don't really understand what those two timing settings do. You explain them in your release notes, but I still don't understand. To me, they sound like they do the same thing.

I'm trying to see a pattern with the Plugins that affect this situation and I am scratching my head. I mean, Whitespacer goes in and changes the edit window, so I can see that, depending on ordering of Plugin runs, maybe altering the highlighted selection. Dunno. This is mysterious.

Just to clarify: I'm aware that it doesn't work, as it hasn't been implemented yet. I wasn't able to make it work, but perhaps someone else will and open a PR at some point. (I know the response was to @bj-286, just thought I'll update on the subject.)

EDIT: I was finally able to reproduce the problem with your help (thanks!). I've released v0.2.2 to try to solve it. Here's a settings guide:

This setting determines how often the cursor is saved. EDIT: Renamed to Refresh interval for saving cursor and scroll position (ms).

This setting determines how long the plugin waits before trying to set in the editor the cursor position.

New setting! (v0.2.2)
Delay before starting the plugin (in ms): 1000

Since you love these timing settings, I've added another one. :wink: This one is meant to help the plugin setup the editor without interference from other plugins. I hope that the default value will work for you, otherwise try to increase it to 2000-3000.

@t0dd Hope you'll see this edited message.

1 Like