Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plate collapses code_line's into a single code_line #176

Open
cloverich opened this issue Jun 3, 2024 · 0 comments
Open

Plate collapses code_line's into a single code_line #176

cloverich opened this issue Jun 3, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@cloverich
Copy link
Owner

Plate's code block plugin supplies a code_line block type which we re-implement in a basic fashion. I believe this is meant to exist for each line of code within a code_block. However, even though the mdast-to-slate transformer creates these (seemingly correctly), on the first edit within the code lock Plate will collapse all of them into a single code_line.

While I am not 100% positive this is incorrect, I believe it is, and I belive it is related to a few other issues:

  • Unindenting code (shift+tab) does not work once the code_lines are reduced to a single code_line
  • Copy / paste (esp. if in middle of code) has all sorts of odd behavior

I dug for a while but don't understand enough about Plate's mechanics to even get a break point into the right spot, to understand which Plate plugin / component is behaving unexpected. My best guess is it has to do with Prism and specifically packages/code-block/src/client/decorateCodeLine.ts:

// comes from Slate DOM
const codeBlock = getParentNode<TCodeBlockElement>(editor, path);

// later, is normalized
let langName = codeBlock[0].lang ?? '';

// Prism applied
const tokens = tokenize(text, lang);

// Serialized to ranges with token types applied:
    for (const element of tokens) {
      if (element instanceof Token) {
        ranges.push({
          [ELEMENT_CODE_SYNTAX]: true,
          anchor: { offset, path },
          focus: { offset: offset + element.length, path },
          tokenType: element.type,
        });
      }

      offset += element.length;
    }

// return ranges
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant