@@ -2,7 +2,7 @@ import type { Editor } from "@tiptap/core";
22import { TextSelection } from "@tiptap/pm/state" ;
33import { act , createRef } from "react" ;
44import { createRoot , type Root } from "react-dom/client" ;
5- import { afterEach , beforeEach , expect , it , vi } from "vite-plus/test" ;
5+ import { afterEach , beforeEach , describe , expect , it , vi } from "vite-plus/test" ;
66
77import { serializeEditorDoc } from "~/composer-rich-text-doc" ;
88import { ComposerPromptEditor , type ComposerPromptEditorHandle } from "./ComposerPromptEditor" ;
@@ -23,6 +23,7 @@ beforeEach(() => {
2323afterEach ( async ( ) => {
2424 await act ( async ( ) => root . unmount ( ) ) ;
2525 container . remove ( ) ;
26+ vi . restoreAllMocks ( ) ;
2627 vi . unstubAllGlobals ( ) ;
2728} ) ;
2829
@@ -97,19 +98,110 @@ it("leaves vertical navigation between paragraphs to the browser", async () => {
9798 } ) ;
9899} ) ;
99100
100- it . each ( [
101- { shiftKey : true } ,
102- { altKey : true } ,
103- { metaKey : true } ,
104- { ctrlKey : true } ,
105- { isComposing : true } ,
106- ] ) ( "preserves modified Up behavior for %j" , async ( options ) => {
107- const editor = await mountEditor ( draft ) ;
108- await act ( async ( ) => {
109- expect ( press ( editor , "ArrowUp" , options ) ) . toBe ( false ) ;
110- editor . commands . insertContent ( "x" ) ;
101+ it . each ( [ { shiftKey : true } , { altKey : true } , { ctrlKey : true } , { isComposing : true } ] ) (
102+ "preserves modified Up behavior for %j" ,
103+ async ( options ) => {
104+ const editor = await mountEditor ( draft ) ;
105+ await act ( async ( ) => {
106+ expect ( press ( editor , "ArrowUp" , options ) ) . toBe ( false ) ;
107+ editor . commands . insertContent ( "x" ) ;
108+ } ) ;
109+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( draft . replace ( "> **" , "> **x" ) ) ;
110+ } ,
111+ ) ;
112+
113+ describe ( "macOS boundary navigation" , ( ) => {
114+ beforeEach ( ( ) => {
115+ vi . spyOn ( navigator , "platform" , "get" ) . mockReturnValue ( "MacIntel" ) ;
116+ container . style . width = "600px" ;
117+ } ) ;
118+
119+ const markdown = String . raw `Fixed the top padding to 16px and updated the offline index and ZIP.
120+
121+ **Yes: [HW08, problem 6, page 2](/Users/yashsingh/.t3/scratch/2026-10-16-gather-all-info-about-the-2fcd52f5/calculus-resources/files/HW08.pdf)** asks for the absolute maximum and minimum of
122+ \[
123+ f(x,y)=2x^2+y^2,\qquad x^2+y^2\le16.
124+ \]
125+ That's exactly a disk with the circular boundary \(x^2+y^2=16\), and it is within section 14.7.
126+
127+ The original Fall 2022, 2023, and 2024 sample exams also have circle-constrained extrema problems, all question 6. Those explicitly require Lagrange multipliers, so they were removed from your filtered copies. **HW08 #6 is the best match for your exam.**` ;
128+
129+ it . each ( [ "ArrowRight" , "ArrowDown" ] ) (
130+ "keeps Command-%s after the closing marker in the pasted draft" ,
131+ async ( key ) => {
132+ const editor = await mountEditor ( markdown ) ;
133+ await act ( async ( ) => {
134+ editor . view . dispatch ( editor . state . tr . setSelection ( TextSelection . atEnd ( editor . state . doc ) ) ) ;
135+ editor . view . focus ( ) ;
136+ expect ( press ( editor , "ArrowRight" ) ) . toBe ( true ) ;
137+ expect ( press ( editor , key , { metaKey : true } ) ) . toBe ( true ) ;
138+ expect ( editor . state . selection . eq ( TextSelection . atEnd ( editor . state . doc ) ) ) . toBe ( true ) ;
139+ // Force the DOM selection rewrite that used to pull the caret back.
140+ editor . view . updateState ( editor . state ) ;
141+ const markers = editor . view . dom . querySelectorAll ( ".composer-rich-marker" ) ;
142+ const closingMarker = markers [ markers . length - 1 ] ;
143+ const caret = window . getSelection ( ) ?. getRangeAt ( 0 ) ;
144+ if ( ! closingMarker || ! caret ) throw new Error ( "Caret or closing marker is missing" ) ;
145+ const markerRange = document . createRange ( ) ;
146+ markerRange . selectNode ( closingMarker ) ;
147+ expect ( caret . compareBoundaryPoints ( Range . START_TO_END , markerRange ) ) . toBeGreaterThanOrEqual (
148+ 0 ,
149+ ) ;
150+ editor . commands . insertContent ( "x" ) ;
151+ } ) ;
152+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( markdown + "x" ) ;
153+ } ,
154+ ) ;
155+
156+ it . each ( [ "ArrowRight" , "ArrowDown" ] ) (
157+ "moves Command-%s from inside bold to outside its closing marker" ,
158+ async ( key ) => {
159+ const editor = await mountEditor ( "**bold**" ) ;
160+ await act ( async ( ) => {
161+ editor . commands . setTextSelection ( 3 ) ;
162+ editor . view . focus ( ) ;
163+ expect ( press ( editor , key , { metaKey : true } ) ) . toBe ( true ) ;
164+ editor . commands . insertContent ( "x" ) ;
165+ } ) ;
166+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( "**bold**x" ) ;
167+ } ,
168+ ) ;
169+
170+ it . each ( [ "ArrowLeft" , "ArrowUp" ] ) ( "moves Command-%s before the opening marker" , async ( key ) => {
171+ const editor = await mountEditor ( "**bold**" ) ;
172+ await act ( async ( ) => {
173+ editor . commands . setTextSelection ( 3 ) ;
174+ editor . view . focus ( ) ;
175+ expect ( press ( editor , key , { metaKey : true } ) ) . toBe ( true ) ;
176+ editor . commands . insertContent ( "x" ) ;
177+ } ) ;
178+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( "x**bold**" ) ;
179+ } ) ;
180+
181+ it . each ( [ "ArrowRight" , "ArrowDown" ] ) (
182+ "extends Shift-Command-%s to the end without collapsing the selection" ,
183+ async ( key ) => {
184+ const editor = await mountEditor ( "**bold**" ) ;
185+ await act ( async ( ) => {
186+ editor . commands . setTextSelection ( 3 ) ;
187+ editor . view . focus ( ) ;
188+ expect ( press ( editor , key , { metaKey : true , shiftKey : true } ) ) . toBe ( true ) ;
189+ expect ( editor . state . selection . anchor ) . toBe ( 3 ) ;
190+ expect ( editor . state . selection . head ) . toBe ( TextSelection . atEnd ( editor . state . doc ) . to ) ;
191+ editor . commands . insertContent ( "x" ) ;
192+ } ) ;
193+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( "**box**" ) ;
194+ } ,
195+ ) ;
196+
197+ it ( "leaves Command-arrow navigation to the browser on other platforms" , async ( ) => {
198+ vi . spyOn ( navigator , "platform" , "get" ) . mockReturnValue ( "Linux x86_64" ) ;
199+ const editor = await mountEditor ( "**bold**" ) ;
200+ await act ( async ( ) => {
201+ editor . view . focus ( ) ;
202+ expect ( press ( editor , "ArrowDown" , { metaKey : true } ) ) . toBe ( false ) ;
203+ } ) ;
111204 } ) ;
112- expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( draft . replace ( "> **" , "> **x" ) ) ;
113205} ) ;
114206
115207it ( "leaves literal Markdown navigation to the browser in plain mode" , async ( ) => {
0 commit comments