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

This commit is contained in:
Tim Zallmann 2017-09-26 14:23:01 +02:00
parent 8ace5fc188
commit e58c8413d4
4 changed files with 30 additions and 7 deletions

View File

@ -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,

View File

@ -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,
});
}
}
}
}
});
},

View File

@ -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;

View File

@ -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.