Repository navigation
Select and copy math like text - #16
Merged
Merged
Conversation
Formulas are SVG, so the browser had nothing to select or paint in them, and a tall inline formula made Chrome paint the words beside it as tall as the whole line. Selected formulas are now painted in the selection colour, lines holding inline math draw the selection through a custom highlight at text height, and double-clicking a formula selects it. Copying a selection with math writes the TeX interleaved with the words, list markers, table tabs and code to text/plain, and the drawn formulas to text/html. Hosts match their ::selection colour with --mk-selection. Co-Authored-By: spade <bot@acehq.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Selecting across an answer with math highlighted only the words between formulas, in boxes as tall as the line, and never the formulas. This makes math select and copy like text.
Cause
\lim) makes the line box tall, so the words beside it get tall highlight boxes.data-tex, but it rebuilt the text withtextContent, which drops list markers (1.) and table/line structure. It also wrote notext/html.Change
web/math-selection.js: onselectionchange, formulas the selection touches getdata-selectedand are painted in--mk-selection(defaultHighlight, and#355274in dark to match Chrome's native dark selection). Inline formulas highlight like a word; display formulas highlight as a block. The selection is mirrored into amarkit-selectioncustom highlight (CSS Custom Highlight API). In lines that hold inline math,style.cssshows that highlight instead of the native one, and it paints at text height. Double-clicking a formula selects all of it. One listener is shared per document.web/copy-text.js: when the copied selection holds math,text/plaingets the TeX source (as written:$…$,$$…$$,\(…\)) interleaved with the words, list markers (1.,-, nested indent), task boxes, table tabs and code.text/htmlgets the selected markup with every formula whole. Selections without math copy as the browser does.::selectioncolour set--mk-selectionto the same value. This is documented indocs/integration.md.Tests
web/tests/math-selection.spec.js(Playwright, real mouse drag and real copy). All three tests fail onmain:text/htmlhas all 9 formulas. Before: the1./2.markers were missing and there was notext/html.Also ran
renderer.spec.js,react.spec.js,inline.spec.jsandtests/node(jsdom): all pass.Copied text for the example: