Skip to content

Commit a7e07fa

Browse files
fix: equation code action is broken since v0.13 (#1561)
Todo: discuss the correct behavior on `$ | $` and `$ |$` where `|` are the cursors.
1 parent 2ba7935 commit a7e07fa

42 files changed

Lines changed: 682 additions & 29 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/tinymist-query/src/analysis/code_action.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,25 @@ impl<'a> CodeActionWorker<'a> {
488488
Some(())
489489
}
490490

491+
/// Whether the equation should be displayed as a separate block.
492+
fn math_is_block(equation: ast::Equation) -> bool {
493+
let is_space =
494+
|node: Option<&SyntaxNode>| node.map(SyntaxNode::kind) == Some(SyntaxKind::Space);
495+
let eq = equation.to_untyped();
496+
497+
let mut nodes = eq.children().skip(1);
498+
let mut first = nodes.next();
499+
if first.is_some_and(|first| first.is_empty() && matches!(first.kind(), SyntaxKind::Math)) {
500+
first = nodes.next();
501+
}
502+
503+
is_space(first) && is_space(eq.children().nth_back(1))
504+
}
505+
491506
fn equation_actions(&mut self, node: &LinkedNode) -> Option<()> {
492507
let equation = node.cast::<ast::Equation>()?;
493508
let body = equation.body();
494-
let is_block = equation.block();
509+
let is_block = Self::math_is_block(equation);
495510

496511
let body = node.find(body.span())?;
497512
let body_range = body.range();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ $/* range -1..-1 */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ $/* range -1..-1 */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ a $/* range -1..-1 */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ a $/* range -2..-2 */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ a $/* range -4..-4 */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ a $/* range -5..-5 */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$
2+
a
3+
$/* range -1..-1 */
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
$
2+
$/* range -1..-1 */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ a $. /* range -4..-4 */

0 commit comments

Comments
 (0)