Fixed Back Button for files + line number jumping for preview and editor
This commit is contained in:
parent
8ace5fc188
commit
e58c8413d4
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue