Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] indent and unindent with tab completely impossible #363

Open
dtinhvo opened this issue Dec 30, 2024 · 5 comments
Open

[BUG] indent and unindent with tab completely impossible #363

dtinhvo opened this issue Dec 30, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@dtinhvo
Copy link

dtinhvo commented Dec 30, 2024

Description

When this plugin is enabled, tab to indent and shift-tab to indent in math block is completely impossible with no known alternative.

To Reproduce

Enable the plugin, type some math block. Now press tab with the math block content selected, individual lines selected, or at beginning of lines. Instead of indenting , cursor will just go to next tabstop

Expected Behavior

at least with a selection, tab should indent the line, or block - very few cases are exceptions to this behavior. I understand that tab stops and such might interfere, but since VISUAL is a feature in this plugin, tab and shift-tab should be given priority to this behavior. Or at least a toggle in settings. Current implementation of VISUAL also does not help me with an alternative, because line-wise addition is not supported (which will at least make a snippet for tab that indents).

@dtinhvo dtinhvo added the bug Something isn't working label Dec 30, 2024
@dtinhvo
Copy link
Author

dtinhvo commented Jan 1, 2025

Some other suggestions that is possible to achieve indentable math

  • add a command in Command Palette that disables tabout. After this I can select the equation block, press tab to indent each line, then turns on tabout again. The command can be something like this (I havent looked at the source code)
this.addCommand({
  id: 'toggle-tabout',
  name: 'Toggle Tabout',
  callback: async () => {
    this.settings.tabout = !this.settings.tabout;
    console.log(`Tabout is now ${this.settings.tabout ? 'enabled' : 'disabled'}`);
    await this.saveSettings();
  },
});
  • Command to indent or unindent a block code selection, similar to the "Box current equation"

@dtinhvo
Copy link
Author

dtinhvo commented Jan 2, 2025

For now, a workaround (that I use) is to exploit the visual function snippet function within obsidian-latex-suite itself:

    {trigger: "<", replacement: (sel) => {
        let lines = sel.split('\n');
        return lines.slice(0, -1).map(line => line.startsWith('    ') ? line.substring(4) : line) .concat(lines[lines.length - 1]) .join('\n');
    }, options: "mAv"},
    {trigger: ">", replacement: (sel) => {
        let lines = sel.split('\n');
        return lines.slice(0, -1) .map(line => '    ' + line) .concat(lines[lines.length - 1]) .join('\n');
    }, options: "mAv"},

This will match Obsidian's selection pattern when you click on a math block, and indent the content lines between 2 $$ with > and vice-versa with <
image
image

@superle3
Copy link

superle3 commented Jan 4, 2025

This seems more like a feature request than a bug report, but it is easily implemented by checking if something is selected in the tabout code.
Does this behaviour also need to work for matrix environments or should a & be inserted instead there?

And make it a setting or default behaviour?

@dtinhvo
Copy link
Author

dtinhvo commented Jan 4, 2025

I think this treads between a bug report and feature request, because the plugin is blocking the default Obsidian ability to indent lines, with no known built-in alternative.
Personally, I would not make tab insert a & if a selection is active - the location of insertion is ambiguous. This distinction also gives the tab key 2 modes of operation (with and without a selection) that is somewhat consistent with other editors (VSCode also indents the line on tab if you are selecting part of that line).
The above behavior can be default, but needs modification to not interfere with tabstops. I don't know how tabstops is implemented, but some possible suggestions:

  • if the next tabstop is "unused" then it will take priority to go to the next tabstop. Then, delete the tabstop we have just gone to ("use" it)
  • if the selection is the entire math block, like how obsidian defaults to if you click on the math render (see above comment) then indent take highest priority. Currently, such a selection + pressing tab will deselect the math block and move the cursor outside the mathblock which imo makes no sense.
  • Add Shift-Tab to unindent
    If the above is tricky to implement, we can make Ctrl+Tab to indent and Ctrl-Shift-Tab to unindent, removing any ambiguity with tabstops and align's & insert. The setting switch can be then swapping behavior of (Shift-)Tab and Ctrl-(Shift-)Tab,

@superle3
Copy link

superle3 commented Jan 4, 2025

The hard part is multicursor, but its so obscure that I don't think its worth bothering
Also Shift-Tab should work since the plugin is only overwriting the behaviour of tab if a condition is met like a matrix environment, otherwise the normal behaviour of obsidian goes through.
This should not interfere with tabstops since I didn't touch that code and since that is checked earlier then the tabout and matrix code.

And looking back, this does not make sense as a toggle-able setting so it's permanent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants