The Unified and Autonomous Development Platform
midwork
robin shine9256855f2a68
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.javaindex 73fe0850cb..4e3d3f00cd 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewContext.java@@ -13,6 +13,7 @@ import com.pmease.gitplex.core.model.Comment;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.search.hit.QueryHit;+import com.pmease.gitplex.web.page.repository.file.Highlight;public interface BlobViewContext extends Serializable {@@ -29,7 +30,7 @@ public interface BlobViewContext extends Serializable {BlobIdent getBlobIdent();@Nullable- TokenPosition getTokenPos();+ Highlight getHighlight();Mode getMode();diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.javaindex cd3d7583a2..a0f3d6c26f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/markdown/MarkdownRenderer.java@@ -15,7 +15,7 @@ public class MarkdownRenderer implements BlobRenderer {if (context.getBlobIdent().isFile()&& blob.getText() != null&& context.getBlobIdent().path.endsWith(".md")) {- if (context.getTokenPos() != null || context.getMode() == Mode.BLAME)+ if (context.getHighlight() != null || context.getMode() == Mode.BLAME)return new SourceViewPanel(panelId, context);elsereturn new MarkdownViewPanel(panelId, context);diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.javaindex 2b12f9c832..f29013249d 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceViewPanel.java@@ -51,7 +51,6 @@ import com.pmease.commons.lang.extractors.ExtractException;import com.pmease.commons.lang.extractors.Extractor;import com.pmease.commons.lang.extractors.Extractors;import com.pmease.commons.lang.extractors.Symbol;-import com.pmease.commons.lang.extractors.TokenPosition;import com.pmease.commons.loader.InheritableThreadLocalData;import com.pmease.commons.wicket.assets.codemirror.CodeMirrorResourceReference;import com.pmease.commons.wicket.assets.cookies.CookiesResourceReference;@@ -72,6 +71,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewContext.Mode;import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;import com.pmease.gitplex.web.page.repository.commit.RepoCommitPage;+import com.pmease.gitplex.web.page.repository.file.Highlight;import com.pmease.gitplex.web.utils.DateUtils;@SuppressWarnings("serial")@@ -147,18 +147,18 @@ public class SourceViewPanel extends BlobViewPanel {return fragment;}- public void highlightToken(AjaxRequestTarget target, @Nullable TokenPosition tokenPos) {+ public void highlight(AjaxRequestTarget target, @Nullable Highlight highlight) {String json;- if (tokenPos != null) {+ if (highlight != null) {try {- json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(tokenPos);+ json = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(highlight);} catch (JsonProcessingException e) {throw new RuntimeException(e);}} else {json = "undefined";}- String script = String.format("gitplex.sourceview.highlightToken('%s', %s);",+ String script = String.format("gitplex.sourceview.highlight('%s', %s);",codeContainer.getMarkupId(), json);target.appendJavaScript(script);}@@ -174,7 +174,7 @@ public class SourceViewPanel extends BlobViewPanel {@Overrideprotected void onSelect(AjaxRequestTarget target, Symbol symbol) {- highlightToken(target, symbol.getPos());+ highlight(target, new Highlight(symbol.getPos()));}});@@ -312,9 +312,9 @@ public class SourceViewPanel extends BlobViewPanel {response.render(CssHeaderItem.forReference(new CssResourceReference(SourceViewPanel.class, "source-view.css")));- String highlightToken;+ String highlight;try {- highlightToken = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(context.getTokenPos());+ highlight = GitPlex.getInstance(ObjectMapper.class).writeValueAsString(context.getHighlight());} catch (JsonProcessingException e) {throw new RuntimeException(e);}@@ -329,7 +329,7 @@ public class SourceViewPanel extends BlobViewPanel {codeContainer.getMarkupId(),StringEscapeUtils.escapeEcmaScript(blob.getText().getContent()),context.getBlobIdent().path,- highlightToken,+ highlight,symbolTooltip.getMarkupId(),context.getBlobIdent().revision,getBlameCommits(),diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.cssindex 9c7426f3f4..70208f0e6c 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.css@@ -4,18 +4,6 @@padding-left: 4px;border-left: 1px solid #DDD;}-.CodeMirror-tokentooltip ul.declarations li {- vertical-align: top;- padding: 2px 4px;- white-space: nowrap;-}-.CodeMirror-tokentooltip ul.declarations .scope {- color: #666;-}-.CodeMirror-tokentooltip>div {- font-weight: bold;-}-.source-view>.outline {font-size: 13px;}@@ -69,3 +57,9 @@ pre+.CodeMirror-linewidget>.comment>div, pre+.CodeMirror-linewidget>.comment>forcolor: black;font-size: 14px;}+.CodeMirror-highlight {+ background: #D4A7F3;+}+.CodeMirror-highlight.cm-identifierhighlight {+ background: #ACF0A6;+}\ No newline at end of filediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.jsindex a58f762ff6..d47af04dd4 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/source-view.js@@ -1,5 +1,5 @@gitplex.sourceview = {- init: function(codeId, fileContent, filePath, tokenPos, symbolTooltipId, revision,+ init: function(codeId, fileContent, filePath, highlight, symbolTooltipId, revision,blameCommits, commentId, addCommentCallback) {var cm;@@ -70,16 +70,6 @@ gitplex.sourceview = {matchBrackets: true,scrollbarStyle: "simple",highlightIdentifiers: {delay: 500},- tokenHover: {- getTooltip: function(tokenEl) {- var tooltip = document.createElement("div");- var $tooltip = $(tooltip);- $tooltip.html("<img src=" + ajaxIndicatorUrl + "></img>");- $tooltip.attr("id", codeId + "-symbolstooltip");- symbolQuery($(tokenEl).text());- return tooltip;- }- },gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],extraKeys: {"F11": function(cm) {@@ -120,8 +110,8 @@ gitplex.sourceview = {CodeMirror.autoLoadMode(cm, modeInfo.mode);}- if (tokenPos)- gitplex.sourceview.highlightToken(cm, tokenPos);+ if (highlight)+ gitplex.sourceview.highlight(cm, highlight);// use scroll timer and cursor timer to minimize performance impact of// remembering scroll and cursor position@@ -188,30 +178,22 @@ gitplex.sourceview = {});},- symbolsQueried: function(codeId, symbolsId) {- var $symbols = $("#" + symbolsId);- var $tooltip = $("#" + codeId + "-symbolstooltip");- $tooltip.children().remove();- $symbols.children().appendTo($tooltip);- $tooltip.align();- },-- highlightToken: function(cm, tokenPos) {+ highlight: function(cm, highlight) {if (typeof cm === "string")cm = $("#"+ cm + ">.CodeMirror")[0].CodeMirror;- if (tokenPos) {+ if (highlight) {var h = cm.getScrollInfo().clientHeight;- var coords = cm.charCoords({line: tokenPos.line, ch: 0}, "local");+ var coords = cm.charCoords({line: highlight.fromLine, ch: 0}, "local");cm.scrollTo(null, (coords.top + coords.bottom - h) / 2);- if (tokenPos.range) {- var anchor = {line: tokenPos.line, ch: tokenPos.range.start};- var head = {line: tokenPos.line, ch: tokenPos.range.end};- cm.setSelection(anchor, head);- } else {- cm.setCursor(tokenPos.line);- }+ var allMarks = cm.getAllMarks();+ for (var i=0; i<allMarks.length; i++)+ allMarks[i].clear();+ cm.markText(+ {line: highlight.fromLine, ch: highlight.fromChar},+ {line: highlight.toLine, ch: highlight.toChar},+ {className: "CodeMirror-highlight"});} else {cm.setCursor(0, 0);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/Highlight.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/Highlight.javanew file mode 100644index 0000000000..7840b1c223--- /dev/null+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/Highlight.java@@ -0,0 +1,57 @@+package com.pmease.gitplex.web.page.repository.file;++import java.io.Serializable;++import org.apache.commons.lang3.StringUtils;++import com.pmease.commons.lang.extractors.TokenPosition;++public class Highlight implements Serializable {++ private static final long serialVersionUID = 1L;++ private final int fromLine, fromChar, toLine, toChar;++ public Highlight(int fromLine, int fromChar, int toLine, int toChar) {+ this.fromLine = fromLine;+ this.fromChar = fromChar;+ this.toLine = toLine;+ this.toChar = toChar;+ }++ public Highlight(TokenPosition tokenPos) {+ this(tokenPos.getLine(), tokenPos.getRange().getStart(),+ tokenPos.getLine(), tokenPos.getRange().getEnd());+ }++ public Highlight(String str) {+ String from = StringUtils.substringBefore(str, "-");+ String to = StringUtils.substringAfter(str, "-");+ fromLine = Integer.parseInt(StringUtils.substringBefore(from, ","))-1;+ fromChar = Integer.parseInt(StringUtils.substringAfter(from, ","))-1;+ toLine = Integer.parseInt(StringUtils.substringBefore(to, ","))-1;+ toChar = Integer.parseInt(StringUtils.substringAfter(to, ","))-1;+ }++ public int getFromLine() {+ return fromLine;+ }++ public int getFromChar() {+ return fromChar;+ }++ public int getToLine() {+ return toLine;+ }++ public int getToChar() {+ return toChar;+ }++ @Override+ public String toString() {+ return (fromLine+1) + "," + (fromChar+1) + "-" + (toLine+1) + "," + (toChar+1);+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.javaindex fa7a4bf678..7df562c331 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.java@@ -3,7 +3,6 @@ package com.pmease.gitplex.web.page.repository.file;import java.io.Serializable;import com.pmease.commons.git.BlobIdent;-import com.pmease.commons.lang.extractors.TokenPosition;import com.pmease.gitplex.web.component.repofile.blobview.BlobViewContext.Mode;class HistoryState implements Serializable {@@ -16,7 +15,7 @@ class HistoryState implements Serializable {public BlobIdent blobIdent = new BlobIdent();- public TokenPosition tokenPos;+ public Highlight highlight;public Mode mode;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.javaindex 5d740c1491..20ddc3d906 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java@@ -95,6 +95,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private static final String PARAM_MODE = "mode";+ private static final String PARAM_HIGHLIGHT = "highlight";+private static final String REVISION_SELECTOR_ID = "revisionSelector";private static final String FILE_NAVIGATOR_ID = "fileNavigator";@@ -137,7 +139,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private BlobIdent blobIdent = new BlobIdent();- private TokenPosition tokenPos;+ private Highlight highlight;private Mode mode;@@ -587,14 +589,14 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private void pushState(AjaxRequestTarget target) {PageParameters params = paramsOf(getRepository(), blobIdent.revision, blobIdent.path,- mode, commentId, requestId);+ mode, highlight, commentId, requestId);CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, params);HistoryState state = new HistoryState();state.mode = mode;state.commentId = commentId;state.requestId = requestId;state.blobIdent = blobIdent;- state.tokenPos = tokenPos;+ state.highlight = highlight;pushState(target, url.toString(), state);}@@ -616,12 +618,12 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}public static PageParameters paramsOf(PullRequest request, String commitHash, @Nullable String path) {- return paramsOf(request.getTargetRepo(), commitHash, path, null, null, request.getId());+ return paramsOf(request.getTargetRepo(), commitHash, path, null, null, null, request.getId());}public static PageParameters paramsOf(Comment comment) {return paramsOf(comment.getRepository(), comment.getBlobIdent().revision,- comment.getBlobIdent().path, null, comment.getId(), null);+ comment.getBlobIdent().path, null, null, comment.getId(), null);}public static PageParameters paramsOf(Repository repository, BlobIdent blobIdent) {@@ -634,11 +636,12 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {public static PageParameters paramsOf(Repository repository, @Nullable String revision,@Nullable String path, @Nullable Mode mode) {- return paramsOf(repository, revision, path, mode, null, null);+ return paramsOf(repository, revision, path, mode, null, null, null);}public static PageParameters paramsOf(Repository repository, @Nullable String revision,- @Nullable String path, Mode mode, @Nullable Long commentId, @Nullable Long requestId) {+ @Nullable String path, Mode mode, @Nullable Highlight highlight,+ @Nullable Long commentId, @Nullable Long requestId) {PageParameters params = paramsOf(repository);if (revision != null)params.set(PARAM_REVISION, revision);@@ -646,6 +649,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {params.set(PARAM_PATH, path);if (mode != null)params.set(PARAM_MODE, mode.name().toLowerCase());+ if (highlight != null)+ params.set(PARAM_HIGHLIGHT, highlight.toString());if (commentId != null)params.set(PARAM_COMMENT, commentId);if (requestId != null)@@ -670,14 +675,14 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {@Overrideprotected void onSelect(AjaxRequestTarget target, QueryHit hit) {if (hit.getBlobPath().equals(blobIdent.path) && fileViewer instanceof SourceViewPanel) {- tokenPos = hit.getTokenPos();+ highlight = new Highlight(hit.getTokenPos());SourceViewPanel sourceViewer = (SourceViewPanel) fileViewer;- if (tokenPos != null || mode == Mode.BLAME) {- sourceViewer.highlightToken(target, tokenPos);+ if (highlight != null || mode == Mode.BLAME) {+ sourceViewer.highlight(target, highlight);} else {BlobViewPanel blobViewer = renderBlobViewer(FILE_VIEWER_ID);if (blobViewer instanceof SourceViewPanel) {- sourceViewer.highlightToken(target, tokenPos);+ sourceViewer.highlight(target, highlight);} else {fileViewer.replaceWith(blobViewer);fileViewer = blobViewer;@@ -714,7 +719,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {mode = state.mode;commentId = state.commentId;requestId = state.requestId;- tokenPos = state.tokenPos;+ highlight = state.highlight;trait.revision = blobIdent.revision;@@ -777,8 +782,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}@Override- public TokenPosition getTokenPos() {- return tokenPos;+ public Highlight getHighlight() {+ return highlight;}@Override@@ -789,7 +794,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {@Overridepublic void onSelect(AjaxRequestTarget target, BlobIdent blobIdent, TokenPosition tokenPos) {this.blobIdent = blobIdent;- this.tokenPos = tokenPos;+ this.highlight = new Highlight(tokenPos);mode = null;newFileNavigator(target, null);@@ -813,7 +818,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {if (fileViewer instanceof SourceViewPanel) {SourceViewPanel sourceViewer = (SourceViewPanel) fileViewer;- if (Mode.BLAME == mode || tokenPos != null) {+ if (Mode.BLAME == mode || highlight != null) {sourceViewer.onBlameChange(target);} else {BlobViewPanel blobViewer = renderBlobViewer(FILE_VIEWER_ID);