Slate: Japanese input seems to overlap

Created on 13 Feb 2019  ·  7Comments  ·  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Bug report

What's the current behavior?

Japanese input seems to overlap in this example (https://www.slatejs.org/#/markdown-preview). Please see following gif. I guess this behavior is occurred by decorator.

untitled

日本語 is duplicated.

My env

Google chrome 71.0.3578.98
Google 日本語入力 2.24.3250.1

What's the expected behavior?

Japanese input does not overlap with decorator.

bug ⚑ ime

Most helpful comment

I found a solution.
When you are composing give the mark a new key to force the mark to re-render.

    // in decorateNode method
      if (typeof token != 'string') {
        const dec = {
          anchor: {
            key: startText.key,
            offset: startOffset,
          },
          focus: {
            key: endText.key,
            offset: endOffset,
          },
          mark: {
            type: token.type,
          },
        }
        if (this.state.isComposing) {
          const nodeKey = token.type + Date.now()
          dec.mark.data = {
            key: nodeKey
          }
        }
        decorations.push(dec)
      }
// set key prop in renderMark method
case 'bold':
        return <strong {...attributes} key={mark.data.get('key')}>{children}</strong>
// other mark also can set key

All 7 comments

You can add onCompositionStart and onCompositionEnd props on the Editor component.

If you are composing return others in decorateNode method.

Code like this

  decorateNode = (node, editor, next) => {
    const others = next() || []
    if (node.object != 'block' || this.state.isComposing) return others
   // ...

@wuxiandiejia Thanks :) I'll try it !!

Hmm, I tried above workaround, but unfortunately it does not solve my problem... Do you have any idea??

Maybe you can get help on the slate's slack channel.

I found a solution.
When you are composing give the mark a new key to force the mark to re-render.

    // in decorateNode method
      if (typeof token != 'string') {
        const dec = {
          anchor: {
            key: startText.key,
            offset: startOffset,
          },
          focus: {
            key: endText.key,
            offset: endOffset,
          },
          mark: {
            type: token.type,
          },
        }
        if (this.state.isComposing) {
          const nodeKey = token.type + Date.now()
          dec.mark.data = {
            key: nodeKey
          }
        }
        decorations.push(dec)
      }
// set key prop in renderMark method
case 'bold':
        return <strong {...attributes} key={mark.data.get('key')}>{children}</strong>
// other mark also can set key

@wuxiandiejia Thanks :) I'll try it 👍

Hey, thanks for reporting this. I think this is actually a duplicate of https://github.com/ianstormtaylor/slate/issues/2368, so I'm going to close this in favor of that one. Feel free to comment over there with any other info!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JSH3R0 picture JSH3R0  ·  3Comments

Slapbox picture Slapbox  ·  3Comments

bunterWolf picture bunterWolf  ·  3Comments

ezakto picture ezakto  ·  3Comments

vdms picture vdms  ·  3Comments