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

Enhance matrixShortcuts: Optional whitespace trimming & multi-selection support #391

Conversation

Testudinidae
Copy link
Contributor

@Testudinidae Testudinidae commented Feb 13, 2025

Summary

This PR adds an optional whitespace trimming feature to matrixShortcuts.

Changes

  • New setting: matrixShortcutsTrimWhitespace
  • Functionality:
    • When enabled, pressing Tab or Enter in a matrix environment will remove surrounding whitespace before inserting "&" or "\\".
    • Multi-selection support: Ensures consistent trimming across multiple cursors.
  • Purpose: Prevents excessive spaces from affecting LaTeX matrix formatting.

This feature is enabled by default and can be disabled in settings.

@Testudinidae Testudinidae force-pushed the feature/matrix-shortcuts-trim-whitespace branch 2 times, most recently from 0c271b2 to 82ae879 Compare February 16, 2025 08:39
@Testudinidae Testudinidae force-pushed the feature/matrix-shortcuts-trim-whitespace branch from 82ae879 to 4509ae0 Compare February 17, 2025 00:13
@Testudinidae Testudinidae force-pushed the feature/matrix-shortcuts-trim-whitespace branch 2 times, most recently from ea07bcc to b645757 Compare February 17, 2025 14:35
@Testudinidae Testudinidae force-pushed the feature/matrix-shortcuts-trim-whitespace branch from b645757 to a9eb98b Compare February 19, 2025 04:06
Comment on lines -22 to +79
// Take main cursor since ctx.mode takes the main cursor, weird behaviour is expected with multicursor because of this.
if (key === "Tab" && view.state.selection.main.empty) {
view.dispatch(view.state.replaceSelection(" & "));
trimWhitespace = settings.matrixShortcutsTrimWhitespace;

if (key === "Tab") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shifting indentation when selecting something makes more sense then replacing the current selection with a &. Otherwise you can't change the indentation easily but you can replace the current selection by pressing & itself.

couldn't figure out how to review properly, sorry for the possible notifications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good consideration. I will add && view.state.selection.main.empty back, which means it’s based on the main selection. If there is a selection range in the main, it will indent; if there is no selection in the main, it will replace (regardless of other selections). But I’m also considering whether to change it so that if the selection is the entire line, it will indent, as some IDEs (like VS Code) handle it this way.

@Testudinidae
Copy link
Contributor Author

PR closed as it was replaced by another PR. #394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants