From 9bfbd62b228c8811a297d92e358ffb621e13c096 Mon Sep 17 00:00:00 2001 From: DeathAxe Date: Tue, 14 Sep 2021 19:02:10 +0200 Subject: [PATCH] Fix: Correct heading style detection Fixes #625 Just count leading and trailing hash tags and compare the amount in order to decide for style. This ignores SETEXT headings and fixes an edge case caused by new syntax definition. --- plugins/headings/style.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/plugins/headings/style.py b/plugins/headings/style.py index b05b40d0..72b94761 100644 --- a/plugins/headings/style.py +++ b/plugins/headings/style.py @@ -76,19 +76,16 @@ def auto_detect_heading_style(self): view.settings().set("mde.auto_match_heading_hashes", False) return - num_leading = 0 - num_trailing = 0 - - for h1, h2 in zip( - view.find_by_selector("markup.heading")[:10], - view.find_by_selector("markup.heading - punctuation.definition.heading")[:10], - ): - num_leading += 1 - if h1.end() > h2.end(): - num_trailing += 1 - + num_leading = len( + view.find_by_selector("markup.heading punctuation.definition.heading.begin") + ) if num_leading: + num_trailing = len( + view.find_by_selector("markup.heading punctuation.definition.heading.end") + ) view.settings().set("mde.match_heading_hashes", num_trailing / num_leading > 0.5) + else: + view.settings().erase("mde.match_heading_hashes") if view.settings().get("mde.auto_match_heading_hashes", False): view.run_command("mde_match_heading_hashes")