on master help sign in
Slightly change the behavior of the `@stop-extend` capture.
dc44348Daniel Ebert
book/src/guides/indent.md+5−4
@@ -54,10 +54,11 @@ for languages like Python, where for the purpose of indentation some nodes
54
54
55- `@stop-extend`:
55- `@stop-extend`:
56Prevents the first extension of an ancestor of this node. For example, in Python
56Prevents the first extension of an ancestor of this node. For example, in Python
57−a return expression always ends the block that it is in. Note that this only prevents
57+a return expression always ends the block that it is in. Note that this only stops the
58−the next extension of one ancestor: If multiple ancestors can be extended (for example
58+extension of the next `@extend-indented` capture. If multiple ancestors are captured,
59−multiple nested conditional blocks in python), only the extension of the innermost
59+only the extension of the innermost one is prevented. All other ancestors are unaffected
60−ancestor is prevented.
60+(regardless of whether the innermost ancestor would actually have been extended).
61+
61
62
62## Predicates
63## Predicates
63
64
helix-core/src/indent.rs+11−10
@@ -471,6 +471,10 @@ fn extend_nodes<'a>(
471 let mut stop_extend = false;
471 let mut stop_extend = false;
472 while deepest_preceding != *node {
472 while deepest_preceding != *node {
473 let mut extend_node = false;
473 let mut extend_node = false;
474+ // This will be set to true if this node is captured, regardless of whether
475+ // it actually will be extended (e.g. because the cursor isn't indented
476+ // more than the node).
477+ let mut node_captured = false;
474 if let Some(captures) = extend_captures.get(&deepest_preceding.id()) {
478 if let Some(captures) = extend_captures.get(&deepest_preceding.id()) {
475 for capture in captures {
479 for capture in captures {
476 match capture {
480 match capture {
@@ -478,6 +482,7 @@ fn extend_nodes<'a>(
478 stop_extend = true;
482 stop_extend = true;
479 }
483 }
480 ExtendCapture::ExtendIndented => {
484 ExtendCapture::ExtendIndented => {
485+ node_captured = true;
481 // We extend the node if
486 // We extend the node if
482 // - the cursor is on the same line as the end of the node OR
487 // - the cursor is on the same line as the end of the node OR
483 // - the line that the cursor is on is more indented than the
488 // - the line that the cursor is on is more indented than the
@@ -501,16 +506,12 @@ fn extend_nodes<'a>(
501 }
506 }
502 // If we encountered some `StopExtend` capture before, we don't
507 // If we encountered some `StopExtend` capture before, we don't
503 // extend the node even if we otherwise would
508 // extend the node even if we otherwise would
509+ if node_captured && stop_extend {
510+ stop_extend = false;
504− match (extend_node, stop_extend) {
511+ } else if extend_node && !stop_extend {
505− (true, true) => {
506− stop_extend = false;
507− }
508− (true, false) => {
509− *node = deepest_preceding;
512+ *node = deepest_preceding;
510− break;
513+ break;
511− }
512− _ => {}
513− };
514+ }
514 // This parent always exists since node is an ancestor of deepest_preceding
515 // This parent always exists since node is an ancestor of deepest_preceding
515 deepest_preceding = deepest_preceding.parent().unwrap();
516 deepest_preceding = deepest_preceding.parent().unwrap();
516 }
517 }