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) => { onChange={(event) => {
handleValueChange(event.target.value); handleValueChange(event.target.value);
}} }}
placeholder={t("filter.text-placeholder")}
/> />
) : ( ) : (
<Selector className="value-selector" dataSource={valueDataSource} value={value} handleValueChanged={handleValueChange} /> <Selector className="value-selector" dataSource={valueDataSource} value={value} handleValueChanged={handleValueChange} />

View File

@ -142,11 +142,16 @@ export const checkShouldShowMemo = (memo: Memo, filter: Filter) => {
} }
shouldShow = matched; shouldShow = matched;
} else if (type === "TEXT") { } else if (type === "TEXT") {
let contained = memo.content.toLowerCase().includes(value.toLowerCase()); if (value.startsWith("^")) {
if (operator === "NOT_CONTAIN") { const reg = new RegExp(value.slice(1));
contained = !contained; 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; return shouldShow;

View File

@ -116,7 +116,8 @@
"value": { "value": {
"not-tagged": "No tags", "not-tagged": "No tags",
"linked": "Has links" "linked": "Has links"
} },
"text-placeholder": "Starts with ^ to use regex"
}, },
"tag-list": { "tag-list": {
"tip-text": "Enter `#tag ` to create" "tip-text": "Enter `#tag ` to create"

View File

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