Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add same line code comment box twice #11837

Merged
merged 3 commits into from
Jun 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1239,25 +1239,42 @@ function initPullRequestReview() {
$(this).closest('tr').removeClass('focus-lines-new focus-lines-old');
});
$('.add-code-comment').on('click', function (e) {
// https://github.com/go-gitea/gitea/issues/4745
if ($(e.target).hasClass('btn-add-single')) {
return;
}
if ($(e.target).hasClass('btn-add-single')) return; // https://github.com/go-gitea/gitea/issues/4745
e.preventDefault();

const isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
const side = $(this).data('side');
const idx = $(this).data('idx');
const path = $(this).data('path');
const form = $('#pull_review_add_comment').html();
const tr = $(this).closest('tr');

const oldLineNum = tr.find('.lines-num-old').data('line-num');
const newLineNum = tr.find('.lines-num-new').data('line-num');
const addCommentKey = `${oldLineNum}|${newLineNum}`;
if (document.querySelector(`[data-add-comment-key="${addCommentKey}"]`)) return; // don't add same comment box twice

let ntr = tr.next();
if (!ntr.hasClass('add-comment')) {
ntr = $(`<tr class="add-comment">${
isSplit ? '<td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-left"></td><td class="lines-num"></td><td class="lines-type-marker"></td><td class="add-comment-right"></td>' :
'<td class="lines-num"></td><td class="lines-num"></td><td class="add-comment-left add-comment-right" colspan="2"></td>'
}</tr>`);
ntr = $(`
<tr class="add-comment" data-add-comment-key="${addCommentKey}">
${isSplit ? `
<td class="lines-num"></td>
<td class="lines-type-marker"></td>
<td class="add-comment-left"></td>
<td class="lines-num"></td>
<td class="lines-type-marker"></td>
<td class="add-comment-right"></td>
` : `
<td class="lines-num"></td>
<td class="lines-num"></td>
<td class="add-comment-left add-comment-right" colspan="2">
</td>
techknowlogick marked this conversation as resolved.
Show resolved Hide resolved
`}
</tr>`);
tr.after(ntr);
}

const td = ntr.find(`.add-comment-${side}`);
let commentCloud = td.find('.comment-code-cloud');
if (commentCloud.length === 0) {
Expand Down