mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 07:28:08 +03:00
Leave muli-character fold end tokens on their own line
Signed-off-by: Nathan Sobo <nathan@github.com>
This commit is contained in:
parent
264de98d92
commit
136dc86584
@ -186,7 +186,8 @@ describe('TreeSitterLanguageMode', () => {
|
||||
expect(getDisplayText(editor)).toBe(dedent `
|
||||
const element1 = <Element…/>
|
||||
|
||||
const element2 = <Element>…</Element>
|
||||
const element2 = <Element>…
|
||||
</Element>
|
||||
`)
|
||||
})
|
||||
|
||||
@ -239,10 +240,15 @@ describe('TreeSitterLanguageMode', () => {
|
||||
folds: [
|
||||
// If the #ifdef has an `#else` clause, then end the fold there.
|
||||
{
|
||||
type: 'preproc_ifdef',
|
||||
type: ['preproc_ifdef', 'preproc_elif'],
|
||||
start: {index: 1},
|
||||
end: {type: 'preproc_else'}
|
||||
},
|
||||
{
|
||||
type: ['preproc_ifdef', 'preproc_elif'],
|
||||
start: {index: 1},
|
||||
end: {type: 'preproc_elif'}
|
||||
},
|
||||
|
||||
// Otherwise, end the fold at the last child - the `#endif`.
|
||||
{
|
||||
@ -270,6 +276,11 @@ describe('TreeSitterLanguageMode', () => {
|
||||
#include <windows.h>
|
||||
const char *path_separator = "\\";
|
||||
|
||||
#elif defined MACOS
|
||||
|
||||
#include <carbon.h>
|
||||
const char *path_separator = "/";
|
||||
|
||||
#else
|
||||
|
||||
#include <dirent.h>
|
||||
@ -287,7 +298,13 @@ describe('TreeSitterLanguageMode', () => {
|
||||
#ifndef FOO_H_
|
||||
#define FOO_H_
|
||||
|
||||
#ifdef _WIN32…#else
|
||||
#ifdef _WIN32…
|
||||
#elif defined MACOS
|
||||
|
||||
#include <carbon.h>
|
||||
const char *path_separator = "/";
|
||||
|
||||
#else
|
||||
|
||||
#include <dirent.h>
|
||||
const char *path_separator = "/";
|
||||
@ -302,7 +319,12 @@ describe('TreeSitterLanguageMode', () => {
|
||||
#ifndef FOO_H_
|
||||
#define FOO_H_
|
||||
|
||||
#ifdef _WIN32…#else…
|
||||
#ifdef _WIN32…
|
||||
#elif defined MACOS…
|
||||
#else
|
||||
|
||||
#include <dirent.h>
|
||||
const char *path_separator = "/";
|
||||
|
||||
#endif
|
||||
|
||||
@ -311,7 +333,8 @@ describe('TreeSitterLanguageMode', () => {
|
||||
|
||||
editor.foldBufferRow(0)
|
||||
expect(getDisplayText(editor)).toBe(dedent `
|
||||
#ifndef FOO_H_…#endif
|
||||
#ifndef FOO_H_…
|
||||
#endif
|
||||
`)
|
||||
})
|
||||
|
||||
|
@ -221,16 +221,22 @@ class TreeSitterLanguageMode {
|
||||
let foldEnd
|
||||
const endEntry = foldEntry.end
|
||||
if (endEntry) {
|
||||
let foldEndNode
|
||||
if (endEntry.index != null) {
|
||||
const index = endEntry.index < 0 ? childCount + endEntry.index : endEntry.index
|
||||
const child = children[index]
|
||||
if (!child || (endEntry.type && endEntry.type !== child.type)) continue
|
||||
foldEnd = child.startPosition
|
||||
foldEndNode = children[index]
|
||||
if (!foldEndNode || (endEntry.type && endEntry.type !== foldEndNode.type)) continue
|
||||
} else {
|
||||
if (!childTypes) childTypes = children.map(child => child.type)
|
||||
if (!childTypes) childTypes = children.map(foldEndNode => foldEndNode.type)
|
||||
const index = childTypes.lastIndexOf(endEntry.type)
|
||||
if (index === -1) continue
|
||||
foldEnd = children[index].startPosition
|
||||
foldEndNode = children[index]
|
||||
}
|
||||
|
||||
if (foldEndNode.endIndex - foldEndNode.startIndex > 1 && foldEndNode.startPosition.row > foldStart.row) {
|
||||
foldEnd = new Point(foldEndNode.startPosition.row - 1, Infinity)
|
||||
} else {
|
||||
foldEnd = foldEndNode.startPosition
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user