Show which line is highlighted

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-02-25 16:56:33 +01:00
parent a41c3cd293
commit cfb695d592
3 changed files with 13 additions and 8 deletions
+7 -4
View File
@@ -7,7 +7,7 @@
const lastCommit = blob.info.lastCommit;
const lines = blob.binary ? 0 : (blob.content.match(/\n/g) || []).length;
const lineNumbers = Array(lines).fill(0).map((_, index) => (index + 1).toString());
const lineNumbers = Array(lines).fill(0).map((_, index) => index + 1);
const parentDir = blob.path.match(/^.*\/|/)?.values().next().value;
// Waiting onMount, due to the line numbers still loading.
@@ -66,8 +66,8 @@
.line-number {
display: block;
}
.line-number:hover {
color: var(--color-foreground);
.line-number:hover, .line-number.highlighted {
color: var(--color-foreground-90);
}
.code {
@@ -133,7 +133,10 @@
{:else}
<pre class="line-numbers">
{#each lineNumbers as lineNumber}
<a href="#L{lineNumber}" class="line-number" id="L{lineNumber}">{lineNumber}</a>
<a href="#L{lineNumber}"
class="line-number"
class:highlighted={lineNumber === line}
id="L{lineNumber}">{lineNumber}</a>
{/each}
</pre>
<pre
+1 -1
View File
@@ -57,7 +57,7 @@
mobileFileTree = false;
if (path) {
project.navigateTo({ path: newPath, revision });
project.navigateTo({ path: newPath, revision, line: null });
}
};
+5 -3
View File
@@ -15,11 +15,13 @@
export let config: Config;
export let hash: string | null = null;
const line = formatLocationHash(hash);
const browse: proj.BrowseTo = { content, peer, path: "/", line };
const browse: proj.BrowseTo = { content, peer, path: "/" };
const head = project.branches[project.defaultBranch];
// route is passed when the URL has more params after e.g. /tree or /history
// If line-number hash changes, we update the browser.
$: browse.line = formatLocationHash(hash);
// `route` includes any unmatched path segments.
$: if (route) {
const { path, revision } = proj.parseRoute(route, project.branches);