Skip to content

Fix/code highlighting split#2382

Closed
lateefazeez wants to merge 5 commits into
facebook:mainfrom
MLH-Fellowship:fix/code-highlighting-split
Closed

Fix/code highlighting split#2382
lateefazeez wants to merge 5 commits into
facebook:mainfrom
MLH-Fellowship:fix/code-highlighting-split

Conversation

@lateefazeez
Copy link
Copy Markdown

Split Code Highlighting Plugin

  • Split code highlighting plugin into highlighting and editor shortcuts (indent multiple lines, keep tab level on a new line
Screen.Recording.2022-06-09.at.12.44.47.PM.mov

)

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 9, 2022
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 9, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lexical ✅ Ready (Inspect) Visit Preview Jun 10, 2022 at 4:09PM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview Jun 10, 2022 at 4:09PM (UTC)

return currentNode;
}

export function getLastCodeHighlightNodeOfLine(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should probably go into EditorShortcuts as it's not used here


const LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';

export class CodeNode extends ElementNode {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind extracting CodeNode & all related helpers (including $isCodeNode, $createCodeNode) into own file, and same for CodeHighlightingNode. It should make highlighting plugin file easier to navigate through

return offset;
}

export function getStartOfCodeInLine(anchor: LexicalNode): {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one does not seem to be used anywhere else, so no need to export it. Same applies to few other exports: try to move helpers into plugins files where they are used and only export node classes + helpers that are used as API ($isCodeNode, registerCodeHighlighting, etc). The rest can remain as local helpers without exporting

@lateefazeez
Copy link
Copy Markdown
Author

Changes

  • I rearranged the codes, created separate files for CodeHighlightNode, CodeNode, Code Highlighter and EditorShortcuts as requested. Please review.

Copy link
Copy Markdown
Collaborator

@fantactuka fantactuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple minor changes needed, but looks good otherwise 👍

editor: LexicalEditor,
threshold: number,
): () => void;
declare function registerCodeIndent(editor: LexicalEditor): () => void;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove registerCodeIndent from d.ts file for now, it is part of registerCodeHighlighting for now. I think we should eventually split them and call separately, but it'll be a breaking change so it's not urgent to do now

declare function registerCodeHighlighting(editor: LexicalEditor): () => void;
declare function registerCodeHighlighting(
editor: LexicalEditor,
threshold: number,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be optional argument, with Infinity as default value

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that will be completed as part of the codehighlighter threshold branch


useEffect(() => {
return registerCodeHighlighting(editor);
return registerCodeHighlighting(editor, 50);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have it 10000 for a playground

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, will do same as above

@acywatson
Copy link
Copy Markdown
Contributor

Hey @lateefazeez - can we get the conflicts resolved here so we can merge?

@lateefazeez
Copy link
Copy Markdown
Author

lateefazeez commented Jul 5, 2022

@acywatson I updated this code to resolve all conflicts, but somehow not showing up here. So I created a new PR for this. Link below

MLH-Fellowship#5

@lateefazeez lateefazeez closed this Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants