joplin-plugin-cm-linenumbers icon indicating copy to clipboard operation
joplin-plugin-cm-linenumbers copied to clipboard

Make line numbers relative

Open jannes opened this issue 4 years ago • 7 comments

This makes the displayed line numbers relative to current line. The current line number will also be displayed. This is the same behavior as Vim hybrid line numbers (:set number relativenumber).

I find this the most useful when using Vim. We could also add a build option to let the user choose between absolute and relative.

reference for implementation: https://github.com/codemirror/CodeMirror/issues/4116

jannes avatar Dec 02 '20 12:12 jannes

Awesome work, @jannes 👍 It works perfectly. Could you please see if you could add the option to choose between absolute and relative. If you'd like to do that as a separate PR, that's ok too (Let me know if that's the case).

shantanugoel avatar Dec 02 '20 13:12 shantanugoel

I'll have a look, so you think just having to different npm commands to build one or the other would be good? E.g npm run dist-absolute, npm run dist-relative

jannes avatar Dec 03 '20 09:12 jannes

I was thinking of more like adding a setting using joplin.settings API that users could flip on/off. But in case it looks time consuming to do, different npm commands is ok to do for now and I can add the settings myself once I get a breather from work.

shantanugoel avatar Dec 03 '20 16:12 shantanugoel

No, I agree that would be the nicest, but are you sure that this is already possible with the current plugin system? If so, I would have a look at this the coming days

Edit: I don't think it is possible yet to have subsettings for plugins. But we can add an extra menu item 'Toggle absolute/relative linenumbers' in the 'View' menu. What do you think?

jannes avatar Dec 03 '20 16:12 jannes

But we can add an extra menu item 'Toggle absolute/relative linenumbers' in the 'View' menu.

Yes, this should be good.

shantanugoel avatar Dec 03 '20 21:12 shantanugoel

Still haven't found the time to implement the setting.

But I notice that the relative line numbers do not work consistently, after some time of having Joplin open it stops working and just uses the absolute numbering. Can you confirm this behavior?

It seems like the event handler for 'cursorActivity' is overriden/removed somehow, can not explain this otherwise.

jannes avatar Dec 09 '20 12:12 jannes

Hmm, I haven't seen that behavior. My instance has been open for many days but it's still showing relative numbers. Will keep an eye out for it.

shantanugoel avatar Dec 11 '20 13:12 shantanugoel