kirby icon indicating copy to clipboard operation
kirby copied to clipboard

Writer field containing non-breaking space causes Kirby to think there are unsaved changes when switching languages

Open trych opened this issue 1 year ago • 3 comments

Description

When I have a writer field that contains a non-breaking space in a multi-language installation, Kirby will claim there are unsaved changes when I switch languages on the page containing the field even if there were no changes.

Expected behavior
Kirby should not claim there are unsaved changes when there are no changes.

To reproduce

  1. Grab a starterkit with the most recent v4 rc4
  2. Make the site multilanguage, add two languages.
  3. Add a non-breaking space to a writer field, e.g. the address field on the about page.
  4. Make changes to the secondary language to cause a translation file to be created (not sure if this is necessary)
  5. Save.
  6. Switch between languages, Kirby will now claim that there are unsaved changes.

Your system (please complete the following information)

  • OS: macOS 12.6
  • Browser: Chrome
  • Version: Kirby 4 rc4

trych avatar Nov 26 '23 12:11 trych

@trych As I have a multilingual starter kit with RC4, I was able to try out your instructions immediately. I deleted the .txt of the second language before. However, I could not detect any unsaved changes when switching languages.

gbdesign2023 avatar Nov 26 '23 13:11 gbdesign2023

Well, you need the .txt of the second language for the problem to appear.

trych avatar Nov 26 '23 18:11 trych

I can reproduce this issue. It happens quite often in our websites, for example when copying text from a Microsoft Teams message into a writer field. It’s also easy to add a non breaking space by mistake on Mac, by holding down ⌥ and pressing Space.

Any idea why this happens? I only found out that the non breaking space is sometimes stored as   and other times as \u00a0: So when switching languages, the backend sends the non breaking space as \u00a0, but in localstorage the non breaking space is stored as  .

Here’s a link to a ProseMirror forum post with a similar issue: https://discuss.prosemirror.net/t/non-breaking-spaces-being-added-to-pasted-html/3911

SebastianEberlein-JUNO avatar Feb 21 '24 11:02 SebastianEberlein-JUNO

If we simply replace the non-breaking spaces to standard spaces when pasting text, will this solve the problem permanently?

afbora avatar Jul 11 '24 09:07 afbora

This might solve the issue of accidentally pasting a text with non-breaking spaces. But in some cases, the user intentionally adds a non-breaking space, for example to prevent a line break within "10 kg" or "July 2024".

In a text field, I can paste non-breaking spaces or add them manually. So I think the writer field should behave the same.

SebastianEberlein-JUNO avatar Jul 11 '24 10:07 SebastianEberlein-JUNO

Could this also be fixed by https://github.com/getkirby/kirby/pull/6562? @afbora can you confirm?

distantnative avatar Aug 13 '24 16:08 distantnative