Don't automatically hide singleton nodes

This commit is contained in:
Max Brunsfeld 2015-09-02 16:36:29 -07:00
parent acf9280eda
commit 53926c467e
21 changed files with 4284 additions and 4221 deletions

View file

@ -63,8 +63,8 @@ void ts_document_set_input_string(TSDocument *document, const char *text) {
}
TSNode ts_document_root_node(const TSDocument *document) {
TSTree *tree = document->tree;
while (tree && ts_tree_is_singleton(tree))
tree = tree->children[0];
return ts_node_make(tree, ts_length_zero());
TSNode result = ts_node_make(document->tree, ts_length_zero());
while (result.data && !ts_tree_is_visible(result.data))
result = ts_node_child(result, 0);
return result;
}

View file

@ -67,9 +67,6 @@ TSTree *ts_tree_make_node(TSSymbol symbol, size_t child_count,
} else {
if (is_hidden)
options |= TSTreeOptionsHidden;
if (child_count == 1 &&
(ts_tree_is_visible(children[0]) || ts_tree_is_singleton(children[0])))
options |= (TSTreeOptionsSingleton | TSTreeOptionsHidden);
if (child_count > 0) {
if (ts_tree_is_fragile_left(children[0]))
options |= (TSTreeOptionsFragileLeft);
@ -207,7 +204,6 @@ void ts_tree_prepend_children(TSTree *tree, size_t count, TSTree **children) {
tree->child_count * sizeof(TSTree *));
free(tree->children);
ts_tree_unset_singleton(tree);
tree->children = new_children;
tree->visible_child_count += visible_count;
tree->child_count += count;

View file

@ -11,9 +11,8 @@ extern "C" {
typedef enum {
TSTreeOptionsHidden = 1 << 0,
TSTreeOptionsExtra = 1 << 1,
TSTreeOptionsSingleton = 1 << 2,
TSTreeOptionsFragileLeft = 1 << 3,
TSTreeOptionsFragileRight = 1 << 4,
TSTreeOptionsFragileLeft = 1 << 2,
TSTreeOptionsFragileRight = 1 << 3,
} TSTreeOptions;
struct TSTree {
@ -47,14 +46,6 @@ static inline bool ts_tree_is_visible(const TSTree *tree) {
return !(tree->options & TSTreeOptionsHidden);
}
static inline bool ts_tree_is_singleton(const TSTree *tree) {
return !!(tree->options & TSTreeOptionsSingleton);
}
static inline void ts_tree_unset_singleton(TSTree *tree) {
tree->options = (TSTreeOptions)(tree->options & ~TSTreeOptionsSingleton);
}
static inline void ts_tree_set_options(TSTree *tree, TSTreeOptions options) {
tree->options = (TSTreeOptions)(tree->options | options);
}