artisticat1 / obsidian-latex-suite

Make typesetting LaTeX as fast as handwriting through snippets, text expansion, and editor enhancements
MIT License
1.28k stars 52 forks source link

Backspace functionality to delete both $ in empty inline math #285

Closed bdm-k closed 3 months ago

bdm-k commented 5 months ago

Closes #266

If the implementation looks good, I'd like to proceed with the next steps, such as:

artisticat1 commented 5 months ago

Implementation looks fine to me!

I am not sure if this is necessary, but perhaps we should clear all tabstops when this effect is triggered.

bdm-k commented 5 months ago

Do you mean calling removeAllTabstops, which is defined in "tabstops_state_field.ts"?

artisticat1 commented 5 months ago

Yeah, exactly.

bdm-k commented 5 months ago

Could you tell me specifically what other changes I should make?

artisticat1 commented 5 months ago

I'm happy to merge after this is done:

  • making this feature toggleable
  • organizing the code into a new file
bdm-k commented 5 months ago

I'm having second thoughts. Isn't it a bit excessive to create a new file since there are only a few lines of code?

artisticat1 commented 5 months ago

Actually, can we check whether context.mode.inlineMath is true instead of looking for $ symbols? This would be more semantic as well as robust.

I'm having second thoughts. Isn't it a bit excessive to create a new file since there are only a few lines of code?

That's true; it would be nice for consistency with the other functions/features though. I'll leave it up to you.

bdm-k commented 4 months ago

Actually, can we check whether context.mode.inlineMath is true instead of looking for $ symbols? This would be more semantic as well as robust.

In the case of $|$, context.mode.inlineMath will be false. So, we can't determine whether the cursor is inside an empty inline math or entirely outside of an inline math.

artisticat1 commented 4 months ago

Oh, that sounds like unintended behaviour - I'll try to look into it.

bdm-k commented 3 months ago

When the text is $$, the syntax tree will be:

Document [1:0..1:2]
   └─ formatting_formatting-math_formatting-math-begin_keyword_math_math-block [1:0..1:2]: "$$"

On the other hand, when the text is $x$, the syntax tree will be:

Document [1:0..1:3]
   ├─ formatting_formatting-math_formatting-math-begin_keyword_math [1:0..1:1]: "$"
   ├─ math_variable-2 [1:1..1:2]: "x"
   └─ formatting_formatting-math_formatting-math-end_keyword_math_math- [1:2..1:3]: "$"

In the first case, no node contains "math-end" in its name, so context.mode.inlineMath will be false. Therefore, we must directly look for $ symbols.

artisticat1 commented 3 months ago

Okay, I'll go ahead and merge this then. Thank you!