@@ -67,15 +67,42 @@ function BaseMod:disable()
6767 end
6868end
6969
70+ -- Rendering will only occur when the following conditions are met.
71+ -- 1. The buffer is valid
72+ -- 2. The plugin is enabled
73+ -- 3. The filetype is not in the exclude_filetypes list
74+ -- 4. The shiftwidth is not 0
75+ -- 5. The buftype is not in the allowed_buftypes list { "help", "nofile", "terminal", "prompt" }
7076function BaseMod :shouldRender (bufnr )
71- if api .nvim_buf_is_valid (bufnr ) then
72- local ft = vim .bo [bufnr ].ft
73- local shiftwidth = cFunc .get_sw (bufnr )
74- if ft then
75- return self .conf .enable and not self .conf .exclude_filetypes [ft ] and shiftwidth ~= 0
76- end
77+ if not api .nvim_buf_is_valid (bufnr ) then
78+ return false
79+ end
80+
81+ local ft = vim .bo [bufnr ].filetype
82+ local buftype = vim .bo [bufnr ].buftype
83+
84+ if not self .conf .enable then
85+ return false
86+ end
87+
88+ -- filetype
89+ if self .conf .exclude_filetypes [ft ] then
90+ return false
7791 end
78- return false
92+
93+ -- shiftwidth
94+ local shiftwidth = cFunc .get_sw (bufnr )
95+ if shiftwidth == 0 then
96+ return false
97+ end
98+
99+ -- buftype
100+ local allowed_buftypes = { " help" , " nofile" , " terminal" , " prompt" }
101+ if vim .tbl_contains (allowed_buftypes , buftype ) then
102+ return false
103+ end
104+
105+ return true
79106end
80107
81108function BaseMod :render (range )
@@ -85,7 +112,6 @@ function BaseMod:render(range)
85112 self :clear (range )
86113end
87114
88- -- TODO: API-indexing
89115--- @param range HlChunk.Scope the range to clear , start line and end line all include , 0-index
90116function BaseMod :clear (range )
91117 local start = range .start
0 commit comments