Skip to content

The Unified and Autonomous Development Platform

Preserve scroll/cursor when edit/blame files

robin shine0f785560da4b
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java
index 77faa90663..23c996464e 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/CommonPage.java
@@ -118,12 +118,12 @@ public abstract class CommonPage extends WebPage {
public void pushState(AjaxRequestTarget target, String url, Serializable data) {
String encodedData = new String(Base64.encodeBase64(SerializationUtils.serialize(data)));
- target.appendJavaScript(String.format("pmease.commons.history.pushState('%s', '%s');", encodedData, url));
+ target.prependJavaScript(String.format("pmease.commons.history.pushState('%s', '%s');", encodedData, url));
}
public void replaceState(AjaxRequestTarget target, String url, Serializable data) {
String encodedData = new String(Base64.encodeBase64(SerializationUtils.serialize(data)));
- target.appendJavaScript(String.format("pmease.commons.history.replaceState('%s', '%s');", encodedData, url));
+ target.prependJavaScript(String.format("pmease.commons.history.replaceState('%s', '%s');", encodedData, url));
}
@Override
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
index 07df202e25..6f9f80228e 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/common.js
@@ -890,7 +890,6 @@ pmease.commons = {
};
},
pushState: function(data, url) {
- console.log("pushState");
var state = {data: data};
pmease.commons.history.current = {state: state, url: url};
history.pushState(state, '', url);
@@ -902,11 +901,11 @@ pmease.commons = {
history.replaceState(state, '', url);
pmease.commons.history.urlWithoutHash = location.pathname+(location.search?location.search:'');
},
- setScrollPos: function(scrollPos) {
+ setScroll: function(scroll) {
var state = history.state;
if (!state)
state = {};
- var newState = {scrollPos: scrollPos, cursor: state.cursor, data: state.data};
+ var newState = {scroll: scroll, cursor: state.cursor, data: state.data};
history.replaceState(newState, '', window.location.href );
pmease.commons.history.current = {
state: newState,
@@ -917,16 +916,16 @@ pmease.commons = {
var state = history.state;
if (!state)
state = {};
- var newState = {cursor: cursor, scrollPos: state.scrollPos, data: state.data};
+ var newState = {cursor: cursor, scroll: state.scroll, data: state.data};
history.replaceState(newState, '', window.location.href );
pmease.commons.history.current = {
state: newState,
url: window.location.href
};
},
- getScrollPos: function() {
- if (history.state && history.state.scrollPos)
- return history.state.scrollPos;
+ getScroll: function() {
+ if (history.state && history.state.scroll)
+ return history.state.scroll;
else
return undefined;
},
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java
new file mode 100644
index 0000000000..76510952a0
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/ClientStateAwareAjaxLink.java
@@ -0,0 +1,45 @@
+package com.pmease.commons.wicket.component;
+
+import javax.annotation.Nullable;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.cycle.RequestCycle;
+
+@SuppressWarnings("serial")
+public abstract class ClientStateAwareAjaxLink<T> extends AjaxLink<T> {
+
+ public ClientStateAwareAjaxLink(String id) {
+ super(id);
+ }
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.setMethod(Method.POST);
+
+ String script = String.format(""
+ + "var state = $('#%s').data('state');"
+ + "return state?JSON.stringify(state):'';", getMarkupId());
+ attributes.getDynamicExtraParameters().add("return {state: function() {" + script + "}}");
+ }
+
+ public ClientStateAwareAjaxLink(String id, IModel<T> model) {
+ super(id, model);
+ }
+
+ @Override
+ public final void onClick(AjaxRequestTarget target) {
+ String value = RequestCycle.get().getRequest().getRequestParameters().getParameterValue("state").toString();
+ if (StringUtils.isNotBlank(value))
+ onClick(target, value);
+ else
+ onClick(target, null);
+ }
+
+ protected abstract void onClick(AjaxRequestTarget target, @Nullable String clientState);
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java
index 9f239651ec..ddd7d176a3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobRenderer.java
@@ -7,6 +7,6 @@ import com.pmease.commons.loader.ExtensionPoint;
@ExtensionPoint
public interface BlobRenderer {
- @Nullable BlobViewPanel render(String panelId, BlobViewContext context);
+ @Nullable BlobViewPanel render(String panelId, BlobViewContext context, @Nullable String clientState);
}
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.java
index fef4c895b1..01267ac03d 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
@@ -42,10 +42,10 @@ public interface BlobViewContext extends Serializable {
void onSearchComplete(AjaxRequestTarget target, List<QueryHit> hits);
- void onBlameChange(AjaxRequestTarget target);
+ void onBlameChange(AjaxRequestTarget target, @Nullable String clientState);
void onDelete(AjaxRequestTarget target);
- void onEdit(AjaxRequestTarget target);
+ void onEdit(AjaxRequestTarget target, @Nullable String clientState);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.html
index f8ebb56270..bf5007db48 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.html
@@ -13,12 +13,12 @@
<div class="pull-right actions">
<div class="btn-group">
<a wicket:id="raw" class="btn btn-default btn-xs"><i class="fa fa-file-o"></i> Raw</a>
- <a wicket:id="blame" class="btn btn-default btn-xs blame-toggle"><i class="fa fa-user"></i> Blame</a>
+ <a wicket:id="blame" class="btn btn-default btn-xs blame-toggle preserve-cm-state"><i class="fa fa-user"></i> Blame</a>
<a wicket:id="history" class="btn btn-default btn-xs"><i class="fa fa-history"></i> History</a>
<wicket:container wicket:id="customActions"></wicket:container>
</div>
<div wicket:id="changeActions" class="btn-group">
- <a wicket:id="edit" class="btn btn-default btn-xs"><i class="fa fa-pencil"></i> <span wicket:id="label"></span></a>
+ <a wicket:id="edit" class="btn btn-default btn-xs preserve-cm-state"><i class="fa fa-pencil"></i> <span wicket:id="label"></span></a>
<a wicket:id="delete" class="btn btn-default btn-xs"><i class="fa fa-trash"></i> <span wicket:id="label"></span></a>
</div>
</div>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java
index 3c073973f9..e65532c302 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/BlobViewPanel.java
@@ -1,5 +1,7 @@
package com.pmease.gitplex.web.component.repofile.blobview;
+import javax.annotation.Nullable;
+
import org.apache.commons.io.FileUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
@@ -22,6 +24,7 @@ import com.google.common.base.Preconditions;
import com.pmease.commons.git.Blob;
import com.pmease.commons.git.BlobIdent;
import com.pmease.commons.wicket.assets.closestdescendant.ClosestDescendantResourceReference;
+import com.pmease.commons.wicket.component.ClientStateAwareAjaxLink;
import com.pmease.gitplex.web.component.repofile.blobview.BlobViewContext.Mode;
import com.pmease.gitplex.web.page.repository.file.RepoFilePage;
import com.pmease.gitplex.web.resource.BlobResource;
@@ -91,7 +94,7 @@ public abstract class BlobViewPanel extends Panel {
add(new ResourceLink<Void>("raw", new BlobResourceReference(),
BlobResource.paramsOf(context.getRepository(), context.getBlobIdent())));
- add(new AjaxLink<Void>("blame") {
+ add(new ClientStateAwareAjaxLink<Void>("blame") {
@Override
protected void onInitialize() {
@@ -113,8 +116,8 @@ public abstract class BlobViewPanel extends Panel {
}
@Override
- public void onClick(AjaxRequestTarget target) {
- context.onBlameChange(target);
+ public void onClick(AjaxRequestTarget target, @Nullable String clientState) {
+ context.onBlameChange(target, clientState);
// this blob view panel might be replaced with another panel
if (findPage() != null) {
@@ -154,7 +157,7 @@ public abstract class BlobViewPanel extends Panel {
};
add(changeActions);
- changeActions.add(new AjaxLink<Void>("edit") {
+ changeActions.add(new ClientStateAwareAjaxLink<Void>("edit") {
@Override
protected void onInitialize() {
@@ -182,9 +185,9 @@ public abstract class BlobViewPanel extends Panel {
}
@Override
- public void onClick(AjaxRequestTarget target) {
+ public void onClick(AjaxRequestTarget target, String state) {
if (context.isOnBranch()) {
- context.onEdit(target);
+ context.onEdit(target, state);
} else {
PageParameters params = RepoFilePage.paramsOf(context.getRepository(),
context.getPullRequest().getSourceBranch(), context.getBlobIdent().path, Mode.EDIT);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java
index 5e45782797..45df687764 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/binary/BinaryRenderer.java
@@ -8,7 +8,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class BinaryRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
Blob blob = context.getRepository().getBlob(context.getBlobIdent());
if (blob.getText() == null
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js
index eca74de3f5..97793714e4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/blob-view.js
@@ -3,7 +3,7 @@ gitplex.blobView = function(containerId) {
var $head = $blobView.find(">.head");
var $body = $blobView.find(">.body");
$body.scroll(function() {
- pmease.commons.history.setScrollPos({left: $body.scrollLeft(), top: $body.scrollTop()});
+ pmease.commons.history.setScroll({left: $body.scrollLeft(), top: $body.scrollTop()});
});
gitplex.expandable.getScrollTop = function() {
@@ -22,10 +22,10 @@ gitplex.blobView = function(containerId) {
$body.outerWidth(width).outerHeight(height);
$body.closestDescendant(".autofit:visible").trigger("autofit", [$body.width(), $body.height()]);
- var scrollPos = pmease.commons.history.getScrollPos();
- if (scrollPos) {
- $body.scrollLeft(scrollPos.left);
- $body.scrollTop(scrollPos.top);
+ var scroll = pmease.commons.history.getScroll();
+ if (scroll) {
+ $body.scrollLeft(scroll.left);
+ $body.scrollTop(scroll.top);
}
});
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java
index ef1d8d6bde..f77596b6ca 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/gitlink/GitLinkRenderer.java
@@ -7,7 +7,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class GitLinkRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
if (context.getBlobIdent().isGitLink())
return new GitLinkPanel(panelId, context);
else
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java
index 93e5f356fc..76132bd3ce 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/image/ImageRenderer.java
@@ -8,7 +8,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class ImageRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
Blob blob = context.getRepository().getBlob(context.getBlobIdent());
if (blob.getMediaType().getType().equalsIgnoreCase("image"))
return new ImageViewPanel(panelId, context);
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.java
index a0f3d6c26f..2faa53a552 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
@@ -10,13 +10,13 @@ import com.pmease.gitplex.web.component.repofile.blobview.source.SourceViewPanel
public class MarkdownRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
Blob blob = context.getRepository().getBlob(context.getBlobIdent());
if (context.getBlobIdent().isFile()
&& blob.getText() != null
&& context.getBlobIdent().path.endsWith(".md")) {
if (context.getHighlight() != null || context.getMode() == Mode.BLAME)
- return new SourceViewPanel(panelId, context);
+ return new SourceViewPanel(panelId, context, clientState);
else
return new MarkdownViewPanel(panelId, context);
} else {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java
index b94b273787..036bbdb6cd 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/source/SourceRenderer.java
@@ -8,12 +8,12 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class SourceRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
Blob blob = context.getRepository().getBlob(context.getBlobIdent());
if (context.getBlobIdent().isFile()
&& blob.getText() != null
&& !context.getBlobIdent().path.endsWith(".md")) {
- return new SourceViewPanel(panelId, context);
+ return new SourceViewPanel(panelId, context, clientState);
} else {
return null;
}
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.java
index ef3e19ad3e..37b59b693d 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
@@ -83,6 +83,8 @@ public class SourceViewPanel extends BlobViewPanel {
private final List<Symbol> symbols = new ArrayList<>();
+ private final String clientState;
+
private final IModel<List<Comment>> commentsModel = new LoadableDetachableModel<List<Comment>>() {
@Override
@@ -124,7 +126,7 @@ public class SourceViewPanel extends BlobViewPanel {
private AbstractDefaultAjaxBehavior addCommentBehavior;
- public SourceViewPanel(String id, BlobViewContext context) {
+ public SourceViewPanel(String id, BlobViewContext context, @Nullable String clientState) {
super(id, context);
Blob blob = context.getRepository().getBlob(context.getBlobIdent());
@@ -138,6 +140,8 @@ public class SourceViewPanel extends BlobViewPanel {
logger.debug("Error extracting symbols from blob: " + context.getBlobIdent(), e);
}
}
+
+ this.clientState = clientState;
}
@Override
@@ -361,7 +365,7 @@ public class SourceViewPanel extends BlobViewPanel {
addCommentCallback = addCommentBehavior.getCallbackFunction(CallbackParameter.explicit("lineNo"));
else
addCommentCallback = "undefined";
- String script = String.format("gitplex.sourceview.init('%s', '%s', '%s', %s, '%s', '%s', %s, %d, %s);",
+ String script = String.format("gitplex.sourceview.init('%s', '%s', '%s', %s, '%s', '%s', %s, %d, %s, %s);",
codeContainer.getMarkupId(),
StringEscapeUtils.escapeEcmaScript(blob.getText().getContent()),
context.getBlobIdent().path,
@@ -370,7 +374,8 @@ public class SourceViewPanel extends BlobViewPanel {
context.getBlobIdent().revision,
blameCommitsJson,
context.getComment()!=null?context.getComment().getId():-1,
- addCommentCallback);
+ addCommentCallback,
+ clientState!=null?"'"+clientState+"'":"undefined");
response.render(OnDomReadyHeaderItem.forScript(script));
}
diff --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.js
index a3441475e9..1db43bf411 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,6 +1,6 @@
gitplex.sourceview = {
init: function(codeId, fileContent, filePath, highlight, symbolTooltipId, revision,
- blameCommits, commentId, addCommentCallback) {
+ blameCommits, commentId, addCommentCallback, cmState) {
var cm;
var $code = $("#" + codeId);
@@ -110,37 +110,7 @@ gitplex.sourceview = {
CodeMirror.autoLoadMode(cm, modeInfo.mode);
}
- // use scroll timer and cursor timer to minimize performance impact of
- // remembering scroll and cursor position
- var scrollTimer;
- cm.on("scroll", function() {
- gitplex.mouseState.moved = false;
- if (scrollTimer)
- clearTimeout(scrollTimer);
- scrollTimer = setTimeout(function() {
- scrollTimer = undefined;
- var scrollInfo = cm.getScrollInfo();
- pmease.commons.history.setScrollPos({left: scrollInfo.left, top: scrollInfo.top});
- }, 500);
- });
- var scrollPos = pmease.commons.history.getScrollPos();
- if (scrollPos)
- cm.scrollTo(scrollPos.left, scrollPos.top);
-
- var cursorTimer;
- cm.on("cursorActivity", function() {
- if (cursorTimer)
- clearTimeout(cursorTimer);
- cursorTimer = setTimeout(function() {
- cursorTimer = undefined;
- pmease.commons.history.setCursor(cm.getCursor());
- }, 500);
- });
-
- console.log("check cursor");
- var cursor = pmease.commons.history.getCursor();
- if (cursor)
- cm.setCursor(cursor);
+ gitplex.codemirror.initState(cm, cmState);
if (highlight)
gitplex.sourceview.highlight(cm, highlight);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java
index 8cf3ea67e9..9576f22d9f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/blobview/symbollink/SymbolLinkRenderer.java
@@ -7,7 +7,7 @@ import com.pmease.gitplex.web.component.repofile.blobview.BlobViewPanel;
public class SymbolLinkRenderer implements BlobRenderer {
@Override
- public BlobViewPanel render(String panelId, BlobViewContext context) {
+ public BlobViewPanel render(String panelId, BlobViewContext context, String clientState) {
if (context.getBlobIdent().isSymbolLink())
return new SymbolLinkPanel(panelId, context);
else
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js
index bc93c65f2b..933719fae8 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/editsave/edit-save.js
@@ -2,7 +2,7 @@ gitplex.editsave = {
init: function(containerId) {
var $editSave = $("#" + containerId + ">.edit-save");
$editSave.scroll(function() {
- pmease.commons.history.setScrollPos({left: $editSave.scrollLeft(), top: $editSave.scrollTop()});
+ pmease.commons.history.setScroll({left: $editSave.scrollLeft(), top: $editSave.scrollTop()});
});
gitplex.expandable.getScrollTop = function() {
@@ -19,10 +19,10 @@ gitplex.editsave = {
$editSave.outerWidth(width);
$editSave.outerHeight(height);
- var scrollPos = pmease.commons.history.getScrollPos();
- if (scrollPos) {
- $editSave.scrollLeft(scrollPos.left);
- $editSave.scrollTop(scrollPos.top);
+ var scroll = pmease.commons.history.getScroll();
+ if (scroll) {
+ $editSave.scrollLeft(scroll.left);
+ $editSave.scrollTop(scroll.top);
}
});
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
index b8c8b113a8..19c3b789da 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/FileEditPanel.java
@@ -60,6 +60,8 @@ public abstract class FileEditPanel extends Panel {
private final ObjectId prevCommitId;
+ private final String clientState;
+
private AbstractDefaultAjaxBehavior previewBehavior;
private AbstractDefaultAjaxBehavior saveBehavior;
@@ -67,13 +69,15 @@ public abstract class FileEditPanel extends Panel {
private EditSavePanel editSavePanel;
public FileEditPanel(String id, IModel<Repository> repoModel, String refName,
- @Nullable String oldPath, String content, ObjectId prevCommitId) {
+ @Nullable String oldPath, String content, ObjectId prevCommitId,
+ @Nullable String clientState) {
super(id);
this.repoModel = repoModel;
this.refName = refName;
this.oldPath = GitUtils.normalizePath(oldPath);
this.content = content;
this.prevCommitId = prevCommitId;
+ this.clientState = clientState;
newPath = this.oldPath;
}
@@ -213,10 +217,11 @@ public abstract class FileEditPanel extends Panel {
response.render(CssHeaderItem.forReference(
new CssResourceReference(FileEditPanel.class, "file-edit.css")));
- String script = String.format("gitplex.fileEdit.init('%s', '%s', '%s', %s, %s);",
+ String script = String.format("gitplex.fileEdit.init('%s', '%s', '%s', %s, %s, %s);",
getMarkupId(), getNewPathParam(), StringEscapeUtils.escapeEcmaScript(content),
previewBehavior.getCallbackFunction(CallbackParameter.explicit("content")),
- saveBehavior.getCallbackFunction(CallbackParameter.explicit("content")));
+ saveBehavior.getCallbackFunction(CallbackParameter.explicit("content")),
+ clientState!=null?"'"+clientState+"'":"undefined");
response.render(OnDomReadyHeaderItem.forScript(script));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js
index d363fac9af..4a0a41c0d1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/fileedit/file-edit.js
@@ -1,5 +1,5 @@
gitplex.fileEdit = {
- init: function(containerId, filePath, fileContent, previewCallback, saveCallback) {
+ init: function(containerId, filePath, fileContent, previewCallback, saveCallback, cmState) {
var $container = $("#" + containerId);
var $fileEdit = $container.find(">.file-edit");
var $head = $fileEdit.find(">.head");
@@ -40,37 +40,8 @@ gitplex.fileEdit = {
});
cm.focus();
- // use scroll timer and cursor timer to minimize performance impact of
- // remembering scroll and cursor position
- var scrollTimer;
- cm.on("scroll", function() {
- if (scrollTimer)
- clearTimeout(scrollTimer);
- scrollTimer = setTimeout(function() {
- scrollTimer = undefined;
- var scrollInfo = cm.getScrollInfo();
- pmease.commons.history.setScrollPos({left: scrollInfo.left, top: scrollInfo.top});
- }, 500);
- });
- var scrollPos = pmease.commons.history.getScrollPos();
- if (scrollPos)
- cm.scrollTo(scrollPos.left, scrollPos.top);
-
- var cursorTimer;
- cm.on("cursorActivity", function() {
- if (cursorTimer)
- clearTimeout(cursorTimer);
- cursorTimer = setTimeout(function() {
- cursorTimer = undefined;
- pmease.commons.history.setCursor(cm.getCursor());
- }, 500);
- });
+ gitplex.codemirror.initState(cm, cmState);
- console.log("check cursor");
- var cursor = pmease.commons.history.getCursor();
- if (cursor)
- cm.setCursor(cursor);
-
gitplex.fileEdit.setMode(cm, filePath);
CodeMirror.keyMap.default["Ctrl-L"] = "gotoLine";
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js
index 05927c30b7..72d71b3c6a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/repofile/filelist/file-list.js
@@ -15,15 +15,15 @@ gitplex.filelist = {
$fileList.outerWidth(width);
$fileList.outerHeight(height);
- var scrollPos = pmease.commons.history.getScrollPos();
- if (scrollPos) {
- $fileList.scrollLeft(scrollPos.left);
- $fileList.scrollTop(scrollPos.top);
+ var scroll = pmease.commons.history.getScroll();
+ if (scroll) {
+ $fileList.scrollLeft(scroll.left);
+ $fileList.scrollTop(scroll.top);
}
});
$fileList.scroll(function() {
- pmease.commons.history.setScrollPos({left: $fileList.scrollLeft(), top: $fileList.scrollTop()});
+ pmease.commons.history.setScroll({left: $fileList.scrollLeft(), top: $fileList.scrollTop()});
});
$.ajax({
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js
index 31e9e98212..5b153867ae 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/base/base.js
@@ -49,6 +49,66 @@ var gitplex = {
mouseState: {
pressed: false,
moved: false
+ },
+
+ codemirror: {
+ initState: function(cm, stateStr) {
+ // use timer to minimize performance impact
+ var cursorTimer;
+ cm.on("cursorActivity", function() {
+ if (cursorTimer)
+ clearTimeout(cursorTimer);
+ cursorTimer = setTimeout(function() {
+ cursorTimer = undefined;
+ var cursor = cm.getCursor();
+ pmease.commons.history.setCursor(cursor);
+ $(".preserve-cm-state").each(function() {
+ var state = $(this).data("state");
+ if (!state)
+ state = {};
+ state.cursor = cursor;
+ $(this).data("state", state);
+ });
+ }, 500);
+ });
+
+ var cursor = pmease.commons.history.getCursor();
+ if (cursor)
+ cm.setCursor(cursor);
+
+ // use timer to minimize performance impact
+ var scrollTimer;
+ cm.on("scroll", function() {
+ gitplex.mouseState.moved = false;
+ if (scrollTimer)
+ clearTimeout(scrollTimer);
+ scrollTimer = setTimeout(function() {
+ scrollTimer = undefined;
+ var scrollInfo = cm.getScrollInfo();
+ var scroll = {left: scrollInfo.left, top: scrollInfo.top};
+ pmease.commons.history.setScroll(scroll);
+ $(".preserve-cm-state").each(function() {
+ var state = $(this).data("state");
+ if (!state)
+ state = {};
+ state.scroll = scroll;
+ $(this).data("state", state);
+ });
+ }, 500);
+ });
+ var scroll = pmease.commons.history.getScroll();
+ if (scroll)
+ cm.scrollTo(scroll.left, scroll.top);
+
+ if (stateStr) {
+ var state = JSON.parse(stateStr);
+ if (state.cursor)
+ cm.setCursor(state.cursor);
+ if (state.scroll)
+ cm.scrollTo(state.scroll.left, state.scroll.top);
+ }
+
+ }
}
};
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.java
index 6e9145642c..0f40982977 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
@@ -369,7 +369,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
});
newLastCommit(null);
- newFileViewer(null);
+ newFileViewer(null, null);
add(searchResultContainer = new WebMarkupContainer("searchResultContainer"));
@@ -452,7 +452,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
mode = Mode.EDIT;
newFileNavigator(target);
- newFileViewer(target);
+ newFileViewer(target, null);
pushState(target);
resizeWindow(target);
@@ -497,9 +497,9 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
}
}
- private BlobViewPanel renderBlobViewer(String panelId) {
+ private BlobViewPanel renderBlobViewer(String panelId, @Nullable String clientState) {
for (BlobRenderer renderer: GitPlex.getExtensions(BlobRenderer.class)) {
- BlobViewPanel panel = renderer.render(panelId, this);
+ BlobViewPanel panel = renderer.render(panelId, this, clientState);
if (panel != null)
return panel;
}
@@ -507,7 +507,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
throw new IllegalStateException("No applicable blob renderer found.");
}
- private void newFileViewer(@Nullable AjaxRequestTarget target) {
+ private void newFileViewer(@Nullable AjaxRequestTarget target, @Nullable String clientState) {
Component fileViewer;
if (mode == Mode.EDIT) {
final String refName = GitUtils.branch2ref(blobIdent.revision);
@@ -516,7 +516,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
FILE_VIEWER_ID, repoModel, refName,
blobIdent.isTree()?null:blobIdent.path,
blobIdent.isTree()?"":getRepository().getBlob(blobIdent).getText().getContent(),
- getRepository().getObjectId(blobIdent.revision)) {
+ getRepository().getObjectId(blobIdent.revision), clientState) {
@Override
protected void onCommitted(AjaxRequestTarget target, ObjectId newCommitId) {
@@ -540,7 +540,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
protected void onCancel(AjaxRequestTarget target) {
mode = null;
newFileNavigator(target);
- newFileViewer(target);
+ newFileViewer(target, null);
pushState(target);
resizeWindow(target);
}
@@ -555,7 +555,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
public void onCancel(AjaxRequestTarget target) {
mode = null;
- newFileViewer(target);
+ newFileViewer(target, null);
pushState(target);
resizeWindow(target);
@@ -608,7 +608,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
};
} else {
- fileViewer = renderBlobViewer(FILE_VIEWER_ID);
+ fileViewer = renderBlobViewer(FILE_VIEWER_ID, clientState);
}
if (target != null) {
replace(fileViewer);
@@ -701,7 +701,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
target.add(revisionIndexing);
newLastCommit(target);
- newFileViewer(target);
+ newFileViewer(target, null);
}
@Override
@@ -885,7 +885,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
SourceViewPanel sourceViewer = (SourceViewPanel) fileViewer;
sourceViewer.highlight(target, highlight);
} else {
- newFileViewer(target);
+ newFileViewer(target, null);
resizeWindow(target);
}
} else {
@@ -894,7 +894,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
newFileNavigator(target);
newLastCommit(target);
- newFileViewer(target);
+ newFileViewer(target, null);
resizeWindow(target);
}
@@ -908,12 +908,12 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
}
@Override
- public void onBlameChange(AjaxRequestTarget target) {
+ public void onBlameChange(AjaxRequestTarget target, @Nullable String clientState) {
if (mode == null)
mode = Mode.BLAME;
else
mode = null;
- newFileViewer(target);
+ newFileViewer(target, clientState);
pushState(target);
resizeWindow(target);
}
@@ -922,17 +922,17 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {
public void onDelete(AjaxRequestTarget target) {
mode = Mode.DELETE;
- newFileViewer(target);
+ newFileViewer(target, null);
pushState(target);
resizeWindow(target);
}
@Override
- public void onEdit(AjaxRequestTarget target) {
+ public void onEdit(AjaxRequestTarget target, @Nullable String clientState) {
mode = Mode.EDIT;
newFileNavigator(target);
- newFileViewer(target);
+ newFileViewer(target, clientState);
pushState(target);
resizeWindow(target);
}