Page MenuHomePhabricator

VisualEditor: Ctrl+Shift+Space/Opt+Space to insert a non-breaking space (NBSP)
Closed, ResolvedPublic1 Estimated Story Points

Description

Editor requests support for adding non-breaking spaces ( ), keyboard shortcut?

From MediaWiki Feedback:

How do I enter a no-break space (& nbsp;) into the source text via the keyboard? Something like Ctrl+Space would be nice … And, BTW, can I see the difference between a regular space and a no-break space?

Troubled @sset Work • Talk • Mail‎18:03, 8 July 2013


Alternative: T70429: VisualEditor: Add non-breaking space (nbsp) to the "special character" dialog

Event Timeline

bzimport raised the priority of this task from to High.Nov 22 2014, 2:04 AM
bzimport set Reference to bz51045.
Jdforrester-WMF lowered the priority of this task from High to Low.Jan 15 2015, 12:31 AM
Jdforrester-WMF set Security to None.
Aklapper renamed this task from VisualEditor: Ctrl-Space to insert an NBSP, and a way to see the difference to VisualEditor: Ctrl-Space to insert a non-breaking space (NBSP), and a way to see the difference.Mar 19 2015, 11:09 AM

For this feature, I suggest Ctrl Shift Space rather than Ctrl Space.

Reasons :

  1. Ctrl Space is already taken for Spotlight on Mac.
  2. The Word feature for entering a non-breaking space is pressing Ctrl Shift Space.

The Word feature is quite well known. Having an inconsistency here would confuse users.

For this feature, something would need to be clarified :

What would the keyboard combination insert in the wikicode ?

  1. The character non-breaking space
  2. The HTML entity  

These are two different things.

For this feature, I would recommend inserting the character non-breaking space. Inserting the non-breaking space character leaves the wikicode natural and readable. Well, as readable as the wikicode already is. ;-)

Inserting only the character is not persistent: there is at least one browser which replaces non-breaking spaces with normal spaces in <textearea>s (may be Firefox? don’t remember). See this diff for an example of such a replacement (I read unfortunately more talk pages than articles and don’t remember an recent example in ns-0).

Of course there are safe places (before colons, inside French quotations marks) where MediaWiki does not require a special space to render a non-breaking one and where it would make no difference.

Inserting only the character is not persistent: there is at least one browser which replaces non-breaking spaces with normal spaces in <textearea>s (may be Firefox? don’t remember). See this diff for an example of such a replacement (I read unfortunately more talk pages than articles and don’t remember an recent example in ns-0).

Sometimes, a replacement of non-breaking spaces with normal spaces in the text area occurs (occurred). This is (was) caused by a bug of Firefox, that was fixed years ago. Now, this happens rarely, because people having a fossil Firefox are rare. Over time, such replacements will be rarer and rarer.

Of course there are safe places (before colons, inside French quotations marks) where MediaWiki does not require a special space to render a non-breaking one and where it would make no difference.

These safe places exist. But :

  1. I think that these safe places are a setup specific to the site fr.wikipedia.org, and do not apply in the general case of a MediaWiki. I may be wrong here.
  2. These safe places do not work in links.
  3. These safe places do not work in wikicode.
  4. « The safe places for french quotes » do not work in the visual editor — this is a bug, by the way.

Or you could somehow annotate the whole word as nowrap. Arguably <nowrap>100 °C</nowrap> would be clearer than 100&nbsp;°C

Change 255937 had a related patch set uploaded (by Bartosz Dziewoński):
Add command to insert non-breaking space, triggered by Ctrl Space (PC) / Opt Space (Mac)

https://gerrit.wikimedia.org/r/255937

matmarex renamed this task from VisualEditor: Ctrl-Space to insert a non-breaking space (NBSP), and a way to see the difference to VisualEditor: Ctrl+Space/Opt+Space to insert a non-breaking space (NBSP).Nov 29 2015, 6:18 PM

I also think CTRL+space is quite a high profile shortcut to assign to a relatively uncommon feature.

Change 255937 abandoned by Bartosz Dziewoński:
Add command to insert non-breaking space, triggered by Ctrl Space (PC) / Opt Space (Mac)

Reason:
This doesn't seem to be moving forward. And last time I checked, non-breaking spaces in VE-MW (implemented as MWEntity) had a bunch of problems like T119838, T119839, T119840; so we wouldn't really want to point users towards them without fixing that first.

https://gerrit.wikimedia.org/r/255937

If those are blockers, can they be listed as such?

