mirror of https://github.com/shadowfacts/type.git
More misc fixes
This commit is contained in:
parent
3bd0e584dc
commit
5ddf1145f4
79
js/main.js
79
js/main.js
|
@ -246,24 +246,24 @@ function areAllNextLinesEmpty() {
|
||||||
function getStartPos() {
|
function getStartPos() {
|
||||||
var line = 0;
|
var line = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
line++;
|
|
||||||
let text = editor.doc.getLine(line);
|
let text = editor.doc.getLine(line);
|
||||||
let trimmed = text.trim();
|
let trimmed = text.trim();
|
||||||
if (trimmed.length != 0) {
|
if (trimmed.length != 0) {
|
||||||
return { line: line, ch: text.indexOf(trimmed) };
|
return { line: line, ch: text.indexOf(trimmed) };
|
||||||
}
|
}
|
||||||
|
line++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEndPos() {
|
function getEndPos() {
|
||||||
var line = editor.doc.size - 1;
|
var line = editor.doc.size - 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
line--;
|
|
||||||
let text = editor.doc.getLine(line);
|
let text = editor.doc.getLine(line);
|
||||||
let trimmed = text.trim();
|
let trimmed = text.trim();
|
||||||
if (trimmed.length != 0) {
|
if (trimmed.length != 0) {
|
||||||
return { line: line, ch: text.indexOf(trimmed) + trimmed.length };
|
return { line: line, ch: text.indexOf(trimmed) + trimmed.length };
|
||||||
}
|
}
|
||||||
|
line--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ function getChunk(code) {
|
||||||
if (chunk == totalChunks - 1) {
|
if (chunk == totalChunks - 1) {
|
||||||
return lines.slice(totalChunks - (lines.length % 50), lines.length);
|
return lines.slice(totalChunks - (lines.length % 50), lines.length);
|
||||||
} else {
|
} else {
|
||||||
return lines.slice(chunk * 50, (chunk + 1) * 50 + 1);
|
return lines.slice(chunk * 50, (chunk + 1) * 50);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!val) val = {};
|
if (!val) val = {};
|
||||||
|
@ -323,16 +323,42 @@ function getChunk(code) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function goToNextChunk() {
|
function goToNextChunk() {
|
||||||
// slight delay is required b/c asynchronous shit
|
|
||||||
// setTimeout makes the updated chunk to be set after the save() call
|
|
||||||
if (isComplete()) {
|
if (isComplete()) {
|
||||||
setTimeout(() => {
|
save()
|
||||||
|
.then(() => {
|
||||||
|
localforage.getItem(repo)
|
||||||
|
.then((val) => {
|
||||||
|
let nextChunk = val[filePath].chunk + 1;
|
||||||
|
let totalChunks = Math.ceil(fileLines.length / 50);
|
||||||
|
if (nextChunk < totalChunks) { // not the last chunk
|
||||||
|
val[filePath].chunk = nextChunk;
|
||||||
|
localforage.setItem(repo, val)
|
||||||
|
.then(() => {
|
||||||
|
window.location.reload();
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
let hash = window.location.hash;
|
||||||
|
window.location.href = `/complete.html${hash}`;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function goToPrevChunk() {
|
||||||
|
save()
|
||||||
|
.then(() => {
|
||||||
localforage.getItem(repo)
|
localforage.getItem(repo)
|
||||||
.then((val) => {
|
.then((val) => {
|
||||||
let nextChunk = val[filePath].chunk + 1;
|
let prevChunk = val[filePath].chunk - 1;
|
||||||
let totalChunks = Math.ceil(fileLines.length / 50);
|
if (prevChunk >= 0) {
|
||||||
if (nextChunk < totalChunks) { // not the last chunk
|
val[filePath].chunk = prevChunk;
|
||||||
val[filePath].chunk = nextChunk;
|
|
||||||
localforage.setItem(repo, val)
|
localforage.setItem(repo, val)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
@ -340,41 +366,12 @@ function goToNextChunk() {
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// TODO: show completion screen
|
|
||||||
let hash = window.location.hash;
|
|
||||||
window.location.href = `/complete.html${hash}`;
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}, 50);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function goToPrevChunk() {
|
|
||||||
// slight delay is required b/c asynchronous shit
|
|
||||||
// setTimeout makes the updated chunk to be set after the save() call
|
|
||||||
setTimeout(() => {
|
|
||||||
localforage.getItem(repo)
|
|
||||||
.then((val) => {
|
|
||||||
let prevChunk = val[filePath].chunk - 1;
|
|
||||||
if (prevChunk >= 0) {
|
|
||||||
val[filePath].chunk = prevChunk;
|
|
||||||
localforage.setItem(repo, val)
|
|
||||||
.then(() => {
|
|
||||||
window.location.reload();
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
throw e;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
throw e;
|
|
||||||
});
|
|
||||||
}, 50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
|
@ -394,7 +391,7 @@ function load() {
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
localforage.setItem("theme", saveTheme());
|
localforage.setItem("theme", saveTheme());
|
||||||
localforage.getItem(repo)
|
return localforage.getItem(repo)
|
||||||
.then((val) => {
|
.then((val) => {
|
||||||
if (!val) val = {};
|
if (!val) val = {};
|
||||||
if (!val[filePath]) val[filePath] = {};
|
if (!val[filePath]) val[filePath] = {};
|
||||||
|
|
Loading…
Reference in New Issue