File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ for (const permalinkEl of document.querySelectorAll('.permalink')) {
14
14
function handleClicks ( e ) {
15
15
// No need to scroll
16
16
e . preventDefault ( ) ;
17
- // Add hash back to url
18
- history . pushState ( { } , '' , href ) ;
17
+ // Add hash back to url, but without pushState cuz it usually creates more problems
18
+ window . location . href = href ;
19
19
20
20
const textBlob = new Blob ( [ e . type === 'dblclick' ? markdown : href ] , { type : 'text/plain' } ) ;
21
21
const htmlBlob = new Blob ( [ htmlStr ] , { type : 'text/html' } ) ;
@@ -44,5 +44,16 @@ for (const permalinkEl of document.querySelectorAll('.permalink')) {
44
44
// This can happen if the user denies clipboard permissions
45
45
. catch ( err => console . error ( 'Could not copy to clipboard: ' , err ) ) ;
46
46
}
47
-
48
47
} ;
48
+
49
+ // Handle back-button navigations through hashes. (yes it does seem weird that this need to be done manually.......)
50
+ window . addEventListener ( "popstate" , scrollToCurrentHash ) ;
51
+ document . addEventListener ( "DOMContentLoaded" , scrollToCurrentHash ) ;
52
+ function scrollToCurrentHash ( e ) {
53
+ const u = new URL ( location . href ) ;
54
+ const hash = u . hash . slice ( 1 ) ;
55
+ if ( ! hash ) return ;
56
+
57
+ const elem = document . querySelector ( `#${ hash } ` ) ;
58
+ elem . scrollIntoView ( { block : 'start' } ) ;
59
+ }
You can’t perform that action at this time.
0 commit comments