Commit e58c8413 authored by Tim Zallmann's avatar Tim Zallmann

Fixed Back Button for files + line number jumping for preview and editor

parent 8ace5fc1
......@@ -63,7 +63,7 @@ const RepoEditor = {
const lineNumber = e.target.position.lineNumber;
if (e.target.element.classList.contains('line-numbers')) {
location.hash = `L${lineNumber}`;
Store.activeLine = lineNumber;
Store.setActiveLine(lineNumber);
Helper.monacoInstance.setPosition({
lineNumber: this.activeLine,
......
......@@ -25,11 +25,28 @@ export default {
methods: {
addPopEventListener() {
window.addEventListener('popstate', () => {
if (location.href.indexOf('#') > -1) return;
this.linkClicked({
url: location.href,
});
window.addEventListener('popstate', (event) => {
const selectedFile = this.files.find(file => location.href.indexOf(file.url) > -1);
if (selectedFile) {
if (selectedFile.url !== this.activeFile.url) {
this.fileClicked(selectedFile);
}
if (location.hash.indexOf('#L') > -1) {
const lineNumber = Number(location.hash.substr(2));
if (!isNaN(lineNumber)) {
Store.setActiveLine(lineNumber);
if (Store.isPreviewView()) {
document.getElementById('L' + lineNumber).scrollIntoView();
} else {
Helper.monacoInstance.setPosition({
lineNumber: this.activeLine,
column: 1,
});
}
}
}
}
});
},
......
......@@ -254,7 +254,9 @@ const RepoHelper = {
RepoHelper.key = RepoHelper.genKey();
history.pushState({ key: RepoHelper.key }, '', url);
if (document.location.pathname !== url) {
history.pushState({ key: RepoHelper.key }, '', url);
}
if (title) {
document.title = title;
......
......@@ -101,6 +101,10 @@ const RepoStore = {
RepoStore.activeFileIndex = i;
},
setActiveLine(activeLine) {
RepoStore.activeLine = activeLine;
},
setActiveToRaw() {
RepoStore.activeFile.raw = false;
// can't get vue to listen to raw for some reason so RepoStore for now.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment