Skip to content

Commit b26ac7e

Browse files
committed
Fixed next/prev issue for real this time
1 parent 6e8063f commit b26ac7e

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

package-lock.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"@types/url-parse": "^1.4.1",
3333
"fengari": "^0.1.2",
3434
"monaco-editor": "^0.14.3",
35-
"typescript-to-lua": "file:../typescript-to-lua-0.9.0.tgz",
36-
"url-parse": "^1.4.3"
35+
"typescript-to-lua": "file:../typescript-to-lua-0.9.0.tgz"
3736
}
3837
}

src/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {editor} from 'monaco-editor/esm/vs/editor/editor.api';
44

55
import TSTLWorker = require('worker-loader!./tstlWorker');
66

7-
import * as URL from "url-parse";
8-
97
document.addEventListener('DOMContentLoaded', () => {
108
const container = document.getElementById('example-ts');
119
const exampleLua = document.getElementById('example-lua');
@@ -31,9 +29,10 @@ document.addEventListener('DOMContentLoaded', () => {
3129
document.body.appendChild(button);
3230
`;
3331

34-
let windowUrl = new URL(window.location.href, window.location, true);
35-
if (windowUrl.query.src) {
36-
example = decodeURIComponent(windowUrl.query.src);
32+
var queryStringSrcStart = window.location.hash.indexOf("#src=");
33+
if (queryStringSrcStart == 0) {
34+
var encoded = window.location.hash.substring("#src=".length);
35+
example = decodeURIComponent(encoded);
3736
}
3837

3938
if (container && exampleLua) {
@@ -61,16 +60,25 @@ document.addEventListener('DOMContentLoaded', () => {
6160
tstlWorker.postMessage({tsStr: tsEditor.getValue()});
6261

6362
let timerVar: any;
63+
let ignoreHashChange = false;
6464

6565
tsEditor.onDidChangeModelContent((e => {
6666
clearInterval(timerVar);
6767
// wait one second before submitting work
6868
timerVar = setTimeout(() => {
6969
tstlWorker.postMessage({tsStr: tsEditor.getValue()});
70-
window.location.replace("?src=" + encodeURIComponent(tsEditor.getValue()));
70+
window.location.hash = "#src=" + encodeURIComponent(tsEditor.getValue());
71+
ignoreHashChange = true;
7172
}, 500);
7273
}))
7374

75+
window.onhashchange = () => {
76+
if (ignoreHashChange) {
77+
ignoreHashChange = false;
78+
return;
79+
}
80+
}
81+
7482
tstlWorker.onmessage = (event: MessageEvent) => {
7583
luaEditor.setValue(event.data.luaStr);
7684
}

0 commit comments

Comments
 (0)