feat: text filter regex support (#406)

This commit is contained in:
Zhou Yunliang 2022-11-03 21:06:17 +08:00 committed by GitHub
parent a1068b6fe3
commit 4ed987229b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View File

@ -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} />

View File

@ -142,12 +142,17 @@ export const checkShouldShowMemo = (memo: Memo, filter: Filter) => {
}
shouldShow = matched;
} else if (type === "TEXT") {
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;
}
}
return shouldShow;
};

View File

@ -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"

View File

@ -116,7 +116,8 @@
"value": {
"not-tagged": "无标签",
"linked": "包含链接"
}
},
"text-placeholder": "以 ^ 开头使用正则表达式"
},
"tag-list": {
"tip-text": "输入`#tag `来创建标签"