Skip to content

Commit 956dea2

Browse files
committed
ASTDiff: Remove duplication for PR comments
1 parent 3662270 commit 956dea2

File tree

6 files changed

+70
-132
lines changed

6 files changed

+70
-132
lines changed

src/main/java/gui/webdiff/viewers/monaco/MonacoView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public void renderOn(HtmlCanvas html) throws IOException {
121121
.macros().javascript("/dist/utils.js")
122122
.macros().javascript("/dist/folding.js")
123123
.macros().javascript("/dist/decorations.js")
124+
.macros().javascript("/dist/pr-utils.js")
124125
.macros().javascript("/dist/monaco.js")
125126
.macros().javascript("/dist/listeners.js")
126127
._head();

src/main/java/gui/webdiff/viewers/monaco/SingleMonacoContent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ public void renderOn(HtmlCanvas html) throws IOException {
7777

7878
html
7979
.head()
80-
.macros().stylesheet("/dist/single-monaco.css")
81-
.macros().javascript("/dist/single-monaco.js")
82-
8380
.meta(charset("utf8"))
8481
.meta(name("viewport").content("width=device-width, initial-scale=1.0"))
8582
.title().content("RefactoringMiner")
83+
.macros().stylesheet("/dist/single-monaco.css")
84+
.macros().javascript("/dist/pr-utils.js")
85+
.macros().javascript("/dist/single-monaco.js")
8686
.macros().stylesheet(WebDiff.BOOTSTRAP_CSS_URL)
8787
.macros().stylesheet("/dist/monaco.css")
8888
.macros().javascript(WebDiff.JQUERY_JS_URL)

src/main/java/gui/webdiff/viewers/spv/SinglePageView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ protected void makeHead(HtmlCanvas html) throws IOException {
2424
.macros().javascript("/dist/utils.js")
2525
.macros().javascript("/dist/folding.js")
2626
.macros().javascript("/dist/decorations.js")
27+
.macros().javascript("/dist/pr-utils.js")
2728
.macros().javascript("/dist/monaco.js")
2829
.macros().javascript("/monaco/min/vs/loader.js")
2930
._head();

src/main/resources/web/dist/monaco.js

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -86,71 +86,6 @@ function mymonaco(config) {
8686
}
8787
}
8888

89-
function addInlineComments(editor, comments) {
90-
const container = editor.getDomNode().parentElement;
91-
let popup = document.getElementById('monaco-comment-popup');
92-
if (!popup) {
93-
popup = document.createElement('div');
94-
popup.id = 'monaco-comment-popup';
95-
popup.className = 'inline-comment';
96-
document.body.appendChild(popup);
97-
}
98-
99-
// Create decorations for all lines with comments
100-
const decoratedLines = new Set(comments.map(c => c.line));
101-
const decorations = Array.from(decoratedLines).map(line => ({
102-
range: new monaco.Range(line, 1, line, 1),
103-
options: {
104-
isWholeLine: true,
105-
linesDecorationsClassName: 'comment-icon'
106-
}
107-
}));
108-
109-
editor.deltaDecorations([], decorations);
110-
111-
editor.onMouseMove((e) => {
112-
const target = e.target;
113-
const hoveredLine = target.position?.lineNumber;
114-
const lineComments = comments
115-
.filter(c => c.line === hoveredLine)
116-
.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
117-
118-
if (
119-
[monaco.editor.MouseTargetType.GUTTER_LINE_DECORATIONS, monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN].includes(target.type) &&
120-
lineComments.length > 0
121-
) {
122-
const commentHtml = lineComments.map(comment => {
123-
const formattedDate = new Date(comment.createdAt).toLocaleDateString('en-US', {
124-
year: 'numeric',
125-
month: 'short',
126-
day: 'numeric'
127-
});
128-
return `
129-
<div class="${comment.status}">
130-
<strong>${comment.author}</strong>
131-
<span style="color: #888; font-size: 11px;">(created at ${formattedDate})</span>
132-
<div>${comment.text}</div>
133-
</div>
134-
<hr style="margin: 6px 0; border: none; border-top: 1px solid #ddd;">
135-
`;
136-
}).join('');
137-
138-
popup.innerHTML = commentHtml;
139-
popup.style.display = 'block';
140-
popup.style.top = `${e.event.browserEvent.clientY + 10}px`;
141-
popup.style.left = `${e.event.browserEvent.clientX + 10}px`;
142-
} else {
143-
popup.style.display = 'none';
144-
}
145-
});
146-
147-
editor.onMouseLeave(() => {
148-
popup.style.display = 'none';
149-
});
150-
}
151-
152-
153-
15489
function varInits(config, rightEditor, leftEditor) {
15590
rightEditor.getModel().moved = config.moved;
15691
leftEditor.getModel().moved = config.moved;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
function addInlineComments(editor, comments) {
2+
const container = editor.getDomNode().parentElement;
3+
let popup = document.getElementById('monaco-comment-popup');
4+
if (!popup) {
5+
popup = document.createElement('div');
6+
popup.id = 'monaco-comment-popup';
7+
popup.className = 'inline-comment';
8+
document.body.appendChild(popup);
9+
}
10+
11+
// Create decorations for all lines with comments
12+
const decoratedLines = new Set(comments.map(c => c.line));
13+
const decorations = Array.from(decoratedLines).map(line => ({
14+
range: new monaco.Range(line, 1, line, 1),
15+
options: {
16+
isWholeLine: true,
17+
linesDecorationsClassName: 'comment-icon'
18+
}
19+
}));
20+
21+
editor.deltaDecorations([], decorations);
22+
23+
editor.onMouseMove((e) => {
24+
const target = e.target;
25+
const hoveredLine = target.position?.lineNumber;
26+
const lineComments = comments
27+
.filter(c => c.line === hoveredLine)
28+
.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
29+
30+
if (
31+
[monaco.editor.MouseTargetType.GUTTER_LINE_DECORATIONS, monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN].includes(target.type) &&
32+
lineComments.length > 0
33+
) {
34+
const commentHtml = lineComments.map(comment => {
35+
const formattedDate = new Date(comment.createdAt).toLocaleDateString('en-US', {
36+
year: 'numeric',
37+
month: 'short',
38+
day: 'numeric'
39+
});
40+
return `
41+
<div class="${comment.status}">
42+
<div style="display: flex; align-items: center; gap: 6px;">
43+
<img src="${comment.avatarUrl}" alt="${comment.author}'s avatar" style="width: 20px; height: 20px; border-radius: 50%;">
44+
<strong>${comment.author}</strong>
45+
<span style="color: #888; font-size: 11px;">(created at ${formattedDate})</span>
46+
</div>
47+
<div style="margin-top: 4px;">${comment.text}</div>
48+
</div>
49+
<hr style="margin: 6px 0; border: none; border-top: 1px solid #ddd;">
50+
`;
51+
}).join('');
52+
53+
popup.innerHTML = commentHtml;
54+
popup.style.display = 'block';
55+
popup.style.top = `${e.event.browserEvent.clientY + 10}px`;
56+
popup.style.left = `${e.event.browserEvent.clientX + 10}px`;
57+
} else {
58+
popup.style.display = 'none';
59+
}
60+
});
61+
62+
editor.onMouseLeave(() => {
63+
popup.style.display = 'none';
64+
});
65+
}

src/main/resources/web/dist/single-monaco.js

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,67 +29,3 @@ function _createEditor(id, value, language) {
2929
return null;
3030
}
3131

32-
33-
function addInlineComments(editor, comments) {
34-
const container = editor.getDomNode().parentElement;
35-
let popup = document.getElementById('monaco-comment-popup');
36-
if (!popup) {
37-
popup = document.createElement('div');
38-
popup.id = 'monaco-comment-popup';
39-
popup.className = 'inline-comment';
40-
document.body.appendChild(popup);
41-
}
42-
43-
// Create decorations for all lines with comments
44-
const decoratedLines = new Set(comments.map(c => c.line));
45-
const decorations = Array.from(decoratedLines).map(line => ({
46-
range: new monaco.Range(line, 1, line, 1),
47-
options: {
48-
isWholeLine: true,
49-
linesDecorationsClassName: 'comment-icon'
50-
}
51-
}));
52-
53-
editor.deltaDecorations([], decorations);
54-
55-
editor.onMouseMove((e) => {
56-
const target = e.target;
57-
const hoveredLine = target.position?.lineNumber;
58-
const lineComments = comments
59-
.filter(c => c.line === hoveredLine)
60-
.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
61-
62-
if (
63-
[monaco.editor.MouseTargetType.GUTTER_LINE_DECORATIONS, monaco.editor.MouseTargetType.GUTTER_GLYPH_MARGIN].includes(target.type) &&
64-
lineComments.length > 0
65-
) {
66-
const commentHtml = lineComments.map(comment => {
67-
const formattedDate = new Date(comment.createdAt).toLocaleDateString('en-US', {
68-
year: 'numeric',
69-
month: 'short',
70-
day: 'numeric'
71-
});
72-
return `
73-
<div class="${comment.status}">
74-
<strong>${comment.author}</strong>
75-
<span style="color: #888; font-size: 11px;">(created at ${formattedDate})</span>
76-
<div>${comment.text}</div>
77-
</div>
78-
<hr style="margin: 6px 0; border: none; border-top: 1px solid #ddd;">
79-
`;
80-
}).join('');
81-
82-
popup.innerHTML = commentHtml;
83-
popup.style.display = 'block';
84-
popup.style.top = `${e.event.browserEvent.clientY + 10}px`;
85-
popup.style.left = `${e.event.browserEvent.clientX + 10}px`;
86-
} else {
87-
popup.style.display = 'none';
88-
}
89-
});
90-
91-
editor.onMouseLeave(() => {
92-
popup.style.display = 'none';
93-
});
94-
}
95-

0 commit comments

Comments
 (0)