@@ -67,15 +67,42 @@ function BaseMod:disable()
67
67
end
68
68
end
69
69
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" }
70
76
function 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
77
91
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
79
106
end
80
107
81
108
function BaseMod :render (range )
@@ -85,7 +112,6 @@ function BaseMod:render(range)
85
112
self :clear (range )
86
113
end
87
114
88
- -- TODO: API-indexing
89
115
--- @param range HlChunk.Scope the range to clear , start line and end line all include , 0-index
90
116
function BaseMod :clear (range )
91
117
local start = range .start
0 commit comments