Skip to content

Commit

Permalink
Added 'multi line' regex option
Browse files Browse the repository at this point in the history
  • Loading branch information
FelisDiligens committed Feb 13, 2023
1 parent bd8e576 commit 23df005
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function getDialogHTML() {
<input type="checkbox" id="wrap-chk" name="wrap-chk" {wrap}><label for="wrap-chk">Wrap around</label><br>
<input type="checkbox" id="matchcase-chk" name="matchcase-chk" {matchcase}><label for="matchcase-chk">Match case</label><br>
<input type="checkbox" id="matchwholeword-chk" name="matchwholeword-chk" {matchwholeword}><label for="matchwholeword-chk">Match whole words only</label><br>
<input type="checkbox" id="preservecase-chk" name="preservecase-chk" {preservecase}><label for="preservecase-chk">Preserve case</label>
<input type="checkbox" id="preservecase-chk" name="preservecase-chk" {preservecase}><label for="preservecase-chk">Preserve case</label><br>
<input type="checkbox" id="multiline-chk" name="multiline-chk" {multiline}><label for="multiline-chk">Use 'multi line' flag</label>
</td>
<td>
<input type="radio" id="useliteralsearch-rad" name="matchmethod" value="literal" {matchmethod-literal}><label for="useliteralsearch-rad" checked>Literal search</label><br>
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ joplin.plugins.register({
"matchcase-chk": "off",
"matchwholeword-chk": "off",
"preservecase-chk": "off",
"multiline-chk": "off",
"matchmethod": "literal"
});
dialogSARLastFormData = {
...dialogSAR.getDefaultFormData(),
"matchcase-chk": "on"
"matchcase-chk": "on",
"multiline-chk": "on"
};

/*
Expand Down Expand Up @@ -151,6 +153,7 @@ joplin.plugins.register({
"matchcase": dialogSARLastFormData["matchcase-chk"] == "on" ? "checked" : "",
"matchwholeword": dialogSARLastFormData["matchwholeword-chk"] == "on" ? "checked" : "",
"preservecase": dialogSARLastFormData["preservecase-chk"] == "on" ? "checked" : "",
"multiline": dialogSARLastFormData["multiline-chk"] == "on" ? "checked" : "",
"matchmethod-literal": dialogSARLastFormData["matchmethod"] == "literal" ? "checked" : "",
"matchmethod-wildcards": dialogSARLastFormData["matchmethod"] == "wildcards" ? "checked" : "",
"matchmethod-regex": dialogSARLastFormData["matchmethod"] == "regex" ? "checked" : ""
Expand All @@ -172,7 +175,8 @@ joplin.plugins.register({
matchCase: result.formData["matchcase-chk"] == "on",
matchWholeWord: result.formData["matchwholeword-chk"] == "on",
matchMethod: result.formData["matchmethod"],
preserveCase: result.formData["preservecase-chk"] == "on"
preserveCase: result.formData["preservecase-chk"] == "on",
multiLine: result.formData["multiline-chk"] == "on"
},
}

Expand Down
3 changes: 2 additions & 1 deletion src/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export async function getPanelHTML() {
<input type="checkbox" id="wrap-chk"><label for="wrap-chk">Wrap around<sup>1</sup></label><br>
<input type="checkbox" id="matchcase-chk" checked><label for="matchcase-chk">Match case</label><br>
<input type="checkbox" id="matchwholeword-chk"><label for="matchwholeword-chk">Match whole words only</label><br>
<input type="checkbox" id="preservecase-chk"><label for="preservecase-chk">Preserve case</label>
<input type="checkbox" id="preservecase-chk"><label for="preservecase-chk">Preserve case</label><br>
<input type="checkbox" id="multiline-chk" checked><label for="multiline-chk">Use 'multi line' flag</label>
</td>
<td>
<input type="radio" id="useliteralsearch-rad" name="matchmethod" checked><label for="useliteralsearch-rad" checked>Literal search</label><br>
Expand Down
4 changes: 3 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ export function wildCardToRegExp(value: string, beginToEnd: boolean = true) {
}

/** Create a RegExp with the given `searchPattern` and `options`. */
export function prepareRegex(searchPattern: string, options: {global: boolean, matchCase: boolean, matchMethod: "regex" | "wildcards" | "literal", matchWholeWord: boolean}): RegExp {
export function prepareRegex(searchPattern: string, options: {global: boolean, multiLine: boolean, matchCase: boolean, matchMethod: "regex" | "wildcards" | "literal", matchWholeWord: boolean}): RegExp {
let regexFlags = "";
if (options.global)
regexFlags += "g";
if (!options.matchCase)
regexFlags += "i";
if (options.multiLine)
regexFlags += "m";

let regexStr = searchPattern;

Expand Down
3 changes: 3 additions & 0 deletions src/webview_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let wrapAroundChk = document.querySelector("#wrap-chk");
let matchCaseChk = document.querySelector("#matchcase-chk");
let matchWholeWordChk = document.querySelector("#matchwholeword-chk");
let preserveCaseChk = document.querySelector("#preservecase-chk");
let multiLineChk = document.querySelector("#multiline-chk");

let useLiteralSearchRad = document.querySelector("#useliteralsearch-rad");
let useWildcardsRad = document.querySelector("#usewildcards-rad");
Expand Down Expand Up @@ -55,6 +56,7 @@ function getForm() {
matchWholeWord: matchWholeWordChk.checked,
matchMethod: matchMethod,
preserveCase: preserveCaseChk.checked,
multiLine: multiLineChk.checked
},
};
}
Expand Down Expand Up @@ -132,6 +134,7 @@ matchWholeWordChk.addEventListener("change", updatePreviewRegex);
useLiteralSearchRad.addEventListener("change", updatePreviewRegex);
useWildcardsRad.addEventListener("change", updatePreviewRegex);
useRegexRad.addEventListener("change", updatePreviewRegex);
multiLineChk.addEventListener("change", updatePreviewRegex);

// Hide numbers if the help isn't displayed:
document.querySelectorAll("sup").forEach((el) => {
Expand Down

0 comments on commit 23df005

Please sign in to comment.