Closed mdanka closed 6 years ago
It looks like the only difference between the read only text and the editable text is that the span in the editable text has a -webkit-user-modify: read-write-plaintext-only;
attribute on it. If I disable this style the spaces collapse as well.
It gets added here: https://github.com/ianstormtaylor/slate/blob/master/packages/slate-react/src/components/content.js#L405
@mdanka would white-space: pre
get you where you need to go? By default the editor uses white-space: pre-wrap
.
Ah, @ericedem, that's an excellent observation, I missed that. It indeed resolves the problem! See here: https://jsfiddle.net/a9copgsy/6/
Thanks a lot! Really appreciated.
Do you want to request a feature or report a bug?
Bug
What's the current behavior?
I am creating an editor for guitar tabs. For this, it is important to 1) display multiple spaces with a monospace font 2) sometime switch to read-only mode 3) not to wrap the text in the editor (and instead for the editor to expand horizontally, with a horizontal scrollbar appearing).
white-space: nowrap
to the editor.readOnly
is set totrue
, multiple spaces collapse into a single space.JSFiddle to reproduce (note the
style={{whiteSpace: "nowrap"}}
on the Editor): https://jsfiddle.net/a9copgsy/1/OS: Mac Browser: Chrome Slate: 0.40.2
What's the expected behavior?
The spaces are preserved, not collapsed.
Solution
white-space: nowrap
.Value
itself is correct, the text leaf contains the correct number of spaces, but they are not rendered correctly.)I am happy to submit a PR, but not knowing the code base, I'd appreciate some guidance: you might already have a clear idea of what is going wrong, or whether there is a better way of disabling line wrapping.
Thank you!