Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerijo committed Feb 22, 2019
1 parent bc084b5 commit 96d8a7c
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ function getFoldableRangesAtIndentLevel ({level, editor}, startRow=0, endRow=-1,
if (endRow < 0) endRow = editor.getLineCount();

for (let row = startRow; row < endRow; row++) {
if (!isFoldableAtRow(row, editor)) continue;
if (!isFoldableAtRow({row, editor})) continue;

const range = getFoldableRangeContainingPoint({row: row, column: Infinity}, editor);
const range = getFoldableRangeContainingPoint({point: {row: row, column: Infinity}, editor});
if (range === null) continue;

if (level > 0) {
getFoldableRangesAtIndentLevel(level - 1, editor, range.start.row + 1, range.end.row, ranges);
getFoldableRangesAtIndentLevel({level: level - 1, editor}, range.start.row + 1, range.end.row, ranges);
} else {
ranges.push(range);
}
Expand Down Expand Up @@ -72,10 +72,10 @@ function getFoldableRangeContainingPoint ({point, editor}) {
}

if (!range) return null;
return range.start.row === range.end.row ? null : range;
return range.start.row >= range.end.row ? null : range;
}

function getPreambleRange(editor, row) {
function getPreambleRange (editor, row) {
let startPoint = new Point(row, editor.buffer.lineLengthForRow(row));
let endPoint = null;

Expand All @@ -97,7 +97,7 @@ function getPreambleRange(editor, row) {
return new Range(startPoint, endPoint);
}

function getSectionRange(editor, row, sectionType) {
function getSectionRange (editor, row, sectionType) {
let line = editor.lineTextForBufferRow(row);
let sectionMatch = line.match(/^[ \t]*(?:\\((?:sub){0,2}section|chapter|part|(?:sub)?paragraph)\s*\*?\s*(\[.*?\])?\{([^\}]*\})?)/);

Expand Down Expand Up @@ -142,34 +142,33 @@ function getSectionRange(editor, row, sectionType) {
stop();
});

if (!matchFound) {
return sectionRange = new Range(startPoint, endPosition);
if (matchFound) {
sectionRange = new Range(startPoint, nextSectionCommandRange.start.translate(new Point(-1, Infinity)));
} else {
sectionRange = new Range(startPoint, endPosition);
}

sectionRange = new Range(startPoint, nextSectionCommandRange.start.translate(new Point(-1, Infinity)));

if (!atom.config.get("latex-folding.foldTrailingSectionWhitespace")) {
translateEndRowToLastNonWhitespaceLine(sectionRange, editor);
}

if (sectionRange.start.row >= sectionRange.end.row) return null;

return sectionRange;
return sectionRange.start.row >= sectionRange.end.row ? null : sectionRange;
}

function translateEndRowToLastNonWhitespaceLine (range, editor) {
for (let i = range.end.row; i > range.start.row; i--) {
const line = editor.lineTextForBufferRow(i);
if (/\S/.test(line)) {
range.end.row = i;
range.end.column = Infinity;
return;
};
}

range.end = range.start; // makes it invalid as a fold
}

function getEnvRange(editor, row, lenientEnvNames=false) {
function getEnvRange (editor, row, lenientEnvNames=false) {
let line = editor.lineTextForBufferRow(row);
let envMatch = line.match(/^[ \t]*\\begin\s*\{(.*?)\}/);
if (envMatch === null) {
Expand Down Expand Up @@ -213,7 +212,7 @@ function getEnvRange(editor, row, lenientEnvNames=false) {
return new Range(startPoint, endDelimRange.start);
}

function isCommented(scopesArray) {
function isCommented (scopesArray) {
for (let scope of scopesArray) {
if (scope.startsWith("comment")) { return true; }
}
Expand Down

0 comments on commit 96d8a7c

Please sign in to comment.