Change 255937 had a related patch set uploaded (by Bartosz Dziewoński):
Add command to insert non-breaking space, triggered by Ctrl Space (PC) / Opt Space (Mac)

https://gerrit.wikimedia.org/r/255937

Option Space on Mac is a good combination. Regarding Ctrl Space on PC, would Ctrl Shift Space work as well? It would be good.

Regarding Ctrl Space on PC, would Ctrl Shift Space work as well? It would be good.

Yes, that patch actually used both of these combinations, but space in the commit summary is limited ;)

matmarex removed a project: Patch-For-Review.
matmarex subscribed.

@Nnemo: +1 for Ctrl-Shift-Space which also works on LibreOffice.

  1. « The safe places for french quotes » do not work in the visual editor — this is a bug, by the way.

All the safe places fail in the visual editor. I sometimes have line breaks before colons, semicolons, etc.

Or you could somehow annotate the whole word as nowrap. Arguably <nowrap>100 °C</nowrap> would be clearer than 100&nbsp;°C

Forget <nowrap>. There’s an already existing HTML4 <nobr> tag. To me it would be relevant that MediaWiki supports it; MDN says it’s non-standard (while it’s supported by all browser engines), that may be the reason. The behavior you were looking for can still be obtained with code like what this template uses.

I have a related remark. Even though the editor does not provide itself a keyboard shortcut to insert no-break spaces, your keyboard layout might allow you to write no-break spaces. If you’re in this case, an editor-provided keyboard shortcut to insert no-break spaces is completely unneeded.

The ‘French (alternative)’ keyboard layout (it’s its name on Linux) allows to insert no-break spaces with AltGr-Shift-Space. Personally I use the ‘Bépo’ keyboard layout (a Dvorak-like for French) which allows to type no-break spaces with Shift-Space. But it doesn’t work in the VisualEditor (both in visual and wikitext modes): it inserts a normal space. However it works with the classic (2013?) wikitext editor. It is very weird, because I can type no-break spaces everywhere else on my system, except in some rich-text web editors (I have the same problem with WordPress). I’m very curious about the source of that bug. It might be something else though, that would need its own bug report.

You can test the ‘French (alternative)’ keyboard layout easily on Linux by typing setxkbmap fr oss in a terminal. (Under Windows you must install it: use this archive linked from this Wikipedia page.)

Actually… OK, I just figured out it’s a Firefox bug with the contenteditable="true". Typing no-break spaces does work in Chromium.

Change 255937 restored by Bartosz Dziewoński:
[mediawiki/extensions/VisualEditor@master] Add command to insert non-breaking space, triggered by Ctrl+Space (PC) / Opt+Space (Mac)

https://gerrit.wikimedia.org/r/255937

Change 665132 had a related patch set uploaded (by Esanders; owner: Esanders):
[VisualEditor/VisualEditor@master] Detect NBSPs being inserted deliberately by IMEs

https://gerrit.wikimedia.org/r/665132

Change 665132 merged by jenkins-bot:

[VisualEditor/VisualEditor@master] Detect NBSPs being inserted deliberately by IMEs

https://gerrit.wikimedia.org/r/665132

Change 676162 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (5d0701ea3)

https://gerrit.wikimedia.org/r/676162

Change 676162 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] Update VE core submodule to master (5d0701ea3)

https://gerrit.wikimedia.org/r/676162

matmarex renamed this task from VisualEditor: Ctrl+Space/Opt+Space to insert a non-breaking space (NBSP) to VisualEditor: Ctrl+Shift+Space/Opt+Space to insert a non-breaking space (NBSP).Apr 7 2021, 10:13 PM

Change 255937 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] Add command to insert non-breaking space

https://gerrit.wikimedia.org/r/255937

matmarex moved this task from Code Review to QA on the Editing-team (Kanban Board) board.

This should be fixed now, and the change will be deployed to Wikimedia wikis next week.

Here's how the final version works:

  • On every operating system and keyboard layout, VisualEditor should support the built-in shortcut to insert a non-breaking space – e.g. Opt+Space on macOS, or various Linux keyboard layouts like those mentioned in T53045#5133074. (We'd appreciate if you could test with your favorite operating system / browser / language / keyboard layout / input method, as it's impossible for us to verify all combinations.)
  • In addition to that, on PC, we also support the Ctrl+Shift+Space shortcut to insert a non-breaking space.
  • These shortcuts insert the &nbsp; entity, in new wikitext editor as well as in the visual editor.