@@ -119,7 +119,8 @@ declare global {
119119// When this is included in a transaction, don't update from/to of doc blocks.
120120const docBlockFreezeAnnotation = Annotation . define < boolean > ( ) ;
121121
122- // When this is included in a transaction, don't send autosave scroll/cursor location updates.
122+ // When this is included in a transaction, don't send autosave scroll/cursor
123+ // location updates.
123124const noAutosaveAnnotation = Annotation . define < boolean > ( ) ;
124125
125126// Doc blocks in CodeMirror
@@ -276,7 +277,8 @@ export const docBlockField = StateField.define<DecorationSet>({
276277 prev . spec . widget . contents ,
277278 effect . value . contents ,
278279 ) ,
279- // Assume this isn't a user change unless it's specified.
280+ // Assume this isn't a user change unless it's
281+ // specified.
280282 effect . value . is_user_change ?? false ,
281283 ) ,
282284 ...decorationOptions ,
@@ -373,7 +375,8 @@ type updateDocBlockType = {
373375 indent ?: string ;
374376 delimiter ?: string ;
375377 contents : string | StringDiff [ ] ;
376- // True if this update comes from a user change, as opposed to an update received from the IDE.
378+ // True if this update comes from a user change, as opposed to an update
379+ // received from the IDE.
377380 is_user_change ?: boolean ;
378381} ;
379382
@@ -447,7 +450,8 @@ class DocBlockWidget extends WidgetType {
447450 `<div class="CodeChat-doc-contents" spellcheck contenteditable>` +
448451 this . contents +
449452 "</div>" ;
450- // TODO: this is an async call. However, CodeMirror doesn't provide async support.
453+ // TODO: this is an async call. However, CodeMirror doesn't provide
454+ // async support.
451455 mathJaxTypeset ( wrap ) ;
452456 return wrap ;
453457 }
@@ -457,7 +461,8 @@ class DocBlockWidget extends WidgetType {
457461 // "Update a DOM element created by a widget of the same type (but
458462 // different, non-eq content) to reflect this widget."
459463 updateDOM ( dom : HTMLElement , _view : EditorView ) : boolean {
460- // If this change was produced by a user edit, then the DOM was already updated. Stop here.
464+ // If this change was produced by a user edit, then the DOM was already
465+ // updated. Stop here.
461466 if ( this . is_user_change ) {
462467 console . log ( "user change -- skipping DOM update." ) ;
463468 return true ;
@@ -469,7 +474,8 @@ class DocBlockWidget extends WidgetType {
469474 const [ contents_div , is_tinymce ] = get_contents ( dom ) ;
470475 window . MathJax . typesetClear ( contents_div ) ;
471476 if ( is_tinymce ) {
472- // Save the cursor location before the update, then restore it afterwards, if TinyMCE has focus.
477+ // Save the cursor location before the update, then restore it
478+ // afterwards, if TinyMCE has focus.
473479 const sel = tinymce_singleton ! . hasFocus ( )
474480 ? saveSelection ( )
475481 : undefined ;
@@ -482,7 +488,8 @@ class DocBlockWidget extends WidgetType {
482488 }
483489 mathJaxTypeset ( contents_div ) ;
484490
485- // Indicate the update was successful. TODO: but, contents are still pending...
491+ // Indicate the update was successful. TODO: but, contents are still
492+ // pending...
486493 return true ;
487494 }
488495
@@ -513,44 +520,36 @@ class DocBlockWidget extends WidgetType {
513520}
514521
515522const saveSelection = ( ) => {
516- // Changing the text inside TinyMCE causes it to loose a selection
517- // tied to a specific node. So, instead store the
518- // selection as an array of indices in the childNodes
519- // array of each element: for example, a given selection
520- // is element 10 of the root TinyMCE div's children
521- // (selecting an ol tag), element 5 of the ol's children
522- // (selecting the last li tag), element 0 of the li's
523- // children (a text node where the actual click landed;
524- // the offset in this node is placed in
525- // `selection_offset`.)
523+ // Changing the text inside TinyMCE causes it to loose a selection tied to a
524+ // specific node. So, instead store the selection as an array of indices in
525+ // the childNodes array of each element: for example, a given selection is
526+ // element 10 of the root TinyMCE div's children (selecting an ol tag),
527+ // element 5 of the ol's children (selecting the last li tag), element 0 of
528+ // the li's children (a text node where the actual click landed; the offset
529+ // in this node is placed in `selection_offset`.)
526530 const sel = window . getSelection ( ) ;
527531 let selection_path = [ ] ;
528532 const selection_offset = sel ?. anchorOffset ;
529533 if ( sel ?. anchorNode ) {
530- // Find a path from the selection back to the
531- // containing div.
534+ // Find a path from the selection back to the containing div.
532535 for (
533536 let current_node = sel . anchorNode , is_first = true ;
534- // Continue until we find the div which contains
535- // the doc block contents: either it's not an
536- // element (such as a div), ...
537+ // Continue until we find the div which contains the doc block
538+ // contents: either it's not an element (such as a div), ...
537539 current_node . nodeType !== Node . ELEMENT_NODE ||
538540 // or it's not the doc block contents div.
539541 ! ( current_node as Element ) . classList . contains (
540542 "CodeChat-doc-contents" ,
541543 ) ;
542544 current_node = current_node . parentNode ! , is_first = false
543545 ) {
544- // Store the index of this node in its' parent
545- // list of child nodes/children. Use
546- // `childNodes` on the first iteration, since
547- // the selection is often in a text node, which
548- // isn't in the `parents` list. However, using
549- // `childNodes` all the time causes trouble when
550- // reversing the selection -- sometimes, the
551- // `childNodes` change based on whether text
552- // nodes (such as a newline) are included are
553- // not after tinyMCE parses the content.
546+ // Store the index of this node in its' parent list of child
547+ // nodes/children. Use `childNodes` on the first iteration, since
548+ // the selection is often in a text node, which isn't in the
549+ // `parents` list. However, using `childNodes` all the time causes
550+ // trouble when reversing the selection -- sometimes, the
551+ // `childNodes` change based on whether text nodes (such as a
552+ // newline) are included are not after tinyMCE parses the content.
554553 let p = current_node . parentNode ! ;
555554 selection_path . unshift (
556555 Array . prototype . indexOf . call (
@@ -563,28 +562,28 @@ const saveSelection = () => {
563562 return { selection_path, selection_offset } ;
564563} ;
565564
566- // Restore the selection produced by `saveSelection` to the active TinyMCE instance.
565+ // Restore the selection produced by `saveSelection` to the active TinyMCE
566+ // instance.
567567const restoreSelection = ( {
568568 selection_path,
569569 selection_offset,
570570} : {
571571 selection_path : number [ ] ;
572572 selection_offset ?: number ;
573573} ) => {
574- // Copy the selection over to TinyMCE by indexing the
575- // selection path to find the selected node.
574+ // Copy the selection over to TinyMCE by indexing the selection path to find
575+ // the selected node.
576576 if ( selection_path . length && typeof selection_offset === "number" ) {
577577 let selection_node = tinymce_singleton ! . getContentAreaContainer ( ) ;
578578 for (
579579 ;
580580 selection_path . length &&
581- // If something goes wrong, bail out instead of producing exceptions.
581+ // If something goes wrong, bail out instead of producing
582+ // exceptions.
582583 selection_node !== undefined ;
583584 selection_node =
584- // As before, use the more-consistent
585- // `children` except for the last element,
586- // where we might be selecting a `text`
587- // node.
585+ // As before, use the more-consistent `children` except for the
586+ // last element, where we might be selecting a `text` node.
588587 (
589588 selection_path . length > 1
590589 ? selection_node . children
@@ -662,8 +661,8 @@ const element_is_in_doc_block = (
662661// untypeset, then the dirty ignored.
663662// 3. When MathJax typesets math on a TinyMCE focus out event, the dirty flag
664663// gets set. This should be ignored. However, typesetting is an async
665- // operation, so we assume it's OK to await the typeset completion.
666- // This will lead to nasty bugs at some point.
664+ // operation, so we assume it's OK to await the typeset completion. This will
665+ // lead to nasty bugs at some point.
667666// 4. When an HTML doc block is assigned to the TinyMCE instance for editing,
668667// the dirty flag is set. This must be ignored.
669668const on_dirty = (
@@ -684,8 +683,8 @@ const on_dirty = (
684683 ".CodeChat-doc" ,
685684 ) ! as HTMLDivElement ;
686685
687- // We can only get the position (the `from` value) for the doc block. Use
688- // this to find the `to` value for the doc block.
686+ // We can only get the position (the `from` value) for the doc block.
687+ // Use this to find the `to` value for the doc block.
689688 let from ;
690689 try {
691690 from = current_view . posAtDOM ( target ) ;
@@ -698,7 +697,8 @@ const on_dirty = (
698697 const indent = indent_div . innerHTML ;
699698 const delimiter = indent_div . getAttribute ( "data-delimiter" ) ! ;
700699 const [ contents_div , is_tinymce ] = get_contents ( target ) ;
701- // I'd like to extract this string, then untypeset only that string, not the actual div. But I don't know how.
700+ // I'd like to extract this string, then untypeset only that string, not
701+ // the actual div. But I don't know how.
702702 mathJaxUnTypeset ( contents_div ) ;
703703 const contents = is_tinymce
704704 ? tinymce_singleton ! . save ( )
@@ -828,7 +828,8 @@ export const DocBlockPlugin = ViewPlugin.fromClass(
828828 // cursor position (the selection) to be set in the
829829 // contenteditable div. Then, save that location.
830830 setTimeout ( async ( ) => {
831- // Untypeset math in the old doc block and the current doc block before moving its contents around.
831+ // Untypeset math in the old doc block and the current
832+ // doc block before moving its contents around.
832833 const tinymce_div =
833834 document . getElementById ( "TinyMCE-inst" ) ! ;
834835 mathJaxUnTypeset ( tinymce_div ) ;
@@ -854,7 +855,8 @@ export const DocBlockPlugin = ViewPlugin.fromClass(
854855 old_contents_div ,
855856 null ,
856857 ) ;
857- // The previous content edited by TinyMCE is now a div. Retypeset this after the transition.
858+ // The previous content edited by TinyMCE is now a div.
859+ // Retypeset this after the transition.
858860 await mathJaxTypeset ( old_contents_div ) ;
859861 // Move TinyMCE to the new location, then remove the old
860862 // div it will replace.
@@ -1065,9 +1067,11 @@ export const CodeMirror_load = async (
10651067 // [docs](https://codemirror.net/examples/tab/). TODO:
10661068 // document a way to escape the tab key per the same docs.
10671069 keymap . of ( [ indentWithTab ] ) ,
1068- // Change the font size. See [this post](https://discuss.codemirror.net/t/changing-the-font-size-of-cm6/2935/6).
1070+ // Change the font size. See
1071+ // [this post](https://discuss.codemirror.net/t/changing-the-font-size-of-cm6/2935/6).
10691072 [
1070- // TODO: get these values from the IDE, so we match its size.
1073+ // TODO: get these values from the IDE, so we match its
1074+ // size.
10711075 EditorView . theme ( {
10721076 "&" : {
10731077 fontSize : "14px" ,
@@ -1092,7 +1096,8 @@ export const CodeMirror_load = async (
10921096 await init ( {
10931097 selector : "#TinyMCE-inst" ,
10941098 setup : ( editor : Editor ) => {
1095- // See the [docs](https://www.tiny.cloud/docs/tinymce/latest/events/#editor-core-events).
1099+ // See the
1100+ // [docs](https://www.tiny.cloud/docs/tinymce/latest/events/#editor-core-events).
10961101 editor . on ( "Dirty" , ( event : any ) => {
10971102 // Get the div TinyMCE stores edits in. TODO: find
10981103 // documentation for `event.target.bodyElement`.
@@ -1158,7 +1163,9 @@ export const scroll_to_line = (cursor_line?: number, scroll_line?: number) => {
11581163 return ;
11591164 }
11601165
1161- // Create a transaction to set the cursor and scroll position. Avoid an autosave that sends updated cursor/scroll positions produced by this transaction.
1166+ // Create a transaction to set the cursor and scroll position. Avoid an
1167+ // autosave that sends updated cursor/scroll positions produced by this
1168+ // transaction.
11621169 const dispatch_data : TransactionSpec = {
11631170 annotations : noAutosaveAnnotation . of ( true ) ,
11641171 } ;
0 commit comments