joplin icon indicating copy to clipboard operation
joplin copied to clipboard

Beta editor add two newlines instead of one in certain contexts

Open laurent22 opened this issue 10 months ago • 4 comments

Operating system

Windows

Joplin version

3.0

Desktop version info

Start from this text:

- One

- Two
  • Add > before - One to quote it, then after "One" press Shift+Enter twice
  • Add a bullet point for example - test
  • Press enter once

Current behaviour

Instead of adding one newline, it's adding two even though in other contexts it would add only one.

Probably the editor tries to guess how many newlines there should be and incorrectly does so. I think we should reduce how much magic happens when typing in this editor unless we are 100% sure this is what the user will want. So pressing Enter should add one newline in almost all cases.

There are many other such strange behaviours when I use the editor. For example at some point it displayed my bullet point as code even though it wasn't wrapped in backticks. Cursor was also randomly moving to the next bullet point. But unfortunately I cannot consistently replicate this. But the idea is to make the editor less smart and more predictable.

Expected behaviour

No response

Logs

No response

laurent22 avatar Mar 28 '24 18:03 laurent22

I can reproduce this in the upstream CodeMirror 6 markdown demo: https://codemirror.net/try/?example=Markdown%20code%20block%20highlighting

I am unable to reproduce this in Joplin 2.14.20.

Upstream list indentation behavior changed in https://github.com/codemirror/lang-markdown/commit/fa289d542f65451957c562780d5dd846bee060d4. We upgraded to that version of @codemirror/lang-markdown in https://github.com/laurent22/joplin/commit/dfc08da40c20f3bf7a798b00634f99a866b17dad.

I see, thanks for confirming. I wonder if we could disable some, maybe most of these automatic behaviours? Basically starting from a relatively clean, sane editor, and then potentially enabling some of them back if we find they are useful.

Some obviously are, such as automatically adding a - after a newline when within a list, but others seem random, not that useful, and often get in the way. I've been using the beta Markdown editor more recently just to test, and I spend a lot of time backtracking and undoing what the editor has automatically done.

laurent22 avatar Mar 29 '24 12:03 laurent22

but others seem random, not that useful, and often get in the way. I've been using the beta Markdown editor more recently just to test, and I spend a lot of time backtracking and undoing what the editor has automatically done.

I don't see a way to configure insertNewlineContinueMarkup (the CodeMirror extension we use for list continuation which seems to be causing the issue referenced above). However, it should be possible to disable deleteMarkupBackwards (which I think is on by default), which makes the backspace key behave differently in lists and blockquotes.

Additionally, it may make sense to adjust this if conditional from the insertOrIncreaseIndent command (the legacy CodeMirror 5 editor does allow indenting new list items with tab, but doesn't allow this for existing list items):

https://github.com/laurent22/joplin/blob/2ae08ff46ed3db89ef1756863be7eae7cf4c9379/packages/editor/CodeMirror/markdown/markdownCommands.ts#L433

At present, this command decides whether the tab key should act like the "increase indent" button on mobile or just insert a tab.