lukas-reineke / headlines.nvim

This plugin adds horizontal highlights for text filetypes, like markdown, orgmode, and neorg.
MIT License
688 stars 28 forks source link

Flickering background in Quarto cells #75

Open andy941 opened 6 months ago

andy941 commented 6 months ago

Hi, I love the plugin, it makes a pleasure to work with Quarto files (I use it mainly for data science at work). I have an annoying issue where the cells background is unset in random amount of lines when another highlight is on, or that is what my debugging got me to. See below an example of the type of flickering I get: normal highlight image broken by Illuminate (see the two lemur_residuals) image These are actually very sudden and I am not sure what they are related to (cursor is on a white space, maybe the IndentBlankline plugin?): image

All this flickers constantly while moving the cursor around but I can't figure out why exactly. My guess is that happens when something else sets a background inside the cell? Disabling VimIlluminate for example solves that specific type of flickering.

Changing colorscheme to a default one does not help.

My headlines.nvim config:

require("headlines").setup({
    quarto = {
        query = vim.treesitter.query.parse(
            "markdown",
            [[
        (atx_heading [
          (atx_h1_marker)
          (atx_h2_marker)
          (atx_h3_marker)
          (atx_h4_marker)
          (atx_h5_marker)
          (atx_h6_marker)
        ] @headline)

        (thematic_break) @dash

        (fenced_code_block) @codeblock

        (block_quote_marker) @quote
        (block_quote (paragraph (inline (block_continuation) @quote)))
        (block_quote (paragraph (block_continuation) @quote))
        (block_quote (block_continuation) @quote)
      ]]
        ),
        headline_highlights = { "Headline" },
        bullet_highlights = {
            "@text.title.1.marker.markdown",
            "@text.title.2.marker.markdown",
            "@text.title.3.marker.markdown",
            "@text.title.4.marker.markdown",
            "@text.title.5.marker.markdown",
            "@text.title.6.marker.markdown",
        },
        treesitter_language = "markdown",
        bullets = { "◉", "○", "✸", "✿" },
        codeblock_highlight = "CodeBlock",
        dash_highlight = "Dash",
        dash_string = "-",
        quote_highlight = "Quote",
        quote_string = "┃",
        fat_headlines = true,
        fat_headline_upper_string = "▃",
        fat_headline_lower_string = "🬂",
    },
})

The code in the pictures:

#| label: plotting
#| echo: true
#| output-location: slide
#| message: false
#| fig-align: center
#| fig-alt: "Scatter plot of predicted and residual values for the fitted linear model."
library(reticulate)
library(ggplot2)
lemur_residuals <- py$lemur_data_py
ggplot(
  data = lemur_residuals,
  mapping = aes(
    x = Predicted,
    y = Residuals
  )
) +
  geom_point(colour = "#2F4F4F") +
  geom_hline(
    yintercept = 0,
    colour = "red"
  ) +
  theme(
    panel.background = element_rect(
      fill = "#eaf2f2",
      colour = "#eaf2f2"
    ),
    plot.background = element_rect(
      fill = "#eaf2f2",
      colour = "#eaf2f2"
    )
  )

Do you have an idea on what is going on?

lukas-reineke commented 5 months ago

I cannot reproduce this.

Can you use this template and steps to cause the issue?

local lazypath = "/tmp/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system { "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath }
end
vim.opt.rtp:prepend(lazypath)
vim.opt.termguicolors = true

require("lazy").setup ({
    {
        "lukas-reineke/headlines.nvim",
        config = function()
            require("headlines").setup {}
        end,
    },
}, { root = "/tmp/lazy" })
andy941 commented 5 months ago

Still see a flickering in this very simple example: image

only when the cursor is on one of the parenthesis. I had to expand the minimal config a little bit to work with quarto:

local lazypath = "/tmp/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system { "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath }
end
vim.opt.rtp:prepend(lazypath)
vim.opt.termguicolors = true

require("lazy").setup ({
    {
        "lukas-reineke/headlines.nvim",
        config = function()
            require("headlines").setup {
                quarto = {
                    query = vim.treesitter.query.parse(
                    "markdown",
                    [[
                    (atx_heading [
                    (atx_h1_marker)
                    (atx_h2_marker)
                    (atx_h3_marker)
                    (atx_h4_marker)
                    (atx_h5_marker)
                    (atx_h6_marker)
                    ] @headline)

                    (thematic_break) @dash

                    (fenced_code_block) @codeblock

                    (block_quote_marker) @quote
                    (block_quote (paragraph (inline (block_continuation) @quote)))
                    (block_quote (paragraph (block_continuation) @quote))
                    (block_quote (block_continuation) @quote)
                    ]]
                    ),
                    headline_highlights = { "Headline" },
                    bullet_highlights = {
                        "@text.title.1.marker.markdown",
                        "@text.title.2.marker.markdown",
                        "@text.title.3.marker.markdown",
                        "@text.title.4.marker.markdown",
                        "@text.title.5.marker.markdown",
                        "@text.title.6.marker.markdown",
                    },
                    treesitter_language = "markdown",
                    bullets = { "◉", "○", "✸", "✿" },
                    codeblock_highlight = "CodeBlock",
                    dash_highlight = "Dash",
                    dash_string = "-",
                    quote_highlight = "Quote",
                    quote_string = "┃",
                    fat_headlines = true,
                    fat_headline_upper_string = "▃",
                    fat_headline_lower_string = "🬂",
                },
            }
        end,
        dependencies = {"nvim-treesitter/nvim-treesitter"},
    },
}, { root = "/tmp/lazy" })

I can't reproduce the other bugs with the minimal config.

Let me know if this helps.

andy941 commented 5 months ago

@lukas-reineke Any thoughts? Can I help with more tests?