@@ -45,13 +45,25 @@ class CommentButtonGutterMarker extends GutterMarkerRS {
45
45
}
46
46
}
47
47
48
- function lineCommentsLineMarker ( view : EditorView , line : BlockInfo ) {
48
+ function lineCommentsGutterLineMarker ( view : EditorView , line : BlockInfo ) {
49
49
const lineNumber = view . state . doc . lineAt ( line . from ) . number ;
50
50
const commentsCount = view . state . facet ( lineDataFacet ) [ 0 ] ?. dataForLine ( lineNumber ) ?. commentsCount || 0 ;
51
51
52
52
return new ( commentsCount === 0 ? CommentButtonGutterMarker : CommentsCountGutterMarker ) ( line ) ;
53
53
}
54
54
55
+ function lineCommentsGutterClickHandler ( view : EditorView , line : BlockInfo ) {
56
+ const lineNumber = view . state . doc . lineAt ( line . from ) . number ;
57
+ const expandedLines = view . state . facet ( expandedLineNumbersFacet ) [ 0 ] || [ ] ;
58
+ const newExpandedLines = expandedLines . includes ( lineNumber ) ? expandedLines . without ( lineNumber ) : [ ...expandedLines , lineNumber ] ;
59
+
60
+ view . dispatch ( {
61
+ effects : [ expandedLineNumbersCompartment . reconfigure ( expandedLineNumbersFacet . of ( newExpandedLines ) ) ] ,
62
+ } ) ;
63
+
64
+ return true ;
65
+ }
66
+
55
67
const lineCommentsGutterBaseTheme = EditorView . baseTheme ( {
56
68
'.cm-lineCommentsGutter' : {
57
69
minWidth : '24px' ,
@@ -96,22 +108,9 @@ export function lineCommentsGutter() {
96
108
return [
97
109
gutterRS ( {
98
110
class : 'cm-lineCommentsGutter' ,
99
- lineMarker : lineCommentsLineMarker ,
111
+ lineMarker : lineCommentsGutterLineMarker ,
100
112
domEventHandlers : {
101
- click : ( view : EditorView , line : BlockInfo ) => {
102
- const lineNumber = view . state . doc . lineAt ( line . from ) . number ;
103
- const expandedLines = view . state . facet ( expandedLineNumbersFacet ) [ 0 ] || [ ] ;
104
-
105
- view . dispatch ( {
106
- effects : [
107
- expandedLineNumbersCompartment . reconfigure (
108
- expandedLineNumbersFacet . of ( expandedLines . includes ( lineNumber ) ? expandedLines . without ( lineNumber ) : [ ...expandedLines , lineNumber ] ) ,
109
- ) ,
110
- ] ,
111
- } ) ;
112
-
113
- return true ;
114
- } ,
113
+ click : lineCommentsGutterClickHandler ,
115
114
} ,
116
115
} ) ,
117
116
lineCommentsGutterBaseTheme ,
0 commit comments