diff --git a/modules/behavior/hash.js b/modules/behavior/hash.js index 386e8716a..888e671e5 100644 --- a/modules/behavior/hash.js +++ b/modules/behavior/hash.js @@ -111,8 +111,8 @@ export function behaviorHash(context) { } } - var throttledUpdate = _throttle(updateHashIfNeeded, 500); - var throttledUpdateTitle = _throttle(function() { + var _throttledUpdate = _throttle(updateHashIfNeeded, 500); + var _throttledUpdateTitle = _throttle(function() { updateTitle(true /* includeChangeCount */); }, 500); @@ -164,13 +164,13 @@ export function behaviorHash(context) { function behavior() { context.map() - .on('move.behaviorHash', throttledUpdate); + .on('move.behaviorHash', _throttledUpdate); context.history() - .on('change.behaviorHash', throttledUpdateTitle); + .on('change.behaviorHash', _throttledUpdateTitle); context - .on('enter.behaviorHash', throttledUpdate); + .on('enter.behaviorHash', _throttledUpdate); d3_select(window) .on('hashchange.behaviorHash', hashchange); @@ -206,8 +206,8 @@ export function behaviorHash(context) { } behavior.off = function() { - throttledUpdate.cancel(); - throttledUpdateTitle.cancel(); + _throttledUpdate.cancel(); + _throttledUpdateTitle.cancel(); context.map() .on('move.behaviorHash', null); diff --git a/modules/ui/commit.js b/modules/ui/commit.js index 9fce57a94..de7553389 100644 --- a/modules/ui/commit.js +++ b/modules/ui/commit.js @@ -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 || []; } }