Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,23 @@ There are two hook methods i.e `pre_hook` and `post_hook` which are called befor
pre_hook = function(ctx)
-- Only calculate commentstring for tsx filetypes
if vim.bo.filetype == 'typescriptreact' then
local U = require('Comment.utils')

-- Detemine whether to use linewise or blockwise commentstring
local type = ctx.ctype == require('Comment.utils').ctype.line and '__default' or '__multiline'
return require('ts_context_commentstring.internal').calculate_commentstring({ key = type })
local type = ctx.ctype == U.ctype.line and '__default' or '__multiline'

-- Determine the location where to calculate commentstring from
local location = nil
if ctx.ctype == U.ctype.block then
location = require('ts_context_commentstring.utils').get_cursor_location()
elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
location = require('ts_context_commentstring.utils').get_visual_start_location()
end

return require('ts_context_commentstring.internal').calculate_commentstring({
key = type,
location = location,
})
end
end,
}
Expand Down