mirror of
https://github.com/rabirabirara/obsidian-jelly-snippets.git
synced 2026-07-22 07:30:22 +00:00
refac: denest triggerSearchSnippet
This commit is contained in:
parent
1df6b5b0ed
commit
0c1ed70b5c
1 changed files with 27 additions and 28 deletions
17
main.ts
17
main.ts
|
|
@ -267,11 +267,16 @@ export default class JellySnippets extends Plugin {
|
|||
|
||||
for (let [lhs, search] of Object.entries(this.searches)) {
|
||||
let searchResult = search(curLineText);
|
||||
if (searchResult) {
|
||||
if (!searchResult) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let lastMatchPart = searchResult.matches.find(
|
||||
(part) => part[1] === curpos.ch
|
||||
);
|
||||
if (lastMatchPart) {
|
||||
if (!lastMatchPart) {
|
||||
continue;
|
||||
}
|
||||
if (curpos.ch >= lhs.length) {
|
||||
// TODO: This change fixes old bug but snippet now triggers even if there is no whitespace before the lhs. Or does it? Verify this...
|
||||
// TODO: lhs still cannot have newlines in it. Wouldn't be hard to update however.
|
||||
|
|
@ -285,19 +290,13 @@ export default class JellySnippets extends Plugin {
|
|||
};
|
||||
let lookBack = editor.getRange(from, to);
|
||||
if (lookBack === lhs) {
|
||||
editor.replaceRange(
|
||||
this.searchSnippets[lhs],
|
||||
from,
|
||||
to
|
||||
);
|
||||
editor.replaceRange(this.searchSnippets[lhs], from, to);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// snippet before cursor found but not triggered means no other snippet should trigger
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue