1- import type { Node } from "prosemirror-model" ;
21import type { EditorState } from "prosemirror-state" ;
32import {
43 Decoration ,
54 DecorationSet ,
65 type DecorationSource ,
76} from "prosemirror-view" ;
87import { getSuggestionMarks } from "./utils.js" ;
8+ import { type BoundarySuggestion } from "./schema.js" ;
99
1010function pilcrow ( ) {
1111 const span = document . createElement ( "span" ) ;
@@ -14,13 +14,12 @@ function pilcrow() {
1414}
1515
1616export function getSuggestionDecorations ( state : EditorState ) : DecorationSource {
17- const { deletion, insertion } = getSuggestionMarks ( state . schema ) ;
17+ const { deletion, insertion, blockBoundarySuggestion } = getSuggestionMarks (
18+ state . schema ,
19+ ) ;
1820
1921 const changeDecorations : Decoration [ ] = [ ] ;
20- let lastParentNode : Node | null = null ;
21- let lastTextNode : Node | null = null ;
22- let lastTextNodeEndPos = 0 ;
23- state . doc . descendants ( ( node , pos , parent ) => {
22+ state . doc . descendants ( ( node , pos ) => {
2423 if ( node . isTextblock && node . childCount ) {
2524 if ( node . children . every ( ( child ) => deletion . isInSet ( child . marks ) ) ) {
2625 changeDecorations . push (
@@ -37,65 +36,26 @@ export function getSuggestionDecorations(state: EditorState): DecorationSource {
3736 ) ;
3837 }
3938 }
40- if ( node . type . name !== "text" ) return true ;
41- const currentDeletionMark = node . marks . find (
42- ( mark ) => mark . type === deletion ,
43- ) ;
44- const currentInsertionMark = node . marks . find (
45- ( mark ) => mark . type === insertion ,
46- ) ;
4739
48- const lastDeletionMark = lastTextNode ?. marks . find (
49- ( mark ) => mark . type === deletion ,
50- ) ;
51- const lastInsertionMark = lastTextNode ?. marks . find (
52- ( mark ) => mark . type === insertion ,
53- ) ;
54- const widgetPos = lastTextNodeEndPos ;
55- lastTextNode = node ;
56- lastTextNodeEndPos = pos + node . nodeSize ;
57- if ( parent === lastParentNode ) {
58- lastParentNode = parent ;
59- return true ;
60- }
61- lastParentNode = parent ;
62- if (
63- ( ! currentDeletionMark || ! lastDeletionMark ) &&
64- ( ! currentInsertionMark || ! lastInsertionMark )
65- ) {
66- return true ;
67- }
68- if (
69- currentDeletionMark ?. attrs [ "id" ] !== lastDeletionMark ?. attrs [ "id" ] &&
70- currentInsertionMark ?. attrs [ "id" ] !== lastInsertionMark ?. attrs [ "id" ]
71- ) {
72- return true ;
73- }
74- if ( currentDeletionMark ) {
75- changeDecorations . push (
76- Decoration . widget ( widgetPos , pilcrow , {
77- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
78- key : currentDeletionMark . attrs [ "id" ] ,
79- marks : [
80- deletion . create ( {
81- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
82- id : currentDeletionMark . attrs [ "id" ] ,
83- } ) ,
84- ] ,
85- } ) ,
86- ) ;
87- }
88- if ( currentInsertionMark ) {
40+ const boundarySuggestion = blockBoundarySuggestion . isInSet ( node . marks )
41+ ?. attrs as BoundarySuggestion | undefined ;
42+
43+ if ( ! boundarySuggestion ) return true ;
44+
45+ if ( boundarySuggestion . endType && boundarySuggestion . endId ) {
46+ const markType =
47+ boundarySuggestion . endType === "insertion" ? insertion : deletion ;
48+
49+ console . log ( boundarySuggestion ) ;
50+
8951 changeDecorations . push (
90- Decoration . widget ( widgetPos , pilcrow , {
91- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
92- key : currentInsertionMark . attrs [ "id" ] ,
93- marks : [
94- insertion . create ( {
95- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
96- id : currentInsertionMark . attrs [ "id" ] ,
97- } ) ,
98- ] ,
52+ Decoration . widget ( pos + node . nodeSize - 1 , pilcrow , {
53+ key :
54+ typeof boundarySuggestion . endId === "number"
55+ ? boundarySuggestion . endId . toString ( )
56+ : boundarySuggestion . endId ,
57+
58+ marks : [ markType . create ( { id : boundarySuggestion . endId } ) ] ,
9959 } ) ,
10060 ) ;
10161 }
0 commit comments