Skip to content

Commit 9259f7e

Browse files
committedJan 17, 2025
[WIP] Add lineComments CodeMirror extension - inline widget
1 parent 799b198 commit 9259f7e

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed
 

‎app/utils/code-mirror-line-comments.ts

+33-8
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -140,8 +136,25 @@ export function lineComments() {
140136
}),
141137
highlightActiveLineGutterRS(),
142138
EditorView.baseTheme({
139+
'.cm-line': {
140+
'& line-comments': {
141+
display: 'block',
142+
backgroundColor: '#009bff80',
143+
paddingLeft: '1rem',
144+
marginRight: '-1rem',
145+
146+
'& + br': {
147+
display: 'none',
148+
},
149+
},
150+
151+
'& .cm-insertedLine + br': {
152+
display: 'none',
153+
},
154+
},
155+
143156
'.cm-gutters.cm-gutters-rs': {
144-
backgroundColor: '#ff000070', // 'transparent',
157+
backgroundColor: '#ffffff20', // '#ff000070', // 'transparent',
145158

146159
'& .cm-custom-gutter-rs': {
147160
minWidth: '24px',
@@ -150,14 +163,26 @@ export function lineComments() {
150163
'& .cm-gutterElement': {
151164
cursor: 'pointer',
152165

166+
'& comments-count': {
167+
display: 'block',
168+
backgroundColor: '#ffcd72c0',
169+
borderRadius: '50%',
170+
color: 'black',
171+
transform: 'scale(0.7)',
172+
fontWeight: 'bold',
173+
},
174+
153175
'& comment-button': {
154-
opacity: '0.2',
176+
opacity: '0.15',
155177
},
156178

157179
'&:hover': {
158180
'& comment-button': {
159181
opacity: '1',
160182
},
183+
'& comments-count': {
184+
backgroundColor: '#ffa500',
185+
},
161186
},
162187
},
163188
},

‎app/utils/code-mirror-themes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const BASE_STYLE = {
1818
'.cm-lineNumbers': {
1919
'& .cm-gutterElement': {
2020
display: 'flex',
21-
alignItems: 'center',
21+
alignItems: 'flex-start',
2222
justifyContent: 'flex-end',
2323
padding: '0 0.5rem 0 1rem',
2424
fontSize: '0.875em',

0 commit comments

Comments
 (0)
Failed to load comments.