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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(copy-tex): Use JS (instead of CSS) to select full equation, solving display glitches #3586

Merged
merged 11 commits into from Jun 6, 2022

Conversation

fonsp
Copy link
Contributor

@fonsp fonsp commented Mar 20, 2022

What is the previous behavior before this PR?
When selecting a subrange of a KaTeX equation, we currently use user-select: all to ensure that the entire equation is selected, which is needed to get the tex code correctly.

I found this behaviour to be unstable on Chrome (not just on Safari, like mentioned in the README), and I would often get a partial selection, leading to strange HTML content:

Schermopname.2022-03-20.om.16.28.50.mov

What is the new behavior after this PR?
This PR uses JS to guarantee that when a subrange of an equation is selected, the parent equation is used for the copying logic. We use .closest('.katex') to find this parent.

When the selection is not fully contained inside a katex equation element, the old behaviour is used, which was working great!

This means that the user-select: all class (and in fact, the entire CSS file), can be be removed 馃帀 This fixes the display bugs:

Schermopname.2022-03-20.om.16.35.45.mov

Removing the CSS file should not be breaking, as importing it from a future version will just give a 404, which is fine. (Right?) If not, we can put the file back with empty contents.

Let me know what you think!

@fonsp fonsp changed the title copy-tex: Use JS to select full equation instead of CSS fix(copy-tex): Use JS to select full equation instead of CSS to solve display glitches Mar 20, 2022
@fonsp fonsp changed the title fix(copy-tex): Use JS to select full equation instead of CSS to solve display glitches fix(copy-tex): Use JS (instead of CSS) to select full equation, solving display glitches Mar 20, 2022
Copy link
Member

@edemaine edemaine left a comment

Choose a reason for hiding this comment

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

This looks nice (but I still need to test it). I have one comment about the HTML output though.

contrib/copy-tex/copy-tex.js Outdated Show resolved Hide resolved
Co-authored-by: Erik Demaine <edemaine@mit.edu>
@fonsp fonsp requested a review from edemaine April 20, 2022 16:21
Copy link
Member

@edemaine edemaine left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. I cleaned up your code (in particular, lint was failing, and we weren't using Flow, but are now).

In experimenting with use of this rewrite, I found the undesirable behavior that, if your selection starts within one equation and ends within a different equation, we get ugly text again. So I rewrote the code to separately extend both the start and end of the range, instead of just looking at the common ancestor. This should restore the intended behavior.

Could you take a look and make sure you're good with my changes, before I merge and release?

@fonsp
Copy link
Contributor Author

fonsp commented Jun 6, 2022

Looks great, thanks for the help!

@codecov
Copy link

codecov bot commented Jun 6, 2022

Codecov Report

Merging #3586 (336e0f1) into main (9e3ae4d) will decrease coverage by 0.14%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3586      +/-   ##
==========================================
- Coverage   93.53%   93.39%   -0.15%     
==========================================
  Files          90       90              
  Lines        6669     6679      +10     
  Branches     1549     1554       +5     
==========================================
  Hits         6238     6238              
- Misses        400      403       +3     
- Partials       31       38       +7     
Impacted Files Coverage 螖
contrib/copy-tex/copy-tex.js 0.00% <0.00%> (酶)
contrib/copy-tex/katex2tex.js 0.00% <0.00%> (酶)

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 023cc03...336e0f1. Read the comment docs.

@edemaine edemaine merged commit 8c2d852 into KaTeX:main Jun 6, 2022
KaTeX-bot added a commit that referenced this pull request Jun 6, 2022
# [0.16.0](v0.15.6...v0.16.0) (2022-06-06)

### Bug Fixes

* **copy-tex:** Use JS (instead of CSS) to select full equation, solving display glitches ([#3586](#3586)) ([8c2d852](8c2d852))

### BREAKING CHANGES

* **copy-tex:** copy-tex extension no longer has (or requires) a CSS file.

* Code cleanup, lint fixes, port to Flow

* Rewrite to extend both start and end of range

* Remove contrib/**/*.css linting

Co-authored-by: Erik Demaine <edemaine@mit.edu>
@KaTeX-bot
Copy link
Member

馃帀 This PR is included in version 0.16.0 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

@fonsp
Copy link
Contributor Author

fonsp commented Jun 6, 2022

Ooh and an instant release after the merge, that's awesome! 馃専

@fonsp fonsp deleted the fp/copy-tex-js branch June 6, 2022 17:16
@edemaine
Copy link
Member

edemaine commented Jun 6, 2022

Yeah, semantic-release is pretty cool. Makes for a lot of releases though. 馃槄

@Mister-Hope
Copy link

Hi @fonsp (contributor) and @edemaine (approver), curiously to find out that this PR is made a long time ago.

Currently the file is written in flow (I guess?), but the file is obviously not a valid js file for most browsers and it's publishing to npm as-is.

Can anyone try to fix it by compiling it to a standard JS file when publishing?

See main branch content and you will get what I am talking:

related issue #3948

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants