mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Fix issue where hashtags set in URL parameter would not be honored
This commit is contained in:
@@ -75,17 +75,17 @@ export function uiCommit(context) {
|
||||
if (!_changeset) {
|
||||
|
||||
// load in the URL hash values, if any
|
||||
var hash = context.ui().hash;
|
||||
if (hash.comment) {
|
||||
prefs('comment', hash.comment);
|
||||
var hashBehavior = context.ui().hash;
|
||||
if (hashBehavior.comment) {
|
||||
prefs('comment', hashBehavior.comment);
|
||||
prefs('commentDate', Date.now());
|
||||
}
|
||||
if (hash.source) {
|
||||
prefs('source', hash.source);
|
||||
if (hashBehavior.source) {
|
||||
prefs('source', hashBehavior.source);
|
||||
prefs('commentDate', Date.now());
|
||||
}
|
||||
if (hash.hashtags) {
|
||||
prefs('hashtags', hash.hashtags);
|
||||
if (hashBehavior.hashtags) {
|
||||
prefs('hashtags', hashBehavior.hashtags);
|
||||
}
|
||||
|
||||
var detected = utilDetect();
|
||||
@@ -473,41 +473,38 @@ export function uiCommit(context) {
|
||||
|
||||
|
||||
function findHashtags(tags, commentOnly) {
|
||||
var inComment = commentTags();
|
||||
var inHashTags = hashTags();
|
||||
var detectedHashtags = commentHashtags();
|
||||
|
||||
if (inComment !== null) { // when hashtags are detected in comment...
|
||||
prefs('hashtags', null); // always remove stored hashtags - #4304
|
||||
if (commentOnly) { inHashTags = []; } // optionally override hashtags field
|
||||
if (detectedHashtags.length) {
|
||||
// always remove stored hashtags if there are hashtags in the comment - #4304
|
||||
prefs('hashtags', null);
|
||||
}
|
||||
if (!detectedHashtags.length || !commentOnly) {
|
||||
detectedHashtags = detectedHashtags.concat(hashtagHashtags());
|
||||
}
|
||||
|
||||
// keep only one copy of the tags
|
||||
var all = new Set();
|
||||
var keepTags = [];
|
||||
inComment.forEach(checkTag);
|
||||
inHashTags.forEach(checkTag);
|
||||
return keepTags;
|
||||
|
||||
// Compare tags as lowercase strings, but keep original case tags
|
||||
function checkTag(s) {
|
||||
var compare = s.toLowerCase();
|
||||
if (!all.has(compare)) {
|
||||
all.add(compare);
|
||||
keepTags.push(s);
|
||||
var allLowerCase = new Set();
|
||||
return detectedHashtags.filter(function(hashtag) {
|
||||
// Compare tags as lowercase strings, but keep original case tags
|
||||
var lowerCase = hashtag.toLowerCase();
|
||||
if (!allLowerCase.has(lowerCase)) {
|
||||
allLowerCase.add(lowerCase);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
// Extract hashtags from `comment`
|
||||
function commentTags() {
|
||||
function commentHashtags() {
|
||||
var matches = (tags.comment || '')
|
||||
.replace(/http\S*/g, '') // drop anything that looks like a URL - #4289
|
||||
.match(hashtagRegex);
|
||||
|
||||
return (matches || []);
|
||||
return matches || [];
|
||||
}
|
||||
|
||||
// Extract and clean hashtags from `hashtags`
|
||||
function hashTags() {
|
||||
function hashtagHashtags() {
|
||||
var matches = (tags.hashtags || '')
|
||||
.split(/[,;\s]+/)
|
||||
.map(function (s) {
|
||||
@@ -516,7 +513,7 @@ export function uiCommit(context) {
|
||||
return matched && matched[0];
|
||||
}).filter(Boolean); // exclude falsy
|
||||
|
||||
return (matches || []);
|
||||
return matches || [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user