Skip to content

The Unified and Autonomous Development Platform

remember cursor position when switching between source view and edit.

robin shinef449bf3031fd
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 39f8c2fdc4..b8e9b9ff7a 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
@@ -860,7 +860,18 @@ pmease.commons = {
var state = history.state;
if (!state)
state = {};
- var newState = {scrollPos: scrollPos, data: state.data};
+ var newState = {scrollPos: scrollPos, cursor: state.cursor, data: state.data};
+ history.replaceState(newState, '', window.location.href );
+ pmease.commons.history.current = {
+ state: newState,
+ url: window.location.href
+ };
+ },
+ setCursor: function(cursor) {
+ var state = history.state;
+ if (!state)
+ state = {};
+ var newState = {cursor: cursor, scrollPos: state.scrollPos, data: state.data};
history.replaceState(newState, '', window.location.href );
pmease.commons.history.current = {
state: newState,
@@ -872,6 +883,12 @@ pmease.commons = {
return history.state.scrollPos;
else
return undefined;
+ },
+ getCursor: function() {
+ if (history.state && history.state.cursor)
+ return history.state.cursor;
+ else
+ return undefined;
}
},
isDevice: function() {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/source-view.js
index 4db0abea1f..c4f672aa29 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/blobview/source/source-view.js
@@ -105,18 +105,24 @@ gitplex.sourceview = {
CodeMirror.autoLoadMode(cm, modeInfo.mode);
}
+ if (tokenPos)
+ gitplex.sourceview.highlightToken(cm, tokenPos);
+
cm.on("scroll", function() {
var scrollInfo = cm.getScrollInfo();
pmease.commons.history.setScrollPos({left: scrollInfo.left, top: scrollInfo.top});
});
-
- if (tokenPos)
- gitplex.sourceview.highlightToken(cm, tokenPos);
-
var scrollPos = pmease.commons.history.getScrollPos();
if (scrollPos)
cm.scrollTo(scrollPos.left, scrollPos.top);
+ cm.on("cursorActivity", function() {
+ pmease.commons.history.setCursor(cm.getCursor());
+ });
+ var cursor = pmease.commons.history.getCursor();
+ if (cursor)
+ cm.setCursor(cursor);
+
if (blameCommits) {
// render blame blocks with a timer to avoid the issue that occasionally
// blame gutter becomes much wider than expected
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js
index b9fd2dc29f..75d82d355d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/fileedit/file-edit.js
@@ -27,11 +27,17 @@ gitplex.fileEdit = {
var scrollInfo = cm.getScrollInfo();
pmease.commons.history.setScrollPos({left: scrollInfo.left, top: scrollInfo.top});
});
-
var scrollPos = pmease.commons.history.getScrollPos();
if (scrollPos)
cm.scrollTo(scrollPos.left, scrollPos.top);
+ cm.on("cursorActivity", function() {
+ pmease.commons.history.setCursor(cm.getCursor());
+ });
+ var cursor = pmease.commons.history.getCursor();
+ if (cursor)
+ cm.setCursor(cursor);
+
gitplex.fileEdit.setMode(cm, filePath);
$head.find("a.edit").click(function() {