Skip to content

Commit

Permalink
feat: hide cursor in popup(#12)
Browse files Browse the repository at this point in the history
* Popup: hide cursor

* update: add config option

Added hide_cursor option.

---------

Co-authored-by: = <=>
Co-authored-by: Luckas <luckasranarison@gmail.com>
  • Loading branch information
ArturitoGit and luckasRanarison committed Oct 10, 2023
1 parent f50efe0 commit a44fb10
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ The default configuration:
enable = true,
center = false,
border = "rounded",
hide_cursor = false,
highlights = {
header = "CodeActionHeader",
label = "CodeActionLabel",
Expand Down
1 change: 1 addition & 0 deletions lua/clear-action/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ local defaults = {
enable = true,
center = false,
border = "rounded",
hide_cursor = false,
highlights = {
header = "CodeActionHeader",
label = "CodeActionLabel",
Expand Down
11 changes: 7 additions & 4 deletions lua/clear-action/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local config = require("clear-action.config")
local signs = require("clear-action.signs")
local mappings = require("clear-action.mappings")
local actions = require("clear-action.actions")
local popup = require("clear-action.popup")

M.setup = function(options)
config.setup(options)
Expand All @@ -15,10 +16,12 @@ M.setup = function(options)
local client = vim.lsp.get_client_by_id(args.data.client_id)
local cmd = vim.api.nvim_buf_create_user_command

if client and client.supports_method("textDocument/codeAction") then
signs.on_attach(bufnr)
mappings.on_attach(bufnr, client)
end
if client and client.supports_method("textDocument/codeAction") then return end

signs.on_attach(bufnr)
mappings.on_attach(bufnr, client)

if config.options.popup.hide_cursor then popup.hide_cursor_autocmd() end

cmd(bufnr, "CodeActionToggleSigns", signs.toggle_signs, {})
cmd(bufnr, "CodeActionToggleLabel", signs.toggle_label, {})
Expand Down
22 changes: 22 additions & 0 deletions lua/clear-action/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ local config = require("clear-action.config")
vim.api.nvim_set_hl(0, "CodeActionHeader", { link = "Bold" })
vim.api.nvim_set_hl(0, "CodeActionTitle", { link = "Normal" })
vim.api.nvim_set_hl(0, "CodeActionLabel", { fg = "#f7768e", bold = true, italic = true })
vim.api.nvim_set_hl(0, "CodeActionCursor", { reverse = true, blend = 100 })

local function hide_cursor() vim.opt.guicursor:append("a:CodeActionCursor/CodeActionCursor") end
local function show_cursor() vim.opt.guicursor:remove("a:CodeActionCursor/CodeActionCursor") end

local function hide_cursor_until_leave_buffer()
hide_cursor()
vim.api.nvim_create_autocmd({ "bufleave" }, {
group = config.augroup,
callback = show_cursor,
buffer = 0,
})
end

-- Hide cursor in popup
M.hide_cursor_autocmd = function()
vim.api.nvim_create_autocmd("FileType", {
group = config.augroup,
pattern = "CodeAction",
callback = hide_cursor_until_leave_buffer,
})
end

local function create_popup(action_tuples)
local opts = config.options.popup
Expand Down

0 comments on commit a44fb10

Please sign in to comment.