Skip to content

Commit

Permalink
Merge pull request #120 from Virusmint/master
Browse files Browse the repository at this point in the history
Update main.ts
  • Loading branch information
joeyuping authored Jan 29, 2024
2 parents f6d75f6 + 8b14000 commit 356c55f
Showing 1 changed file with 19 additions and 20 deletions.
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

0 comments on commit 356c55f

Please sign in to comment.