Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

feat: text filter regex support (#406)

Zhou Yunliang4ed987229b1e
diff --git a/web/src/components/CreateShortcutDialog.tsx b/web/src/components/CreateShortcutDialog.tsx
index d6a32c5cf..c6d3d3f79 100644
--- a/web/src/components/CreateShortcutDialog.tsx
+++ b/web/src/components/CreateShortcutDialog.tsx
@@ -258,6 +258,7 @@ const MemoFilterInputer: React.FC<MemoFilterInputerProps> = (props: MemoFilterIn
onChange={(event) => {
handleValueChange(event.target.value);
}}
+ placeholder={t("filter.text-placeholder")}
/>
) : (
<Selector className="value-selector" dataSource={valueDataSource} value={value} handleValueChanged={handleValueChange} />
diff --git a/web/src/helpers/filter.ts b/web/src/helpers/filter.ts
index c0100269b..57dd1880c 100644
--- a/web/src/helpers/filter.ts
+++ b/web/src/helpers/filter.ts
@@ -142,11 +142,16 @@ export const checkShouldShowMemo = (memo: Memo, filter: Filter) => {
}
shouldShow = matched;
} else if (type === "TEXT") {
- let contained = memo.content.toLowerCase().includes(value.toLowerCase());
- if (operator === "NOT_CONTAIN") {
- contained = !contained;
+ if (value.startsWith("^")) {
+ const reg = new RegExp(value.slice(1));
+ shouldShow = operator === "NOT_CONTAIN" ? !reg.test(memo.content) : reg.test(memo.content);
+ } else {
+ let contained = memo.content.toLowerCase().includes(value.toLowerCase());
+ if (operator === "NOT_CONTAIN") {
+ contained = !contained;
+ }
+ shouldShow = contained;
}
- shouldShow = contained;
}
return shouldShow;
diff --git a/web/src/locales/en.json b/web/src/locales/en.json
index 87f98d8dc..67e96810e 100644
--- a/web/src/locales/en.json
+++ b/web/src/locales/en.json
@@ -116,7 +116,8 @@
"value": {
"not-tagged": "No tags",
"linked": "Has links"
- }
+ },
+ "text-placeholder": "Starts with ^ to use regex"
},
"tag-list": {
"tip-text": "Enter `#tag ` to create"
diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json
index 3073eba7d..6d7500344 100644
--- a/web/src/locales/zh.json
+++ b/web/src/locales/zh.json
@@ -116,7 +116,8 @@
"value": {
"not-tagged": "无标签",
"linked": "包含链接"
- }
+ },
+ "text-placeholder": "以 ^ 开头使用正则表达式"
},
"tag-list": {
"tip-text": "输入`#tag `来创建标签"