The Unified and Autonomous Development Platform
Do not scroll document when switch between comments
yjshenb2a608feb22d
diff --git a/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.java b/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.javaindex 5886d6b3cf..2bf48190a7 100644--- a/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.java+++ b/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/TextDiffPanel.java@@ -385,18 +385,13 @@ public class TextDiffPanel extends Panel implements SourceAware {getMarkupId(), getJson(mark));target.appendJavaScript(script);break;- case "toggleComment":+ case "openComment":Long commentId = params.getParameterValue("param1").toLong();CodeComment comment = OneDev.getInstance(CodeCommentManager.class).load(commentId);- CodeComment prevComment = commentSupport.getOpenComment();- commentSupport.onToggleComment(target, comment);- if (!comment.equals(prevComment)) {- script = String.format("onedev.server.textDiff.onOpenComment($('#%s'), %s);",- getMarkupId(), getJsonOfComment(comment));- target.appendJavaScript(script);- } else {- onCommentClosed(target, comment);- }+ commentSupport.onOpenComment(target, comment);+ script = String.format("onedev.server.textDiff.onOpenComment($('#%s'), %s);",+ getMarkupId(), getJsonOfComment(comment));+ target.appendJavaScript(script);break;}}diff --git a/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/text-diff.js b/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/text-diff.jsindex 54310d057c..d5e872887d 100644--- a/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/text-diff.js+++ b/server-core/src/main/java/io/onedev/server/web/component/diff/blob/text/text-diff.js@@ -790,12 +790,14 @@ onedev.server.textDiff = {onedev.server.textDiff.restoreMark($container);});$(this).click(function() {- if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- var comment = comments[$(this).index()];- callback("toggleComment", comment.id);+ if (!$(this).hasClass("active")) {+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ var comment = comments[$(this).index()];+ callback("openComment", comment.id);+ }});});onedev.server.textDiff.highlightCommentTrigger($container);@@ -811,11 +813,13 @@ onedev.server.textDiff = {onedev.server.textDiff.restoreMark($container);});$indicator.click(function() {- if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;+ if (!$indicator.hasClass("active")) {+ if ($("#"+$container.data("dirtyContainerId")).find("form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ callback("openComment", comment.id);}- callback("toggleComment", comment.id);});}$lineNumTd.children(".comment-indicator").remove();@@ -894,9 +898,6 @@ onedev.server.textDiff = {onedev.server.textDiff.addCommentIndicator($container, leftSide, line, comments);}onedev.server.textDiff.highlightCommentTrigger($container);- var mark = $container.data("mark");- if (mark)- onedev.server.textDiff.scrollIntoView($container, mark);},onOpenComment: function($container, comment) {$container.data("openComment", comment);@@ -907,9 +908,6 @@ onedev.server.textDiff = {},onCloseComment: function($container) {$container.removeData("openComment");- var mark = $container.data("mark");- if (mark)- onedev.server.textDiff.scrollIntoView($container, mark);onedev.server.textDiff.highlightCommentTrigger($container);},onAddComment: function($container, mark) {diff --git a/server-core/src/main/java/io/onedev/server/web/component/diff/revision/BlobCommentSupport.java b/server-core/src/main/java/io/onedev/server/web/component/diff/revision/BlobCommentSupport.javaindex a16a25038e..ea73f97d81 100644--- a/server-core/src/main/java/io/onedev/server/web/component/diff/revision/BlobCommentSupport.java+++ b/server-core/src/main/java/io/onedev/server/web/component/diff/revision/BlobCommentSupport.java@@ -21,7 +21,7 @@ public interface BlobCommentSupport extends Serializable {@Nullable CodeComment getOpenComment();- void onToggleComment(AjaxRequestTarget target, CodeComment comment);+ void onOpenComment(AjaxRequestTarget target, CodeComment comment);void onAddComment(AjaxRequestTarget target, Mark mark);diff --git a/server-core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.java b/server-core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.javaindex ae1cd24805..fd9abe3fa6 100644--- a/server-core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.java+++ b/server-core/src/main/java/io/onedev/server/web/component/diff/revision/RevisionDiffPanel.java@@ -755,8 +755,8 @@ public class RevisionDiffPanel extends Panel {}@Override- public void onToggleComment(AjaxRequestTarget target, CodeComment comment) {- RevisionDiffPanel.this.onToggleComment(target, comment);+ public void onOpenComment(AjaxRequestTarget target, CodeComment comment) {+ RevisionDiffPanel.this.onOpenComment(target, comment);}@Override@@ -825,6 +825,7 @@ public class RevisionDiffPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {clearComment(target);+ target.appendJavaScript("onedev.server.revisionDiff.reposition();");Mark mark = getMark();if (mark != null) {SourceAware sourceAware = getSourceAware(mark.getPath());@@ -832,8 +833,6 @@ public class RevisionDiffPanel extends Panel {sourceAware.unmark(target);((CommentSupport)commentSupport).onUnmark(target);}-- target.appendJavaScript("onedev.server.revisionDiff.reposition();");}});@@ -986,56 +985,51 @@ public class RevisionDiffPanel extends Panel {return compareContext;}- private void onToggleComment(AjaxRequestTarget target, CodeComment comment) {- if (!comment.equals(getOpenComment())) {- CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, comment.getId()) {+ private void onOpenComment(AjaxRequestTarget target, CodeComment comment) {+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, comment.getId()) {- @Override- protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {- RevisionDiffPanel.this.onCommentDeleted(target, comment);- }+ @Override+ protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {+ RevisionDiffPanel.this.onCommentDeleted(target, comment);+ }- @Override- protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {- commentSupport.onSaveComment(comment);- target.add(commentContainer.get("head"));- }+ @Override+ protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {+ commentSupport.onSaveComment(comment);+ target.add(commentContainer.get("head"));+ }- @Override- protected PullRequest getPullRequest() {- return requestModel.getObject();- }+ @Override+ protected PullRequest getPullRequest() {+ return requestModel.getObject();+ }- @Override- protected void onSaveCommentReply(AjaxRequestTarget target, CodeCommentReply reply) {- reply.getComment().setCompareContext(getCompareContext(comment.getMark().getCommitHash()));- commentSupport.onSaveCommentReply(reply);- }-- };-- commentContainer.replace(commentPanel);- commentContainer.setVisible(true);- target.add(commentContainer);-- CodeComment prevComment = RevisionDiffPanel.this.getOpenComment();- if (prevComment != null) {- SourceAware sourceAware = getSourceAware(prevComment.getMark().getPath());- if (sourceAware != null)- sourceAware.onCommentClosed(target, prevComment);- }-- Mark prevMark = RevisionDiffPanel.this.getMark();- if (prevMark != null) {- SourceAware sourceAware = getSourceAware(prevMark.getPath());- if (sourceAware != null)- sourceAware.unmark(target);+ @Override+ protected void onSaveCommentReply(AjaxRequestTarget target, CodeCommentReply reply) {+ reply.getComment().setCompareContext(getCompareContext(comment.getMark().getCommitHash()));+ commentSupport.onSaveCommentReply(reply);}- commentSupport.onCommentOpened(target, comment);- } else {- clearComment(target);- commentSupport.onCommentClosed(target);++ };++ commentContainer.replace(commentPanel);+ commentContainer.setVisible(true);+ target.add(commentContainer);++ CodeComment prevComment = RevisionDiffPanel.this.getOpenComment();+ if (prevComment != null) {+ SourceAware sourceAware = getSourceAware(prevComment.getMark().getPath());+ if (sourceAware != null)+ sourceAware.onCommentClosed(target, prevComment);+ }++ Mark prevMark = RevisionDiffPanel.this.getMark();+ if (prevMark != null) {+ SourceAware sourceAware = getSourceAware(prevMark.getPath());+ if (sourceAware != null)+ sourceAware.unmark(target);}+ commentSupport.onCommentOpened(target, comment);target.appendJavaScript("onedev.server.revisionDiff.reposition();");}@@ -1162,15 +1156,15 @@ public class RevisionDiffPanel extends Panel {@Overridepublic void onClick(AjaxRequestTarget target) {- clearComment(target);CodeComment comment = getOpenComment();+ clearComment(target);+ target.appendJavaScript("onedev.server.revisionDiff.reposition();");if (comment != null) {SourceAware sourceAware = getSourceAware(comment.getMark().getPath());if (sourceAware != null)sourceAware.onCommentClosed(target, comment);commentSupport.onCommentClosed(target);}- target.appendJavaScript("onedev.server.revisionDiff.reposition();");}});diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.java b/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.javaindex b236a794d1..19ea2ea9b1 100644--- a/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.java+++ b/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/SourceViewPanel.java@@ -561,43 +561,39 @@ public class SourceViewPanel extends BlobViewPanel implements Positionable, Searcontext.onAddComment(target, mark);target.appendJavaScript(String.format("onedev.server.sourceView.onAddComment(%s);", getJson(mark)));break;- case "toggleComment":+ case "openComment":Long commentId = params.getParameterValue("param1").toLong();CodeComment comment = OneDev.getInstance(CodeCommentManager.class).load(commentId);- if (!comment.equals(context.getOpenComment())) {- CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentId) {+ CodeCommentPanel commentPanel = new CodeCommentPanel(BODY_ID, commentId) {- @Override- protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {- SourceViewPanel.this.onCommentDeleted(target, comment);- }+ @Override+ protected void onDeleteComment(AjaxRequestTarget target, CodeComment comment) {+ SourceViewPanel.this.onCommentDeleted(target, comment);+ }- @Override- protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {- OneDev.getInstance(CodeCommentManager.class).save(comment);- target.add(commentContainer.get("head"));- }+ @Override+ protected void onSaveComment(AjaxRequestTarget target, CodeComment comment) {+ OneDev.getInstance(CodeCommentManager.class).save(comment);+ target.add(commentContainer.get("head"));+ }- @Override- protected PullRequest getPullRequest() {- return context.getPullRequest();- }+ @Override+ protected PullRequest getPullRequest() {+ return context.getPullRequest();+ }- @Override- protected void onSaveCommentReply(AjaxRequestTarget target, CodeCommentReply reply) {- SourceViewPanel.this.onSaveCommentReply(reply);- }+ @Override+ protected void onSaveCommentReply(AjaxRequestTarget target, CodeCommentReply reply) {+ SourceViewPanel.this.onSaveCommentReply(reply);+ }- };- commentContainer.replace(commentPanel);- commentContainer.setVisible(true);- target.add(commentContainer);- script = String.format("onedev.server.sourceView.onOpenComment(%s);", getJsonOfComment(comment));- target.appendJavaScript(script);- context.onCommentOpened(target, comment);- } else {- closeComment(target);- }+ };+ commentContainer.replace(commentPanel);+ commentContainer.setVisible(true);+ target.add(commentContainer);+ script = String.format("onedev.server.sourceView.onOpenComment(%s);", getJsonOfComment(comment));+ target.appendJavaScript(script);+ context.onCommentOpened(target, comment);break;case "outlineSearch":new ModalPanel(target) {diff --git a/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/source-view.js b/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/source-view.jsindex 74a5302a74..337bb72813 100644--- a/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/source-view.js+++ b/server-core/src/main/java/io/onedev/server/web/page/project/blob/render/renderers/source/source-view.js@@ -287,7 +287,7 @@ onedev.server.sourceView = {for (var i in comments) {var comment = comments[i];var index = parseInt(i) + 1;- content += "<a class='comment-trigger' title='Click to show details of this comment'>#" + comment.id + "</a>";+ content += "<a class='comment-trigger' title='Click to show comment of marked text'>#" + comment.id + "</a>";}$indicator.popover({html: true,@@ -306,12 +306,14 @@ onedev.server.sourceView = {onedev.server.sourceView.restoreMark();});$(this).click(function() {- if ($(".source-view form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;- }- var comment = comments[$(this).index()];- callback("toggleComment", comment.id);+ if (!$(this).hasClass("active")) {+ if ($(".source-view form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ var comment = comments[$(this).index()];+ callback("openComment", comment.id);+ }});});onedev.server.sourceView.highlightCommentTrigger();@@ -327,11 +329,13 @@ onedev.server.sourceView = {onedev.server.sourceView.restoreMark();});$indicator.click(function() {- if ($(".source-view form.dirty").length != 0- && !confirm("There are unsaved changes, discard and continue?")) {- return;+ if (!$indicator.hasClass("active")) {+ if ($(".source-view form.dirty").length != 0+ && !confirm("There are unsaved changes, discard and continue?")) {+ return;+ }+ callback("openComment", comment.id);}- callback("toggleComment", comment.id);});}cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);