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

[lexical-playground] Fix: tabs do not show strikethrough #6811

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

vantage-ola
Copy link
Contributor

@vantage-ola vantage-ola commented Nov 8, 2024

Description

Made some changes to .PlaygroundEditorTheme__textStrikethrough to show strikethroughs on tabs

Closes #6808

Before

Screenshot 2024-11-08 161836

After selecting the whole text, it shows the strikethrough is present
Screenshot 2024-11-08 162158

After

The slight change in css makes the strikethrough visible

Screenshot 2024-11-08 162320

Copy link

vercel bot commented Nov 8, 2024

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

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 22, 2024 10:53pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 22, 2024 10:53pm

@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 Nov 8, 2024
Copy link

github-actions bot commented Nov 8, 2024

size-limit report 📦

Path Size
lexical - cjs 30.94 KB (0%)
lexical - esm 30.8 KB (0%)
@lexical/rich-text - cjs 39.6 KB (0%)
@lexical/rich-text - esm 32.66 KB (0%)
@lexical/plain-text - cjs 38.2 KB (0%)
@lexical/plain-text - esm 29.92 KB (0%)
@lexical/react - cjs 41.37 KB (0%)
@lexical/react - esm 34 KB (0%)

@vantage-ola
Copy link
Contributor Author

i took another approach to fixing this.., i just jumped into it without thinking and was in an hurry to fix it... I had even forgotten both underline and strikethrough existed...

the reason I used white-space: pre; is because normally HTML collapses multiple spaces into one, but white-space: pre treats them like <pre> tags

@vantage-ola
Copy link
Contributor Author

vantage-ola commented Nov 9, 2024

i took another approach to fixing this.., i just jumped into it without thinking and was in an hurry to fix it... I had even forgotten both underline and strikethrough existed...

the reason I used white-space: pre; is because normally HTML collapses multiple spaces into one, but white-space: pre treats them like \<pre\> tags

no need for them actually. 😅 silly me.. i was using display: inline-block; while trying out things...

@etrepum
Copy link
Collaborator

etrepum commented Nov 16, 2024

Don't bother trying to replace the spaces, that will cause problems. I suggested a possible approach in my last comment, this workaround only needs to apply to tab nodes. If you add a class so they can be targeted you should be able to work around it for only those nodes and leave the other CSS alone so this fix doesn't break anything else.

@vantage-ola
Copy link
Contributor Author

vantage-ola commented Nov 17, 2024

I tried soemthing... but it breaks something in the tests... but i think the strikethrough/underlining or both works, atleast from what i tested in the playground

Argument of type 'TextNode' is not assignable to parameter of type 'CodeHighlightNode | TabNode | LineBreakNode'.
      Property 'getClassName' is missing in type 'TextNode' but required in type 'TabNode'.

    265       let node = getFirstCodeNodeOfLine(firstSelectionNode);
                                                ~~~~~~~~~~~~~~~~~~

      packages/lexical/src/nodes/LexicalTabNode.ts:52:3
        52   getClassName(): string {
             ~~~~~~~~~~~~
        'getClassName' is declared here.

Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

Not sure why that check failed, let's see if it happens again once the other issues are fixed. I can't review the functionality because it didn't deploy.

Comment on lines 51 to 88
// Add method to get class name for styling
getClassName(): string {
const baseClass = 'PlaygroundEditorTheme__tabNode';
const formatClassNames = [];

const underline = this.hasFormat('underline');
const strikethrough = this.hasFormat('strikethrough');

if (underline && strikethrough) {
formatClassNames.push(
'PlaygroundEditorTheme__textUnderlineStrikethrough',
);
} else if (strikethrough) {
formatClassNames.push('PlaygroundEditorTheme__textStrikethrough');
} else if (underline) {
formatClassNames.push('PlaygroundEditorTheme__textUnderline');
}

return [baseClass, ...formatClassNames].join(' ');
}

createDOM(config: EditorConfig): HTMLElement {
const dom = super.createDOM(config);
dom.className = this.getClassName();
return dom;
}

updateDOM(
prevNode: TabNode,
dom: HTMLElement,
config: EditorConfig,
): boolean {
const updated = super.updateDOM(prevNode, dom, config);
if (updated) {
dom.className = this.getClassName();
}
return updated;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is far more work than it needs to be, the format classes are already assigned by the super implementation. You only need to add the class for TabNode in createDOM. This class should be defined in the theme, not hard-coded in this implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, thank you. will get to work on this. and make necessary adjustments.

@vantage-ola
Copy link
Contributor Author

so, only createDOM is needed in LexicalTabNode, but I noticed a number of tests are failing due to a new class name being introduced to lexical. And while testing, I dont think the pseudo element approach will ever work(but i may be wrong though)

for example:

 ● LexicalSelection tests › Paste text, move selection and delete word forward (#138)

    expect(received).toBe(expected) // Object.is equality

    Expected: "<div contenteditable=\"true\" style=\"user-select: text; white-space: pre-wrap; word-break: break-word;\" data-lexical-editor=\"true\"><p class=\"editor-paragraph\" dir=\"ltr\"><span data-lexical-text=\"true\">ABD</span><span data-lexical-text=\"true\">       </span><span data-lexical-text=\"true\">EFG</span></p></div>"
    Received: "<div contenteditable=\"true\" style=\"user-select: text; white-space: pre-wrap; word-break: break-word;\" data-lexical-editor=\"true\"><p class=\"editor-paragraph\" dir=\"ltr\"><span data-lexical-text=\"true\">ABD</span><span class=\"PlaygroundEditorTheme__tabNode\" data-lexical-text=\"true\">       </span><span data-lexical-text=\"true\">EFG</span></p></div>"

@etrepum
Copy link
Collaborator

etrepum commented Nov 21, 2024

Yes, of course the tests that use tab node will have to change when a class is added.

@vantage-ola
Copy link
Contributor Author

@etrepum I noticed something a while ago(totally unrelated) i dont know if its a bug.. sometimes when you press tab, it doesnt go to the next 4 spaces, it (folds the tab('4' spaces to '1' space), but when you do it again, it goes 4 spaces forward.. Why is that? is that the right behaviour
Screenshot 2024-11-22 232544

@vantage-ola
Copy link
Contributor Author

i have a suggestion @etrepum instead of adding the artificial strikethroughs/underlines or both for affected tab nodes... what of a visual tab indicator like i have here in this screenshot?

Screenshot 2024-11-22 235956

@etrepum
Copy link
Collaborator

etrepum commented Nov 23, 2024

Regarding spacing with tabs - this is how they work. Tabs are not just wide spaces, they are variable width depending on how much space there is until the next horizontal tab stop.

https://developer.mozilla.org/en-US/docs/Web/CSS/tab-size
https://en.wikipedia.org/wiki/Tab_key

As far as displaying them visually goes, that would be a different feature and is unrelated to this issue. Some people expect that the tab character would have text decoration in this particular scenario, as if it was part of the same span as the rest of the text, at least that's what something like Google Docs or Word (the app, not the web version) would do.

I'm not aware of an HTML based editor that can display tabs with text decoration, so I don't have an example to point you towards, but this also isn't an issue that I've researched myself beyond reviewing this PR.

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.

Bug: Tabs do not show strikethrough
4 participants