@@ -37,11 +37,7 @@ class CommentsWidget extends WidgetType {
3737
3838 toDOM ( view : EditorView ) : HTMLElement {
3939 const comments = ( view . state . facet ( lineCommentsFacet ) [ 0 ] || [ ] ) [ this . line . number - 1 ] ;
40-
4140 const elem = document . createElement ( 'line-comments' ) ;
42- elem . style . display = 'block' ;
43- elem . style . backgroundColor = '#009bff80' ;
44- elem . style . paddingLeft = '1rem' ;
4541
4642 if ( comments ?. length ) {
4743 elem . innerText = `💬 COMMENTS (${ comments ?. length || 0 } ) FOR LINE #${ this . line . number } ` ;
@@ -60,8 +56,8 @@ function lineCommentsDecorations(state: EditorState) {
6056 Decoration . widget ( {
6157 widget : new CommentsWidget ( line ) ,
6258 side : 10 ,
63- inlineOrder : true ,
64- block : true ,
59+ // inlineOrder: true,
60+ // block: true,
6561 } ) . range ( line . to ) ,
6662 ) ;
6763 }
@@ -96,7 +92,12 @@ class CommentsCountGutterMarker extends GutterMarkerRS {
9692 const lineNumber = view . state . doc . lineAt ( this . line . from ) . number ;
9793 const comments = ( view . state . facet ( lineCommentsFacet ) [ 0 ] || [ ] ) [ lineNumber - 1 ] ;
9894 const elem = document . createElement ( 'comments-count' ) ;
99- elem . innerText = `${ comments ?. length } ` ;
95+ const commentsCount = comments ?. length || 0 ;
96+ elem . innerText = `${ commentsCount > 99 ? '99+' : commentsCount } ` ;
97+
98+ if ( commentsCount > 99 ) {
99+ elem . className = 'cm-over-99' ;
100+ }
100101
101102 return elem ;
102103 }
@@ -121,11 +122,25 @@ class CommentButtonGutterMarker extends GutterMarkerRS {
121122export function lineComments ( ) {
122123 return [
123124 lineCommentsFacet . compute ( [ 'doc' ] , function ( state ) {
124- return Array . from ( { length : state . doc . lines } ) . map ( ( _v , lineNumber ) =>
125- Array . from < string > ( { length : Math . random ( ) < 0.4 ? getRandomInt ( 0 , 6 ) : 0 } ) . map (
125+ return Array . from ( { length : state . doc . lines } ) . map ( function ( _v , lineNumber ) {
126+ const rnd = Math . random ( ) ;
127+
128+ let commentsCount ;
129+
130+ if ( rnd < 0.05 ) {
131+ commentsCount = getRandomInt ( 100 , 255 ) ;
132+ } else if ( rnd < 0.1 ) {
133+ commentsCount = getRandomInt ( 10 , 99 ) ;
134+ } else if ( rnd < 0.8 ) {
135+ commentsCount = 0 ;
136+ } else {
137+ commentsCount = getRandomInt ( 1 , 9 ) ;
138+ }
139+
140+ return Array . from < string > ( { length : commentsCount } ) . map (
126141 ( _v , index ) => new LineComment ( { lineNumber, author : 'Darth Programmius' , text : `Comment #${ index } ` } ) ,
127- ) ,
128- ) ;
142+ ) ;
143+ } ) ;
129144 } ) ,
130145 lineCommentsStateField ,
131146 gutterRS ( {
@@ -140,8 +155,25 @@ export function lineComments() {
140155 } ) ,
141156 highlightActiveLineGutterRS ( ) ,
142157 EditorView . baseTheme ( {
158+ '.cm-line' : {
159+ '& line-comments' : {
160+ display : 'block' ,
161+ backgroundColor : '#009bff40' ,
162+ paddingLeft : '1rem' ,
163+ marginRight : '-1rem' ,
164+
165+ '& + br' : {
166+ display : 'none' ,
167+ } ,
168+ } ,
169+
170+ '& .cm-insertedLine + br' : {
171+ display : 'none' ,
172+ } ,
173+ } ,
174+
143175 '.cm-gutters.cm-gutters-rs' : {
144- backgroundColor : '#ff000070' , // 'transparent',
176+ backgroundColor : '#ffffff20' , // '# ff000070', // 'transparent',
145177
146178 '& .cm-custom-gutter-rs' : {
147179 minWidth : '24px' ,
@@ -150,14 +182,32 @@ export function lineComments() {
150182 '& .cm-gutterElement' : {
151183 cursor : 'pointer' ,
152184
185+ '& comments-count' : {
186+ display : 'block' ,
187+ backgroundColor : '#ffcd72c0' ,
188+ borderRadius : '50%' ,
189+ color : '#24292e' ,
190+ transform : 'scale(0.75)' ,
191+ fontWeight : '500' ,
192+ fontSize : '12px' ,
193+
194+ '&.cm-over-99' : {
195+ fontSize : '9.5px' ,
196+ } ,
197+ } ,
198+
153199 '& comment-button' : {
154- opacity : '0.2 ' ,
200+ opacity : '0.15 ' ,
155201 } ,
156202
157203 '&:hover' : {
158204 '& comment-button' : {
159205 opacity : '1' ,
160206 } ,
207+
208+ '& comments-count' : {
209+ backgroundColor : '#ffa500' ,
210+ } ,
161211 } ,
162212 } ,
163213 } ,
0 commit comments