Skip to content

Commit

Permalink
2.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyuping committed Oct 25, 2022
1 parent 7eea1cb commit a2b8088
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 5 deletions.
69 changes: 67 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,67 @@ export default class QuickLatexPlugin extends Plugin {
},

},
{
key: 'Shift-Space',
run: (): boolean => {
const view = this.app.workspace.getActiveViewOfType(MarkdownView)
if (!view) return false

const editor = view.editor

if (!this.settings.customShorthand_toggle) return false;

if (this.withinMath(editor)) {
const position = editor.getCursor();

// check for custom shorthand
if (this.settings.customShorthand_toggle && !this.withinText(editor, position.ch)) {
let keyword:string = "";
let keyword_length:number = 0;
for (let i = 0 ; i < this.shorthand_array.length ; i++) {
keyword_length = this.shorthand_array[i][0].length;
if ( keyword_length > position.ch) {
continue;
} else if ( keyword_length == position.ch ) {
keyword = "@" + editor.getRange(
{ line: position.line, ch: position.ch - keyword_length },
{ line: position.line, ch: position.ch });
} else {
keyword = editor.getRange(
{ line: position.line, ch: position.ch - keyword_length - 1 },
{ line: position.line, ch: position.ch });
}
if (keyword[0].toLowerCase() == keyword[0].toUpperCase() ||
keyword[0] == "@" ) {
if (this.shorthand_array[i][0] == keyword.slice(- keyword_length) &&
this.shorthand_array[i][1] != keyword) {
const replace_slash = (keyword[0]=="\\" && this.shorthand_array[i][1][0]=="\\") ? 1 : 0;
const set_cursor_position = this.shorthand_array[i][1].indexOf("#cursor");
editor.replaceRange(this.shorthand_array[i][1],
{ line: position.line, ch: position.ch - keyword_length - replace_slash },
{ line: position.line, ch: position.ch });
if (set_cursor_position != -1) {
editor.replaceRange("",
{line:position.line, ch:position.ch - keyword_length - replace_slash + set_cursor_position},
{line:position.line, ch:position.ch - keyword_length - replace_slash + set_cursor_position+7});
editor.setCursor({line:position.line, ch:position.ch - keyword_length - replace_slash + set_cursor_position})
} else if (this.shorthand_array[i][1].slice(-2) == "{}") {
editor.setCursor(
{ line: position.line,
ch: position.ch + this.shorthand_array[i][1].length - keyword_length - 1 - replace_slash}
);
} else {

}
return true;
};
};
};
};
};
}
},

{
key: 'Enter',
run: (): boolean => {
Expand Down Expand Up @@ -573,6 +634,7 @@ export default class QuickLatexPlugin extends Plugin {

if (this.withinMath(editor)) {
if (this.settings.autoCloseCurly_toggle) {
if (editor.getSelection().length > 0) {return false};
const position = editor.getCursor();
const brackets = [['(', ')'], ['{', '}'], ['[', ']']];
const next_char = editor.getRange(
Expand Down Expand Up @@ -603,6 +665,7 @@ export default class QuickLatexPlugin extends Plugin {

if (this.withinMath(editor)) {
if (this.settings.autoCloseSquare_toggle) {
if (editor.getSelection().length > 0) {return false};
const position = editor.getCursor();
const brackets = [['(', ')'], ['{', '}'], ['[', ']']];
const next_char = editor.getRange(
Expand Down Expand Up @@ -632,6 +695,7 @@ export default class QuickLatexPlugin extends Plugin {

if (this.withinMath(editor)) {
if (this.settings.autoCloseRound_toggle) {
if (editor.getSelection().length > 0) {return false};
const position = editor.getCursor();
const brackets = [['(', ')'], ['{', '}'], ['[', ']']];
const next_char = editor.getRange(
Expand All @@ -641,6 +705,7 @@ export default class QuickLatexPlugin extends Plugin {
{ line: position.line, ch: position.ch },
{ line: position.line, ch: position.ch+2 });
const followed_by_$spacetabnonedoubleslash = (['$',' ',' ',''].contains(next_char) || next_2char == '\\\\');

if (!this.withinAnyBrackets_inline(editor, brackets) && followed_by_$spacetabnonedoubleslash) {
editor.replaceSelection('()');
editor.setCursor({line:position.line, ch:position.ch+1});
Expand All @@ -661,7 +726,7 @@ export default class QuickLatexPlugin extends Plugin {
const editor = view.editor

if (this.withinMath(editor)) {
if (this.settings.autoCloseRound_toggle) {
if (this.settings.autoCloseCurly_toggle) {
const position = editor.getCursor();
const end = editor.getLine(position.line).length
const next_sym = editor.getRange({line:position.line,ch:position.ch},{line:position.line,ch:position.ch+1})
Expand All @@ -687,7 +752,7 @@ export default class QuickLatexPlugin extends Plugin {
const editor = view.editor

if (this.withinMath(editor)) {
if (this.settings.autoCloseRound_toggle) {
if (this.settings.autoCloseSquare_toggle) {
const position = editor.getCursor();
const end = editor.getLine(position.line).length
const next_sym = editor.getRange({line:position.line,ch:position.ch},{line:position.line,ch:position.ch+1})
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "quick-latex",
"name": "Quick Latex for Obsidian",
"version": "2.5.0",
"version": "2.5.1",
"minAppVersion": "0.9.12",
"description": "Speedup latex math typing with auto fraction, align block shortcut, matrix shortcut...etc",
"author": "joeyuping",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ if you want to view the source visit the plugins github repository
export default {
input: 'main.ts',
output: {
dir: 'D:/1 Projects/AI/.obsidian/plugins/quick_latex',
// dir: 'D:/Obsidian/AI/.obsidian/plugins/quick-latex',
// dir: 'D:/1 Projects/AI/.obsidian/plugins/quick_latex',
dir: 'D:/Obsidian/AI/.obsidian/plugins/quick-latex',
sourcemap: 'inline',
sourcemapExcludeSources: isProd,
format: 'cjs',
Expand Down

0 comments on commit a2b8088

Please sign in to comment.