nothingislost / obsidian-dynamic-highlights

An experimental Obsidian plugin that highlights all occurrences of the word under the cursor
MIT License
132 stars 7 forks source link

Highlights disappearing on long files #61

Closed sailKiteV closed 2 years ago

sailKiteV commented 2 years ago

Overview

When scrolling through large files, it seems that otherwise functioning highlights will stop working at a certain point in the scroll. Highlights broken in this manner will no longer function even when scrolling or jumping back to the top of the page. If using a link from another file to immediately jump to a section of a page that is past the cutoff point, then highlights will not appear in any fashion. The issue appears to be related more to the size of the file in terms of content than the size of the file in terms of raw lines.

Information

Error

An error is thrown in the console whenever the issue occurs, taking the following form, to which i have added hyphens to represent the indentation that would normally be present in the console:

app.js:1 RangeError: Mark decorations may not be empty -at e.range (app.js:1:394829) -at Dt.ViewPlugin.fromClass.provide.getDeco (plugin:obsidian-dynamic-highlights:86:26527) -at Dt.ViewPlugin.fromClass.provide.update (plugin:obsidian-dynamic-highlights:86:25579) -at t.update (app.js:1:406664) -at t.updatePlugins (app.js:1:489870) -at t.measure (app.js:1:490654) -at t.onScrollChanged (app.js:1:486040) -at t.onScroll (app.js:1:474953)

Debug

Running Obsidian's debug command produces the following:

SYSTEM INFO: Obsidian version: v0.14.15 Installer version: v0.14.15 Operating system: Windows 10 Home 10.0.19043 Login status: not logged in Insider build toggle: off Live preview: off Legacy editor: off Base theme: dark Community theme: none Snippets enabled: 0 Safe mode: off Plugins installed: 1 Plugins enabled: 1 1: Dynamic Highlights

RECOMMENDATIONS: Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the help vault or disable community plugins.

Examples

i have attached two files that were tested in the Sandbox Vault to demonstrate the occurrence of the issue. 1) copy of playground.md 2) long file 1.md

The first file is one in which the issue is present (larger overall size with more content). The second file is one in which the issue is not present (smaller overall size, but lots of vertical rows).

Demonstration of first file

highlight bug demo 1

Demonstration of second file

highlight bug demo 2


Postscript

Thank you for your time, and if you require any other information please don't hesitate to ask.

Regards, -sailKite

nothingislost commented 2 years ago

Great report, thank you! I'll look into this shortly.

nothingislost commented 2 years ago

Two questions. Which version of the plugin are you using? And can you export your dynamic highlighter and include it here?

sailKiteV commented 2 years ago

Thanks for the speedy reply! As requested:

Plugin Version: 0.2.5 (Closed Sandbox Vault already but it should be the same version.)

Highlight JSON File (in ZIP because GitHub won't accept the JSON as attachment): dynamic-highlights-sail-JSON.zip

Highlight JSON As Text:

{ "quote-property": { "class": "quote-property", "color": "#42188000", "regex": false, "query": "quote:: ", "mark": [ "match" ], "css": ".quote-property {\n display: none;\n}\n\n.HyperMD-quote:hover .cm-quote > .quote-property {\n color: var(--text-faint);\n font-style: italic;\n display: inline;\n}" }, "relative-link-nuker": { "class": "relative-link-nuker", "color": "#1B801838", "regex": true, "query": "(?<=\[\[).?(?=(?:\]\]|#|\|))", "mark": [ "match" ], "css": "" }, "Mini-Linting": { "class": "Mini-Linting", "color": "#A70F0F38", "regex": true, "query": " {2,}(?!\|| |$)|- - |^\s- \n|^ +(?![0-9-`])", "mark": [ "match" ], "css": ".cm-line .Mini-Linting {\n background: none;\n}\n\n.cm-line:not(.cm-active) .Mini-Linting {\n outline: 1px solid var(--text-error);\n}" } }

nothingislost commented 2 years ago

Alright, so this is an issue with your relative link nuker regex. It has the possibility to create a match that is zero characters long (empty) which causes CodeMirror to try and mark a zero character range, which causes a crash. I can look into ignoring zero character matches on my side but for now, you can tune that regex to not have the possibility to match zero characters.

An initial test on your included file shows that this would work (?<=\[\[).*?(?=(?:\]\]|\|))

If you want to play around, use regex101 and make sure none of your matches show up as "null" https://regex101.com/r/PUobqQ/1 image

sailKiteV commented 2 years ago

You are a hero! A hero! Thank you for catching the issue, and i'm glad to see it was a problem between my chair and keyboard, to little surprise! 😅

Best of luck, -sailKite

[Return to top]