mirror of https://github.com/shadowfacts/type.git
Automatically go to the previous chunk
This commit is contained in:
parent
02e0ff39d9
commit
abb31139ab
39
js/main.js
39
js/main.js
|
@ -191,11 +191,16 @@ function moveToEndOfPreviousLine() {
|
||||||
var newLine = pos.line;
|
var newLine = pos.line;
|
||||||
while (true) {
|
while (true) {
|
||||||
newLine--;
|
newLine--;
|
||||||
|
if (newLine < 0) {
|
||||||
|
setCursor({ line: 0, ch: 0 });
|
||||||
|
break;
|
||||||
|
}
|
||||||
let text = editor.doc.getLine(newLine);
|
let text = editor.doc.getLine(newLine);
|
||||||
let trimmed = text.trim();
|
let trimmed = text.trim();
|
||||||
if (trimmed.length != 0) {
|
if (trimmed.length != 0) {
|
||||||
let ch = text.indexOf(trimmed) + trimmed.length;
|
let ch = text.indexOf(trimmed) + trimmed.length;
|
||||||
setCursor({ line: newLine, ch: ch });
|
setCursor({ line: newLine, ch: ch });
|
||||||
|
save();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,7 +297,9 @@ function getChunk(code) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function completeChunk() {
|
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(() => {
|
setTimeout(() => {
|
||||||
localforage.getItem(repo)
|
localforage.getItem(repo)
|
||||||
|
@ -317,10 +324,34 @@ function completeChunk() {
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 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() {
|
||||||
return localforage.getItem(repo)
|
return localforage.getItem(repo)
|
||||||
.then((val) => {
|
.then((val) => {
|
||||||
|
@ -418,7 +449,9 @@ function setCursor(pos) {
|
||||||
editor.setCursor(pos);
|
editor.setCursor(pos);
|
||||||
let end = getEndPos();
|
let end = getEndPos();
|
||||||
if (pos.line == end.line && pos.ch == end.ch) {
|
if (pos.line == end.line && pos.ch == end.ch) {
|
||||||
completeChunk();
|
goToNextChunk();
|
||||||
|
} else if (pos.line == 0 && pos.ch == 0) {
|
||||||
|
goToPrevChunk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue