Skip to content

Commit

Permalink
fix: fixes dice-mod not respecting form/noform in live preview
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Oct 13, 2023
1 parent f37db0f commit c13922d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/live-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,6 @@ function inlineRender(view: EditorView, plugin: DiceRollerPlugin) {
const widgets: Range<Decoration>[] = [];
const selection = view.state.selection;
const regex = new RegExp(".*?_?inline-code_?.*");
/* before:
* em for italics
* highlight for highlight
* after:
* strong for bold
* strikethrough for strikethrough
*/
for (const { from, to } of view.visibleRanges) {
syntaxTree(view.state).iterate({
from,
Expand All @@ -94,19 +87,27 @@ function inlineRender(view: EditorView, plugin: DiceRollerPlugin) {
if (selectionAndRangeOverlap(selection, start, end + 1)) return;

const original = view.state.doc.sliceString(start, end).trim();
if (/^dice-mod:\s*([\s\S]+)\s*?/.test(original)) {
if (/^dice\-mod:\s*([\s\S]+)\s*?/.test(original)) {
let [, content] = original.match(
/dice-mod:\s*([\s\S]+)\s*?/
/dice\-mod:\s*([\s\S]+)\s*?/
);

const currentFile = app.workspace.getActiveFile();
const roller = plugin.getRollerSync(
content,
currentFile.path
);
let showFormula = plugin.data.displayFormulaForMod;

if (content.includes("|noform")) {
showFormula = false;
}
if (content.includes("|form")) {
showFormula = true;
}

roller.roll().then((result) => {
const insert = plugin.data.displayFormulaForMod
roller.roll().then(() => {
const insert = showFormula
? `${roller.inlineText} **${roller.replacer}**`
: `${roller.replacer}`;
const mod = {
Expand Down

0 comments on commit c13922d

Please sign in to comment.