{{ define "repo/fragments/permalinkShortcut" }}
  <script>
    (() => {
      {{ if .LastCommitInfo }}
      const abortController = new AbortController();
      const scriptEl = document.currentScript;
      document.addEventListener('keydown', (e) => {
        if(e.key === 'y' && !e.ctrlKey && !e.metaKey && !e.altKey) {
          if(e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
          const permalinkUrl = '/{{ .RepoInfo.FullName }}/tree/{{ .LastCommitInfo.Hash }}/{{ .Path }}';
          window.location.href = permalinkUrl;
        }
      }, {signal: abortController.signal});

      document.body.addEventListener('htmx:beforeCleanupElement', (e) => {
        if(e.target === scriptEl) {
          abortController.abort();
        }
      }, {signal: abortController.signal});
      {{ end }}
    })();
  </script>
{{ end }}
