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

Update main.ts #120

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,24 @@ export default class QuickLatexPlugin extends Plugin {
}
};

// Tab to go to next #tab with numbering or without numbering if there are no #tabs with numbers
const indexed_tab_expr = /#tab(\d+)?/g;
let next_match;
let current_match;
while ((current_match = indexed_tab_expr.exec(current_line)) != null) {
if (!next_match || parseInt(current_match[1]) < parseInt(next_match[1]))
next_match = current_match;
}

if (next_match) {
const tab_position = next_match.index;
editor.replaceRange("",
{line:position.line, ch:tab_position},
{line:position.line, ch:tab_position+next_match[0].length})
editor.setCursor({line:position.line, ch:tab_position})
return true
}

// Tab shortcut for matrix block
if (this.settings.addMatrixBlock_toggle) {
const begin_matrix = ['\\begin{' + this.settings.addMatrixBlock_parameter+'}', "\\begin{matrix}","\\begin{bmatrix}", "\\begin{Bmatrix}", "\\begin{vmatrix}", "\\begin{Vmatrix}", "\\begin{smallmatrix}"]
Expand Down Expand Up @@ -243,26 +261,7 @@ export default class QuickLatexPlugin extends Plugin {
}
};
}

// Tab to go to next #tab with numbering or without numbering if there are no #tabs with numbers
const indexed_tab_expr = /#tab(\d+)?/g;
let next_match;
let current_match;
while ((current_match = indexed_tab_expr.exec(current_line)) != null) {
if (!next_match || parseInt(current_match[1]) < parseInt(next_match[1]))
next_match = current_match;
}

if (next_match) {
const tab_position = next_match.index;
editor.replaceRange("",
{line:position.line, ch:tab_position},
{line:position.line, ch:tab_position+next_match[0].length})
editor.setCursor({line:position.line, ch:tab_position})
return true
}



// Tab out of $
const next_2 = editor.getRange({line:position.line, ch:position.ch},{line:position.line, ch:position.ch+2})
if (next_2 == "$$") {
Expand Down