Skip to content

Commit e3ebc90

Browse files
authored
Merge pull request velopert#116 from velopert/fix/weird-tags
Properly add tags when there is hashtag in the text - Fix velopert#100
2 parents 655748a + 43ecf5e commit e3ebc90

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/components/write/TagInput.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,24 @@ const TagInput: React.FC<TagInputProps> = ({ onChange, tags: initialTags }) => {
111111
ignore.current = true;
112112
setValue('');
113113
if (tag === '' || tags.includes(tag)) return;
114-
setTags([...tags, tag.trim()]);
114+
let processed = tag;
115+
processed = tag.trim();
116+
if (processed.indexOf(' #') > 0) {
117+
const tempTags: string[] = [];
118+
const regex = /#(\S+)/g;
119+
let execArray: RegExpExecArray | null = null;
120+
while ((execArray = regex.exec(processed))) {
121+
if (execArray !== null) {
122+
tempTags.push(execArray[1]);
123+
}
124+
}
125+
setTags([...tags, ...tempTags]);
126+
return;
127+
}
128+
if (processed.charAt(0) === '#') {
129+
processed = processed.slice(1, processed.length);
130+
}
131+
setTags([...tags, processed]);
115132
},
116133
[tags],
117134
);

0 commit comments

Comments
 (0)