mirror of https://github.com/shadowfacts/type.git
Skip empty lines
This commit is contained in:
parent
a1d3c35de6
commit
b8fc2b29f8
56
main.js
56
main.js
|
@ -6,7 +6,8 @@ let invalids = [];
|
||||||
|
|
||||||
let extensions = {
|
let extensions = {
|
||||||
js: "javascript",
|
js: "javascript",
|
||||||
kt: "kotlin"
|
kt: "kotlin",
|
||||||
|
md: "markdown"
|
||||||
};
|
};
|
||||||
|
|
||||||
// fetch file and setup
|
// fetch file and setup
|
||||||
|
@ -120,10 +121,22 @@ function setup(data, mode) {
|
||||||
let currentLine = editor.doc.getLine(pos.line);
|
let currentLine = editor.doc.getLine(pos.line);
|
||||||
let trimmed = currentLine.trim();
|
let trimmed = currentLine.trim();
|
||||||
if (editor.getCursor().ch >= currentLine.indexOf(trimmed) + trimmed.length) {
|
if (editor.getCursor().ch >= currentLine.indexOf(trimmed) + trimmed.length) {
|
||||||
let newLine = pos.line + 1;
|
var newLine = pos.line;
|
||||||
let text = editor.doc.getLine(newLine);
|
while (true) {
|
||||||
let ch = text.indexOf(text.trim());
|
newLine++;
|
||||||
editor.setCursor({ line: newLine, ch: ch });
|
if (newLine >= editor.doc.size) { // go to end of last line
|
||||||
|
editor.setCursor(getEndPos());
|
||||||
|
break;
|
||||||
|
} else { // try go to next line
|
||||||
|
let newText = editor.doc.getLine(newLine);
|
||||||
|
let newTrimmed = newText.trim();
|
||||||
|
if (newTrimmed.length != 0) { // line is not empty (whitespace-only)
|
||||||
|
let ch = newText.indexOf(newTrimmed);
|
||||||
|
editor.setCursor({ line: newLine, ch: ch });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
updateIncompleteMark();
|
updateIncompleteMark();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,17 +152,25 @@ function setup(data, mode) {
|
||||||
function moveToEndOfPreviousLine() {
|
function moveToEndOfPreviousLine() {
|
||||||
let pos = editor.getCursor();
|
let pos = editor.getCursor();
|
||||||
if (pos.line > 0) {
|
if (pos.line > 0) {
|
||||||
let newLine = pos.line - 1;
|
var newLine = pos.line;
|
||||||
let text = editor.doc.getLine(newLine);
|
while (true) {
|
||||||
let trimmed = text.trim();
|
newLine--;
|
||||||
let ch = text.indexOf(trimmed) + trimmed.length;
|
let text = editor.doc.getLine(newLine);
|
||||||
editor.setCursor({ line: newLine, ch: ch });
|
let trimmed = text.trim();
|
||||||
|
if (trimmed.length != 0) {
|
||||||
|
let ch = text.indexOf(trimmed) + trimmed.length;
|
||||||
|
editor.setCursor({ line: newLine, ch: ch });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isComplete() {
|
function isComplete() {
|
||||||
if (incompleteMark.lines.length != 0) {
|
if (!areAllNextLinesEmpty()) {
|
||||||
return false;
|
if (incompleteMark.lines.length != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < invalids.length; i++) {
|
for (var i = 0; i < invalids.length; i++) {
|
||||||
|
@ -165,6 +186,17 @@ function isComplete() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function areAllNextLinesEmpty() {
|
||||||
|
let pos = editor.getCursor();
|
||||||
|
for (var i = pos.line + 1; i < editor.doc.size; i++) {
|
||||||
|
let line = editor.doc.getLine(i);
|
||||||
|
if (line.trim().length != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function getEndPos() {
|
function getEndPos() {
|
||||||
return { line: editor.doc.size, ch: editor.doc.getLine(editor.doc.size - 1).length };
|
return { line: editor.doc.size, ch: editor.doc.getLine(editor.doc.size - 1).length };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue