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

Bold button is confused by font-weight span #2453

Closed
dae opened this issue Mar 24, 2023 · 4 comments
Closed

Bold button is confused by font-weight span #2453

dae opened this issue Mar 24, 2023 · 4 comments
Labels

Comments

@dae
Copy link
Member

dae commented Mar 24, 2023

Paste the following in a field:

<span style="font-weight: 400;">test</span>

Select one of the characters inside and attempt to bold it. We end up with:

<b>te</b>s<b>t</b>

Original report: https://forums.ankiweb.net/t/applying-bold-inverts-selection/28641/3

@dae dae added the editor label Mar 24, 2023
@SeojinK1m
Copy link

Can I take this issue?

@dae
Copy link
Member Author

dae commented May 1, 2023

Sure

@mmjang
Copy link
Contributor

mmjang commented Jul 14, 2023

Can we change the threshold 400 to 700?

        const fontWeight = element.style.fontWeight;
        if (fontWeight === "bold" || Number(fontWeight) >= 400) {

https://github.com/ankitects/anki/blob/a2cd9ec34da353aa5f4d65002111ccd3966ab3a4/ts/editor/editor-toolbar/BoldButton.svelte#L28C30-L28C30

According this mdn doc, "bold" is mapped to font-weight: 700.

I did a little bit testing, and this change gives more reasonable behaviour.

From normal to bold:

image image

From bold to normal:

image image

Another way to fix this might be using getComputedStyle to get the actual weight of the element, and decide if it is considered "bold" with threshold 700.

dae added a commit that referenced this issue Jul 17, 2023
@dae
Copy link
Member Author

dae commented Jul 17, 2023

Thanks for digging into it! If the docs say 700, happy to go with a check for 700 - I've pushed this change to the main branch.

@dae dae closed this as completed Jul 17, 2023
RumovZ pushed a commit to RumovZ/anki that referenced this issue Aug 18, 2023
dae pushed a commit that referenced this issue Oct 2, 2024
* Decide if element is bold by getComputedStyle (#2453)

* Use getComputedStyle() for italics too (dae)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants