mirror of
https://github.com/ytliu74/obsidian-pseudocode.git
synced 2026-07-22 07:40:25 +00:00
feat: Insert end tag while auto-complete
This commit is contained in:
parent
d73fc6a663
commit
731961466d
1 changed files with 21 additions and 1 deletions
|
|
@ -81,7 +81,16 @@ export class PseudocodeSuggestor extends EditorSuggest<string> {
|
|||
const start = this.context.start;
|
||||
const end = editor.getCursor();
|
||||
|
||||
editor.replaceRange(suggestion, start, end);
|
||||
const pairSuggestion = this.pairSuggestions[suggestion];
|
||||
let insertText = suggestion;
|
||||
if (pairSuggestion) {
|
||||
const line = editor.getLine(start.line);
|
||||
const indentMatch = line.match(/^(\s*)/)?.[0] ?? "";
|
||||
const indent = indentMatch.replace(/\t/g, " "); // replace each tab with four spaces
|
||||
insertText += "\n" + indent + pairSuggestion;
|
||||
}
|
||||
|
||||
editor.replaceRange(insertText, start, end);
|
||||
const newCursor = end;
|
||||
newCursor.ch = start.ch + suggestion.length;
|
||||
|
||||
|
|
@ -91,6 +100,17 @@ export class PseudocodeSuggestor extends EditorSuggest<string> {
|
|||
}
|
||||
}
|
||||
|
||||
private pairSuggestions: Record<string, string> = {
|
||||
"\\begin{algorithmic}": "\\end{algorithmic}",
|
||||
"\\begin{algorithm}": "\\end{algorithm}",
|
||||
"\\Procedure{}{}": "\\EndProcedure",
|
||||
"\\Function{}{}": "\\EndFunction",
|
||||
"\\For{}": "\\EndFor",
|
||||
"\\If{}": "\\EndIf",
|
||||
"\\While{}": "\\EndWhile",
|
||||
// Add more pairs as needed
|
||||
};
|
||||
|
||||
private pseudocodeKeywords: string[] = [
|
||||
"\\begin{algorithmic}",
|
||||
"\\begin{algorithm}",
|
||||
|
|
|
|||
Loading…
Reference in a new issue