Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Active line not highlighted when codeblock language is specified #288

Open
alythobani opened this issue Oct 14, 2024 · 0 comments · May be fixed by #289
Open

Bug: Active line not highlighted when codeblock language is specified #288

alythobani opened this issue Oct 14, 2024 · 0 comments · May be fixed by #289
Assignees
Labels
bug Something isn't working

Comments

@alythobani
Copy link

Describe the bug

The active line highlighting in a codeblock only works if the codeblock doesn't have a language specified. (CSS bug)

Steps to reproduce

  1. Enable "Codeblock Active Line Highlight"
  2. Create a codeblock, and specify a language e.g. ts
  3. Place cursor inside codeblock, and observe that the active line does not get highlighted

Example codeblock

```ts
test
```

Expected behaviour

Active line should be highlighted the way it is when a language isn't specified:

Screen Shot 2024-10-14 at 1 12 02 PM

Current behaviour

Active line is not highlighted when language is specified:
Screen Shot 2024-10-14 at 1 12 24 PM

Environment

  • Plugin Version: 1.1.7
  • Obsidian Version: 1.6.7
  • Platform: Desktop
  • OS: Mac - Monterey 12.5
  • Theme: default
  • CSS Snippets: no

Additional context / Possible solution

Experimenting a little with the source code in codeblocks.css, it looks like the background property from lines 309-312:

.code-styler-active-line-highlight .markdown-source-view .HyperMD-codeblock.cm-active,
.code-styler-active-line-highlight-codeblock .markdown-source-view .HyperMD-codeblock.cm-active {
	background: linear-gradient(to right, var(--code-styler-active-codeblock-line-colour), var(--gradient-highlights-colour-stop), var(--code-styler-codeblock-background-colour)) !important;
}

is getting overridden by the background property from lines 143-145:

.code-styler .markdown-source-view .HyperMD-codeblock[class*='code-styler-line'][class*='language-'] {
	background: linear-gradient(90deg, var(--language-border-colour), var(--language-border-colour) var(--language-border-width), var(--gradient-background-colour) var(--language-border-width) var(--gradient-highlights-colour-stop), transparent 100%), var(--code-styler-codeblock-background-colour) !important;
}

And changing lines 309-312 to just set --gradient-background-colour ( instead of background fixes things. Albeit not fully perfectly: the active line highlighting then fully overrides any other line highlighting e.g. hl; whereas maybe ideally they'd overlap so it's still clear that the current line has another highlight underneath.

Screen Shot 2024-10-14 at 2 49 38 PM Screen Shot 2024-10-14 at 2 49 43 PM

But this is probably good enough as a quick initial fix (a better/different fix, where the active highlighting would be layered on top of other highlighting, might involve a deeper change to the implementation, e.g. maybe adding another div layer for the hl highlighting).

Very cool plugin btw :)

@alythobani alythobani added the bug Something isn't working label Oct 14, 2024
@alythobani alythobani linked a pull request Oct 14, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants