getkirby / kirby

Kirby's core application folder
https://getkirby.com
Other
1.32k stars 168 forks source link

[v4] Textarea toolbar button click makes scroll position jump #5906

Closed nilshoerrmann closed 1 year ago

nilshoerrmann commented 1 year ago

Description

When editing content in a textarea field, the toolbar creates unexpected Markdown for block elements. Think of this existing content, the pipe being the cursor:

# An example |headline

If I select headline 3 in the toolbar, the following will be created:

# An example ### |headline

Same example as before, if I click headline 1 again to unselect it and make the current line a paragraph again, the following will be created:

# An example # |headline

Expected behavior
The block level elements should alter the Markdown blocks and not thus change the marks at the very beginning of the line.

To reproduce

title: Markdown Test
fields:
  text:
    label: Text
    type: textarea

Your setup

Kirby Version
Kirby 4 Beta 3 on Firefox 119 (macOS Sonoma)

nilshoerrmann commented 1 year ago

Additional issue: when selecting a mark in the toolbar, the panel jumps to the top when scrolled. Test with long content that will expand the textarea below "the fold".

distantnative commented 1 year ago

Is the top issue any different than v3?

nilshoerrmann commented 1 year ago

Oh, that's a good question I will have to check. Haven't used the textarea field with toolbar in v3 for a long time.

nilshoerrmann commented 1 year ago

I just checked on 3.9 and the behaviour is the same. But I'm sure this was handled differently in earlier versions (like very early v3).

distantnative commented 1 year ago

I really doubt that. Looking at earlier versions e.g. 3.3 it always seems to have been a simple prepend to the cursor selection.

Maybe you're thinking of https://github.com/fabianmichael/kirby-markdown-field ?

nilshoerrmann commented 1 year ago

The Markdown field is what we usually use because of the highlighting. So yes, that might well be possible. But do we agree that the textarea behaviour is a bit … surprising? 😀

distantnative commented 1 year ago

Yes and no. The textarea buttons have been quite basic, so I do see that one could request the enhancement that they get smarter. But that'd also mean adding quite some more logic, which could be worth it. But it's not a simple fix or changing it back to how it once was.

In fact, with v4 the buttons get a tiny bit smarter: Where in the past wrapping ** were always just added/inserted (again and again and again with each click), they now do get removed when the current selection is already wrapped.

distantnative commented 1 year ago

Added as idea: https://kirby.nolt.io/588

Will focus this issue on the jumping bug you describe in post # 2

nilshoerrmann commented 1 year ago

The main issue I see it that it generates invalid Markdown which is actually the reason why we provide the buttons to editors in the first place: they are not fluent enough in Markdown to write it blindly.

But, please, feel free to consider this a feature request :+1:

nilshoerrmann commented 1 year ago

Ah, just saw the Nolt entry. Thanks!