Skip to content

Commit

Permalink
Make divided folds end at the end of the preceding line much more often
Browse files Browse the repository at this point in the history
  • Loading branch information
savetheclocktower committed Mar 3, 2024
1 parent 89d410b commit ab6f081
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/wasm-tree-sitter-language-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2388,13 +2388,21 @@ class FoldResolver {
}
}

// Returns `true` if there is no non-whitespace content on this position's
// row before this position's column.
positionIsNotPrecededByTextOnLine(position) {
let textForRow = this.buffer.lineForRow(position.row)
let precedingText = textForRow.substring(0, position.column)
return !(/\S/.test(precedingText))
}

resolvePositionForDividedFold(capture) {
let { name, node } = capture;
if (name === 'fold.start') {
return new Point(node.startPosition.row, Infinity);
} else if (name === 'fold.end') {
let end = node.startPosition;
if (end.column === 0) {
if (end.column === 0 || this.positionIsNotPrecededByTextOnLine(end)) {
// If the fold ends at the start of the line, adjust it so that it
// actually ends at the end of the previous line. This behavior is
// implied in the existing specs.
Expand Down

0 comments on commit ab6f081

Please sign in to comment.