Skip to content

Text Features - #362

Merged
saa938 merged 8 commits into
AP-Students:mainfrom
Famousmaster206:rich-text
Aug 12, 2026
Merged

Text Features#362
saa938 merged 8 commits into
AP-Students:mainfrom
Famousmaster206:rich-text

Conversation

@Famousmaster206

Copy link
Copy Markdown
Contributor

Description

Add multiple rich text features
Resolves #334

Pull request type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

A summary of the change, anything else that will help review this PR

Checklist

  • I have performed a self-review of my own code

@saa938 saa938 left a comment

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.

  1. highlight cant be turned off
  2. cursor jumps to start of the field immediately after applying any formatting
  3. formatting text next to latex corrupts math rendering
  4. floating toolbar is keyboard unreachable

@saa938 saa938 left a comment

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.

  1. the highlight issue still exists for me. remove the mark directly instead of asking the browser to
  2. cursor issue is fixed, good job
  3. latex issue is kinda fixed but if someone uses shortcuts like ctrl + b then it doesn't work. what you can do is intercept these shortcuts and route them through the guarded path.
  4. floating toolbar is now keyboard reachable, good work

@saa938 saa938 left a comment

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.

enter doesnt start a new line anymore, and the highlight thing still doesnt work. its a small change so i will just finish up this PR

Two fixes to the rich-text question editor.

Enter no longer starts a new line. emitChange restored the caret on every
input, not just when sanitizing had replaced innerHTML and destroyed the
selection. Because a <br> contributes no characters to the plain-text offset
model, restoring on a freshly created empty line mapped the caret back onto
the end of the previous line, so "one", Enter, "two" produced
"onetwo<div><br></div>". Restore only when the rewrite actually happened, and
let callers that mutate the DOM themselves pass their offsets explicitly.

Highlight could not be turned off. removeHighlightFromSelection unwrapped only
the marks that range extraction pulled into the fragment, and extraction sees a
mark only when the range fully contains it. Selecting the highlighted words --
the natural gesture -- makes that mark the range's common ancestor, so nothing
was found and the highlight stayed. The branch guard made it worse: it read
active.highlight, derived from anchorNode.closest("mark"), which is true
exactly for the selections where removal did nothing and false for the one
selection where it worked, where the code instead added a second mark and
produced nested <mark> elements.

Unwrap by intersection instead, and derive the toggle state from the whole
range rather than the anchor, which also stops the reported state from
depending on drag direction.

Verified in a browser: Enter now yields "one<div>two</div>" and three lines
nest correctly; highlight adds and removes across all three selection
geometries with no nested marks; the LaTeX guard, bold toggling, mid-string
typing, and selection preservation across a sanitizer rewrite are unchanged.
@saa938
saa938 merged commit 2553add into AP-Students:main Aug 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text Features in Questions

2 participants