Skip to content

Commit 653b5a1

Browse files
committed
diff: Highlight both diffed versions in the sidebar
1 parent 8946575 commit 653b5a1

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

elixir/web.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ def get_projects(basedir: str) -> list[ProjectEntry]:
445445
# Used to render version list in the sidebar
446446
VersionEntry = namedtuple('VersionEntry', 'version, url, diff_url')
447447

448+
VersionPath = namedtuple('VersionPath', 'major, minor, path')
449+
448450
# Takes result of Query.get_versions() and prepares it for the sidebar template.
449451
# Returns an OrderedDict with version information and optionally a triple with
450452
# (major, minor, version) of current_version. The triple is useful, because sometimes
@@ -457,10 +459,10 @@ def get_projects(basedir: str) -> list[ProjectEntry]:
457459
def get_versions(versions: OrderedDict[str, OrderedDict[str, str]],
458460
get_url: Callable[[str], str],
459461
get_diff_url: Optional[Callable[[str], str]],
460-
current_version: str) -> Tuple[dict[str, dict[str, list[VersionEntry]]], Tuple[str|None, str|None, str|None]]:
462+
current_version: str) -> Tuple[dict[str, dict[str, list[VersionEntry]]], VersionPath]:
461463

462464
result = OrderedDict()
463-
current_version_path = (None, None, None)
465+
current_version_path = VersionPath(None, None, None)
464466
for major, minor_verions in versions.items():
465467
for minor, patch_versions in minor_verions.items():
466468
for v in patch_versions:
@@ -472,10 +474,20 @@ def get_versions(versions: OrderedDict[str, OrderedDict[str, str]],
472474
VersionEntry(v, get_url(v), get_diff_url(v) if get_diff_url is not None else None)
473475
)
474476
if v == current_version:
475-
current_version_path = (major, minor, v)
477+
current_version_path = VersionPath(major, minor, v)
476478

477479
return result, current_version_path
478480

481+
def find_version_path(versions: OrderedDict[str, OrderedDict[str, str]],
482+
version: str) -> VersionPath:
483+
for major, minor_verions in versions.items():
484+
for minor, patch_versions in minor_verions.items():
485+
for v in patch_versions:
486+
if v == version:
487+
return VersionPath(major, minor, v)
488+
489+
return VersionPath(None, None, None)
490+
479491
def get_versions_cached(q, ctx, project):
480492
with ctx.versions_cache_lock:
481493
if project not in ctx.versions_cache:
@@ -502,6 +514,7 @@ def get_layout_template_context(q: Query, ctx: RequestContext, get_url_with_new_
502514
'projects': get_projects(ctx.config.project_dir),
503515
'versions': versions,
504516
'current_version_path': current_version_path,
517+
'other_version_path': (None, None, None),
505518
'topbar_families': TOPBAR_FAMILIES,
506519
'elixir_version_string': ctx.config.version_string,
507520
'elixir_repo_url': ctx.config.repo_url,
@@ -809,7 +822,8 @@ def generate_warning(type, version):
809822
warning = f'Files are the same in {version} and {version_other}.'
810823
else:
811824
missing_version = version_other if type == 'blob' else version
812-
warning = f'File does not exist, or is not a file in {missing_version}. ({version} displayed)'
825+
shown_version = version if type == 'blob' else version_other
826+
warning = f'File does not exist, or is not a file in {missing_version}. ({shown_version} displayed)'
813827

814828
template_ctx = {
815829
'code': generate_source(q, project, version if type == 'blob' else version_other, path),
@@ -841,6 +855,7 @@ def generate_warning(type, version):
841855
**get_layout_template_context(q, ctx, get_url_with_new_version, get_diff_url, project, version),
842856
**template_ctx,
843857

858+
'other_version_path': find_version_path(get_versions_cached(q, ctx, project), version_other),
844859
'diff_mode_available': True,
845860
'diff_checked': True,
846861
'diff_exit_url': stringify_source_path(project, version, path),

static/style.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,13 @@ h2 {
453453
margin: 0;
454454
}
455455
.sidebar nav li.active a {
456-
color: #eee;
457456
color: #6d7dd2;
458457
font-weight: 700;
459458
}
459+
.sidebar nav li.active-other a {
460+
color: #d2c26d;
461+
font-weight: 700;
462+
}
460463
.sidebar nav ul {
461464
padding: 0;
462465
}

templates/sidebar.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ <h3 class="screenreader">Versions</h3>
2828
{% endif %}
2929

3030
{% set current_major, current_minor, current_version = current_version_path %}
31+
{% set other_major, other_minor, other_version = other_version_path %}
3132
{% for major, major_versions in (versions|default({})).items() %}
3233
<li>
33-
<span class="{{ 'active' if current_major == major else '' }}">{{ major }}</span>
34+
<span class="{{ 'active' if major in (current_major, other_major) else '' }}">{{ major }}</span>
3435

3536
<ul>
3637
{% for minor, minor_versions in major_versions.items() %}
@@ -40,10 +41,13 @@ <h3 class="screenreader">Versions</h3>
4041
</li>
4142
{% else %}
4243
<li>
43-
<span class="{{ 'active' if minor == current_minor else '' }}">{{ minor }}</span>
44+
<span class="{{ 'active' if minor in (current_minor, other_minor) else '' }}">{{ minor }}</span>
4445
<ul>
4546
{% for v in minor_versions %}
46-
<li class="li-link {{ 'active' if v.version == current_tag else '' }}">
47+
<li class="li-link
48+
{{ 'active' if v.version == current_tag else '' }}
49+
{{ 'active-other' if v.version == other_tag else '' }}
50+
">
4751
<a class="version-link-source" href="{{ v.url }}">
4852
{{ v.version }}
4953
</a>

0 commit comments

Comments
 (0)