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 = { ...@@ -63,7 +63,7 @@ const RepoEditor = {
const lineNumber = e.target.position.lineNumber; const lineNumber = e.target.position.lineNumber;
if (e.target.element.classList.contains('line-numbers')) { if (e.target.element.classList.contains('line-numbers')) {
location.hash = `L${lineNumber}`; location.hash = `L${lineNumber}`;
Store.activeLine = lineNumber; Store.setActiveLine(lineNumber);
Helper.monacoInstance.setPosition({ Helper.monacoInstance.setPosition({
lineNumber: this.activeLine, lineNumber: this.activeLine,
......
...@@ -25,11 +25,28 @@ export default { ...@@ -25,11 +25,28 @@ export default {
methods: { methods: {
addPopEventListener() { addPopEventListener() {
window.addEventListener('popstate', () => { window.addEventListener('popstate', (event) => {
if (location.href.indexOf('#') > -1) return; const selectedFile = this.files.find(file => location.href.indexOf(file.url) > -1);
this.linkClicked({ if (selectedFile) {
url: location.href, 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 = { ...@@ -254,7 +254,9 @@ const RepoHelper = {
RepoHelper.key = RepoHelper.genKey(); RepoHelper.key = RepoHelper.genKey();
if (document.location.pathname !== url) {
history.pushState({ key: RepoHelper.key }, '', url); history.pushState({ key: RepoHelper.key }, '', url);
}
if (title) { if (title) {
document.title = title; document.title = title;
......
...@@ -101,6 +101,10 @@ const RepoStore = { ...@@ -101,6 +101,10 @@ const RepoStore = {
RepoStore.activeFileIndex = i; RepoStore.activeFileIndex = i;
}, },
setActiveLine(activeLine) {
RepoStore.activeLine = activeLine;
},
setActiveToRaw() { setActiveToRaw() {
RepoStore.activeFile.raw = false; RepoStore.activeFile.raw = false;
// can't get vue to listen to raw for some reason so RepoStore for now. // 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