question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow overriding getPlainText (and HTML?)

See original GitHub issue

Problem slate-react internally generates the Slate fragment, HTML, and plain-text representations of the editor’s state when interacting with the clipboard, using ReactEditor.setFragmentData. This is called from onCopy, onCut, and onDragStart.

Internally, this function does a bunch of different operations and checks, and eventually generates a blank DOM node which it generates the text/plain and text/html types from. This calls utils/dom/getPlainText, which walks the DOM tree to get the text nodes (and also handles newline generation).

Transforming on input is relatively easy via editor.insertData (as shown in the paste-html example), but output is not so much; it requires repeating some of slate-react’s internal logic in setFragmentData, and attaching to every DOM event. This gets unwieldy, and is brittle to changes and fixes in Slate.

Solution I’d like to define my own getPlainText function (getPlainText(node: DOMNode) => string) to allow for transforming the text being set on the DataTransfer. This would let me check for my void nodes and pick different data to be serialized.

The ability to override the text/html representation may also be useful (although I don’t personally need it).

Alternatives Currently, you can either override the whole setFragmentData with custom code, or wrap the existing behaviour.

Wrapping the existing behaviour means recreating many of the checks setFragmentData, as the processed data isn’t actually exposed (which makes sense). This ends up being essentially equivalent then to overriding setFragmentData and rewriting it. This… is not super fun.

Context In my particular use case, I have dynamic values within my editor represented by void nodes. I’d like to serialize these manually to placeholders (e.g. {{some_value}}) when copying out of the editor, and transform back when copying in. (My particular use case is copying data to and from code editors.)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rmccuecommented, Aug 12, 2021

what I actually do is work through an order

That’ll teach me to read an isolated example. 😉

0reactions
dylanscommented, Aug 26, 2021

@bryanph it would be amazing to see how you’ve replaced setFragmentData as I feel like my custom extension is rather simplistic!

Read more comments on GitHub >

github_iconTop Results From Across the Web

text overriding on another text, need to display below
i am trying chnaging values in following code , but its affecting in other link : .vship1 { position: absolute; top: 110px;. please...
Read more >
QPlainTextEdit Class | Qt Widgets 6.4.1
overwriteMode : bool. This property holds whether text entered by the user will overwrite existing text. As with many text editors, the plain...
Read more >
DecryptResult (AWS SDK for Java - 1.12.372)
public ByteBuffer getPlaintext(). Decrypted plaintext data. ... Overrides: toString in class Object; Returns: A string representation of this object.
Read more >
HeaderedContentControl.cs - Reference Source - Microsoft
</summary> /// <returns></returns> internal override string GetPlainText() { return ContentControl.ContentObjectToString(Header); } /// <summary> ...
Read more >
Template configurations - Apache FreeMarker Manual
This setting lets you override individual settings coming from the common ... Subject templates must get plainText output format, while body templates must ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found