mirror of https://github.com/shadowfacts/type.git
Clean up stuff
This commit is contained in:
parent
821edca54c
commit
c789240a26
64
main.js
64
main.js
|
@ -52,19 +52,33 @@ function setup(data, mime) {
|
|||
|
||||
focused = true;
|
||||
|
||||
editor.on("focus", (instance, event) => {
|
||||
focused = true;
|
||||
});
|
||||
editor.on("blur", (instance, event) => {
|
||||
focused = false;
|
||||
});
|
||||
editor.on("focus", handleFocus);
|
||||
editor.on("blur", handleBlur);
|
||||
editor.on("mousedown", handleMouseDown);
|
||||
|
||||
editor.on("mousedown", (instance, event) => {
|
||||
document.addEventListener("keypress", handleKeyPress);
|
||||
document.addEventListener("keydown", handleKeyDown);
|
||||
|
||||
})
|
||||
.catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
function handleFocus() {
|
||||
focused = true;
|
||||
}
|
||||
|
||||
function handleBlur() {
|
||||
focused = false;
|
||||
}
|
||||
|
||||
function handleMouseDown(instance, event) {
|
||||
event.preventDefault();
|
||||
editor.focus();
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("keypress", (event) => {
|
||||
function handleKeyPress(event) {
|
||||
if (focused) {
|
||||
event.preventDefault();
|
||||
|
||||
|
@ -77,15 +91,21 @@ function setup(data, mime) {
|
|||
editor.setCursor({ line: pos.line, ch: pos.ch + 1 });
|
||||
updateIncompleteMark();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("keydown", (event) => {
|
||||
function handleKeyDown(event) {
|
||||
if (focused) {
|
||||
var result = false;
|
||||
|
||||
if (event.keyCode == 8) { // delete
|
||||
result = true;
|
||||
event.preventDefault();
|
||||
handleDelete(event);
|
||||
} else if (event.keyCode == 13) { // enter
|
||||
event.preventDefault();
|
||||
handleEnter(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleDelete(event) {
|
||||
let pos = editor.getCursor();
|
||||
if (pos.ch == 0) { // move up 1 line {
|
||||
moveToEndOfPreviousLine();
|
||||
|
@ -109,9 +129,9 @@ function setup(data, mime) {
|
|||
}
|
||||
|
||||
updateIncompleteMark();
|
||||
} else if (event.keyCode == 13) { // enter
|
||||
result = true;
|
||||
}
|
||||
|
||||
function handleEnter(event) {
|
||||
let pos = editor.getCursor();
|
||||
if (pos.line != editor.doc.size - 1) {
|
||||
let currentLine = editor.doc.getLine(pos.line);
|
||||
|
@ -136,18 +156,6 @@ function setup(data, mime) {
|
|||
updateIncompleteMark();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
.catch((e) => {
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
function moveToEndOfPreviousLine() {
|
||||
|
|
Loading…
Reference in New Issue