mirror of https://github.com/shadowfacts/type.git
Save cursor position
This commit is contained in:
parent
b62ac18656
commit
4a0315d927
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<script src="codemirror/codemirror.js"></script>
|
<script src="codemirror/codemirror.js"></script>
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/localforage/1.4.2/localforage.min.js"></script>
|
||||||
<script src="languages.js"></script>
|
<script src="languages.js"></script>
|
||||||
<script src="main.js"></script>
|
<script src="main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
47
main.js
47
main.js
|
@ -5,11 +5,14 @@ var focused = false;
|
||||||
let invalids = [];
|
let invalids = [];
|
||||||
|
|
||||||
// fetch file and setup
|
// fetch file and setup
|
||||||
let file = window.location.hash.substring(1);
|
let hash = window.location.hash.substring(1);
|
||||||
|
let hashBits = hash.split("/");
|
||||||
|
let repo = hashBits.slice(0, 3).join("/");
|
||||||
|
let filePath = hashBits.slice(3, hashBits.length).join("/");
|
||||||
$.get({
|
$.get({
|
||||||
url: `https://raw.githubusercontent.com/${file}`,
|
url: `https://raw.githubusercontent.com/${repo}/${filePath}`,
|
||||||
success: (code) => {
|
success: (code) => {
|
||||||
let parts = file.split(".");
|
let parts = filePath.split(".");
|
||||||
let fileExtension = parts[parts.length - 1];
|
let fileExtension = parts[parts.length - 1];
|
||||||
let lang = getLanguageByExtension(fileExtension);
|
let lang = getLanguageByExtension(fileExtension);
|
||||||
$.get({
|
$.get({
|
||||||
|
@ -40,7 +43,19 @@ function setup(data, mime) {
|
||||||
|
|
||||||
editor.setSize("100%", "100%");
|
editor.setSize("100%", "100%");
|
||||||
|
|
||||||
incompleteMark = editor.doc.markText({ line: 0, ch: 0 }, getEndPos(), {
|
localforage.getItem(repo)
|
||||||
|
.then((val) => {
|
||||||
|
var startPos; // the initial position of the cursor
|
||||||
|
if (val && val[filePath] && val[filePath].pos) {
|
||||||
|
startPos = val[filePath].pos;
|
||||||
|
} else {
|
||||||
|
startPos = { line: 0, ch: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
saveCursor();
|
||||||
|
editor.setCursor(startPos);
|
||||||
|
|
||||||
|
incompleteMark = editor.doc.markText(editor.getCursor(), getEndPos(), {
|
||||||
className: "incomplete"
|
className: "incomplete"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -141,6 +156,11 @@ function setup(data, mime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function moveToEndOfPreviousLine() {
|
function moveToEndOfPreviousLine() {
|
||||||
|
@ -202,6 +222,25 @@ function updateIncompleteMark() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveCursor() {
|
||||||
|
localforage.getItem(repo)
|
||||||
|
.then((val) => {
|
||||||
|
if (!val) val = {};
|
||||||
|
|
||||||
|
val[filePath] = {
|
||||||
|
pos: editor.getCursor()
|
||||||
|
};
|
||||||
|
localforage.setItem(repo, val)
|
||||||
|
.catch((e) => {
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
setTimeout(saveCursor, 15000);
|
||||||
|
}
|
||||||
|
|
||||||
String.prototype.hasOnlyWhiteSpaceBeforeIndex = function(index) {
|
String.prototype.hasOnlyWhiteSpaceBeforeIndex = function(index) {
|
||||||
return this.substring(index) == this.trim();
|
return this.substring(index) == this.trim();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue