mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Add code to extract hashtags from changeset comment
This commit is contained in:
@@ -260,6 +260,30 @@ export function uiCommit(context) {
|
||||
}
|
||||
|
||||
|
||||
function findHashtags(tags) {
|
||||
return _.unionBy(commentTags(), hashTags(), function (s) {
|
||||
return s.toLowerCase();
|
||||
});
|
||||
|
||||
// Extract hashtags from `comment`
|
||||
function commentTags() {
|
||||
return tags.comment.match(/#[^\s\#]+/g);
|
||||
}
|
||||
|
||||
// Extract and clean hashtags from `hashtags`
|
||||
function hashTags() {
|
||||
var t = tags.hashtags || '';
|
||||
return t
|
||||
.split(/[,;\s]+/)
|
||||
.map(function (s) {
|
||||
if (s[0] !== '#') { s = '#' + s; } // prepend '#'
|
||||
var matched = s.match(/#[^\s\#]+/g); // match valid hashtags
|
||||
return matched && matched[0];
|
||||
}).filter(Boolean); // exclude falsey
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function isReviewRequested(tags) {
|
||||
var rr = tags.review_requested;
|
||||
if (rr === undefined) return false;
|
||||
@@ -286,6 +310,13 @@ export function uiCommit(context) {
|
||||
}
|
||||
});
|
||||
|
||||
if (!onInput) {
|
||||
var hashtags = findHashtags(tags);
|
||||
if (hashtags.length) {
|
||||
tags.hashtags = hashtags.join(';').substr(0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
if (!_.isEqual(changeset.tags, tags)) {
|
||||
changeset = changeset.update({ tags: tags });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user