Skip to content

Commit

Permalink
fix(split): refactor filetype setting and highlight application
Browse files Browse the repository at this point in the history
This commit refactors the way the filetype is set for the split buffer
in `hurl/split.lua`. Instead of conditionally setting the filetype based
on the presence of `edgy.nvim`, the filetype is now always set to
'hurl-nvim'. This change simplifies the code and ensures consistent
behavior regardless of the presence of `edgy.nvim`.
  • Loading branch information
jellydn committed May 28, 2024
1 parent a185094 commit 675ff84
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lua/hurl/split.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ local M = {}
M.show = function(data, type)
-- mount/open the component
split:mount()
-- If have edgy.nvim
if pcall(require, 'edgy') then
-- Create a custom filetype so that we can use https://github.com/folke/edgy.nvim to manage the window
-- E.g: { title = "Hurl Nvim", ft = "hurl-nvim" },
vim.api.nvim_buf_set_option(split.bufnr, 'filetype', 'hurl-nvim')
end

-- Set content to highlight, refer https://github.com/MunifTanjim/nui.nvim/issues/76#issuecomment-1001358770
vim.api.nvim_buf_set_option(split.bufnr, 'filetype', type)
-- Create a custom filetype so that we can use https://github.com/folke/edgy.nvim to manage the window
-- E.g: { title = "Hurl Nvim", ft = "hurl-nvim" },
vim.bo[split.bufnr].filetype = 'hurl-nvim'

vim.api.nvim_buf_set_name(split.bufnr, 'hurl-response')

Expand Down Expand Up @@ -58,6 +53,12 @@ M.show = function(data, type)
-- Add content to the bottom
vim.api.nvim_buf_set_lines(split.bufnr, headers_table.line, -1, false, content)

-- Set content to highlight, refer https://github.com/MunifTanjim/nui.nvim/issues/76#issuecomment-1001358770
-- After 200ms, the highlight will be applied
vim.defer_fn(function()
vim.bo[split.bufnr].filetype = type
end, 200)

local function quit()
-- set buffer name to empty string so it wouldn't conflict when next time buffer opened
vim.api.nvim_buf_set_name(split.bufnr, '')
Expand Down

0 comments on commit 675ff84

Please sign in to comment.