Skip to content

Commit 85329db

Browse files
committed
fix fuzzy matching when match already exists
1 parent 5a77814 commit 85329db

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

themes/vue/source/js/common.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,23 @@
3434
}
3535
}
3636

37-
function escapeCharacters (hash) {
37+
function parseRawHash (hash) {
3838
// Remove leading hash
3939
if (hash.charAt(0) === '#') {
4040
hash = hash.substr(1)
4141
}
4242

43-
return '#' + CSS.escape(hash)
43+
// Escape characthers
44+
try {
45+
hash = decodeURIComponent(hash)
46+
} catch (e) {}
47+
return CSS.escape(hash)
4448
}
4549

4650
function initLocationHashFuzzyMatching () {
4751
var rawHash = window.location.hash
4852
if (!rawHash) return
49-
var hash
50-
try {
51-
hash = escapeCharacters(decodeURIComponent(rawHash))
52-
} catch(e) {
53-
hash = escapeCharacters(rawHash)
54-
}
53+
var hash = parseRawHash(rawHash)
5554
var hashTarget = document.getElementById(hash)
5655
if (!hashTarget) {
5756
var normalizedHash = normalizeHash(hash)
@@ -64,7 +63,7 @@
6463
if (distanceA > distanceB) return 1
6564
return 0
6665
})
67-
window.location.hash = possibleHashes[0]
66+
window.location.hash = '#' + possibleHashes[0]
6867
}
6968

7069
function normalizeHash (rawHash) {

0 commit comments

Comments
 (0)