diff --git a/lazy-lock.json b/lazy-lock.json index 3ceb019..bcf2fbd 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -6,7 +6,7 @@ "auto-bufferline.nvim": { "branch": "main", "commit": "2766951c88e7fdf667b25799771d209fe1f025f3" }, "auto-conform.nvim": { "branch": "main", "commit": "5f0897235e84bf2f8ff9d634e81678d5bfa63ab8" }, "auto-lint.nvim": { "branch": "main", "commit": "aff13cb8eaa055e66e940d43b7d83166397e5413" }, - "auto-lsp.nvim": { "branch": "main", "commit": "ea80aef3ac630d310c2643047aaa7d7747d207a1" }, + "auto-lsp.nvim": { "branch": "main", "commit": "c0e6f49bcf789b476ee551279f5b3ec9a8081bbd" }, "auto-lualine.nvim": { "branch": "main", "commit": "c889473aef975bf3b17a770dfb2039bb2a0cd41c" }, "breadcrumbs.nvim": { "branch": "master", "commit": "9f764278784ce2f10dbe2f555ba14be2451d36a0" }, "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, @@ -14,15 +14,15 @@ "cmp-cmdline": { "branch": "main", "commit": "d126061b624e0af6c3a556428712dd4d4194ec6d" }, "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, - "cmp-path": { "branch": "main", "commit": "c6635aae33a50d6010bf1aa756ac2398a2d54c32" }, + "cmp-path": { "branch": "main", "commit": "e52e640b7befd8113b3350f46e8cfcfe98fcf730" }, "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "code_runner.nvim": { "branch": "main", "commit": "65c8d11f507073b915f10faa88ea05bd4fbf69ce" }, "codeium.vim": { "branch": "main", "commit": "272c6e2755e8faa90e26bcdcd9fde6b9e61751ea" }, - "conform.nvim": { "branch": "master", "commit": "8132ec733eed3bf415b97b76797ca41b59f51d7d" }, + "conform.nvim": { "branch": "master", "commit": "4c9003aab62879612c50136649baa1b8ed36cfa1" }, "dracula.nvim": { "branch": "main", "commit": "96c9d19ce81b26053055ad6f688277d655b3f7d2" }, "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, "friendly-snippets": { "branch": "main", "commit": "572f5660cf05f8cd8834e096d7b4c921ba18e175" }, - "gitsigns.nvim": { "branch": "main", "commit": "1b0350ab707713b2bc6c236151f1a324175347b1" }, + "gitsigns.nvim": { "branch": "main", "commit": "588264bee92993df92535b6742576f5655c91b1c" }, "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lualine.nvim": { "branch": "master", "commit": "a94fc68960665e54408fe37dcf573193c4ce82c9" }, @@ -35,14 +35,14 @@ "multiple-cursors.nvim": { "branch": "main", "commit": "1ac15d047a4b265cc2389957bcc56ee561b29e02" }, "neotest": { "branch": "master", "commit": "1d4b3bd89afa8bfa12fffd2bb1ccd26ac3c92ce5" }, "neotest-golang": { "branch": "main", "commit": "9521843942423fcac9991c596ff19c1f4f500650" }, - "neotest-jest": { "branch": "main", "commit": "dd82016c01704d9bbd5188749fe0586b3b620693" }, + "neotest-jest": { "branch": "main", "commit": "797515e113ac8e19c6855046d7f746d9c0c39c15" }, "neotest-plenary": { "branch": "master", "commit": "3523adcf9ffaad1911960c5813b0136c1b63a2ec" }, "neotest-vim-test": { "branch": "master", "commit": "75c4228882ae4883b11bfce9b8383e637eb44192" }, "neotest-vitest": { "branch": "main", "commit": "a6099e1fb55a2c2851da3dd0f4d510af9a234c92" }, "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, "npm-runner.nvim": { "branch": "main", "commit": "06d303e0a8ba384cd5fc35de6ba62d3500c99148" }, "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, - "nvim-autopairs": { "branch": "master", "commit": "2647cce4cb64fb35c212146663384e05ae126bdf" }, + "nvim-autopairs": { "branch": "master", "commit": "23320e75953ac82e559c610bec5a90d9c6dfa743" }, "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, "nvim-colorizer.lua": { "branch": "master", "commit": "517df88cf2afb36652830df2c655df2da416a0ae" }, "nvim-dap": { "branch": "master", "commit": "14fe46ae16eb272629144a93f7738f5279665a4f" }, @@ -51,7 +51,7 @@ "nvim-dap-virtual-text": { "branch": "master", "commit": "fbdb48c2ed45f4a8293d0d483f7730d24467ccb6" }, "nvim-dap-vscode-js": { "branch": "main", "commit": "03bd29672d7fab5e515fc8469b7d07cc5994bbf6" }, "nvim-lint": { "branch": "master", "commit": "2b0039b8be9583704591a13129c600891ac2c596" }, - "nvim-lspconfig": { "branch": "master", "commit": "6bba673aa8993eceec233be17b42ddfb9540794b" }, + "nvim-lspconfig": { "branch": "master", "commit": "1cb30b1bafe5a63a5c6ac20dc39f83487df38855" }, "nvim-material-icon": { "branch": "main", "commit": "c25a4e56be2f846dfdf8f30b980adc17f219d019" }, "nvim-navic": { "branch": "master", "commit": "f887d794a0f4594882814d7780980a949200a238" }, "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, diff --git a/lua/pcode/core/init.lua b/lua/pcode/core/init.lua index 7ef9ee4..b3b3091 100644 --- a/lua/pcode/core/init.lua +++ b/lua/pcode/core/init.lua @@ -3,3 +3,5 @@ require("pcode.user.default") require("pcode.config.lazy_lib") require("pcode.user.colorscheme") require("pcode.core.neovide") + +require("pcode.core.keymaps") diff --git a/lua/pcode/core/keymaps.lua b/lua/pcode/core/keymaps.lua new file mode 100644 index 0000000..16dca05 --- /dev/null +++ b/lua/pcode/core/keymaps.lua @@ -0,0 +1,180 @@ +local keymaps = { + ["LSP"] = { + { "LSP Code Action", "la" }, + { "LSP Code Format", "lf" }, + { "LSP Information", "li" }, + { "Mason Information", "lI" }, + { "LSP Next Diagnostic", "lj" }, + { "LSP Previous Diagnostic", "lk" }, + { "LSP Quickfix", "lr" }, + { "LSP Signature Help", "ls" }, + { "LSP Format On Range", "lF" }, + }, + ["Cmp"] = { + { "Scroll Next Documentation", "CTRL + f" }, + { "Scroll Previous Documentation", "CTRL + b" }, + { "Mapping Complete", "CTRL + space" }, + { "Abort Completion", "CTRL + e" }, + { "Accept Completion", "↵" }, + { "Next Autocompletion", "TAB" }, + { "Previous Autocompletion", "SHIFT + TAB" }, + }, + ["Terminal"] = { + { "Terminal Float", "tf" }, + { "Terminal Horizontal", "th" }, + { "Terminal new tab", "ts" }, + { "Terminal Vertical", "tv" }, + { "Terminal Close", "tx" }, + }, + ["Comment"] = { + { "Comment line toggle", "gcc or CTRL + /" }, + { "Comment block toggle", "gbc or CTRL + /" }, + { "Comment visual selection", "gc" }, + { "Comment visual selection using block delimiters", "gb" }, + { "Comment out text object line wise", "gc" }, + { "Comment out text object block wise", "gb" }, + { "Add comment on the line above", "gcO" }, + { "Add comment on the line below", "gco" }, + { "Add comment at the end of line", "gcA" }, + }, + ["Bufferline"] = { + { "Move Active Buffer Left", "SHIFT + h OR SHIFT + ArrowLeft" }, + { "Move Active Buffer Right", "SHIFT + l OR SHIFT + ArrowRight" }, + { "Reorder Bufferline", "SHIFT + PageUp/PageDown" }, + { "Close Current Buffer", "SHIFT + t" }, + }, + ["Window"] = { + { "Resize Window", "CTRL + ArrowLeft/ArrowRight/ArrowUp/ArrowDown" }, + { "Navigate Window", "CTRL + h/l" }, + }, +} + +-- Section title highlight setup +vim.api.nvim_set_hl(0, "KeymapsSectionOil", { bg = "#8fbcbb", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "KeymapsSectionCmp", { bg = "#b48ead", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "KeymapsSectionComment", { bg = "#bf616a", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Normal2", { bg = "#56B7C3", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Color1", { bg = "#D6ACFF", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Color2", { bg = "#F1FA8C", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Color3", { bg = "#FF79C6", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Color4", { bg = "#FF92DF", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Color5", { bg = "#69ff94", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Color6", { bg = "#FF6E6E", fg = "#1e1e1e", bold = true }) +vim.api.nvim_set_hl(0, "Color7", { bg = "#D6ACFF", fg = "#1e1e1e", bold = true }) + +local section_hl = { + "KeymapsSectionOil", + "KeymapsSectionCmp", + "KeymapsSectionComment", + "Normal2", + "Color1", + "Color2", + "Color3", + "Color4", + "Color5", + "Color6", + "Color7", +} + +local function pad(str, width) + local n = vim.fn.strdisplaywidth(str) + return str .. string.rep(" ", width - n) +end + +local function calc_widths(tbl) + local col1, col2 = 0, 0 + for _, group in pairs(tbl) do + for _, row in ipairs(group) do + col1 = math.max(col1, vim.fn.strdisplaywidth(row[1])) + col2 = math.max(col2, vim.fn.strdisplaywidth(row[2])) + end + end + return col1, col2 +end + +local function make_lines(tbl, max_width) + local col1, col2 = calc_widths(tbl) + if max_width then + local padding = max_width - (col1 + col2 + 3) + if padding > 0 then + col1 = col1 + math.floor(padding * 0.7) + col2 = col2 + padding - math.floor(padding * 0.7) + end + end + local lines = {} + local hls = {} + Random_index = 1 + + for section, rows in pairs(tbl) do + local section_title = (" %s "):format(section) + table.insert(lines, section_title) + table.insert(hls, { { 0, #section_title, section_hl[Random_index] or "Normal2" } }) + Random_index = Random_index + 1 + if Random_index > #section_hl then + Random_index = 1 + end + -- Hapus baris Description, hanya tampilkan garis bawah dan data + table.insert(lines, string.rep("─", col1) .. "─┬─" .. string.rep("─", col2)) + table.insert(hls, {}) + for _, row in ipairs(rows) do + table.insert(lines, pad(row[1], col1) .. " │ " .. pad(row[2], col2)) + table.insert(hls, {}) + end + table.insert(lines, "") + table.insert(hls, {}) + end + return lines, col1 + col2 + 3, hls +end + +local function show_keymaps_popup() + local ui = vim.api.nvim_list_uis()[1] + local win_width = math.floor(ui.width * 0.7) + local lines, width, hls = make_lines(keymaps, win_width) + width = win_width + local height = #lines + + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) + vim.api.nvim_buf_set_option(buf, "modifiable", false) + vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe") + + -- highlight section titles + for i, l in ipairs(hls) do + for _, v in ipairs(l) do + vim.api.nvim_buf_add_highlight(buf, -1, v[3], i - 1, v[1], v[2]) + end + end + + local row = math.floor((ui.height - height) / 2) + local col = math.floor((ui.width - width) / 2) + + local win = vim.api.nvim_open_win(buf, true, { + relative = "editor", + row = row, + col = col, + width = width, + height = height, + style = "minimal", + border = "single", + title = "Keymaps", + title_pos = "center", + }) + + vim.keymap.set("n", "q", function() + vim.api.nvim_win_close(win, true) + end, { buffer = buf, nowait = true }) + vim.keymap.set("n", "", function() + vim.api.nvim_win_close(win, true) + end, { buffer = buf, nowait = true }) +end + +vim.api.nvim_create_user_command("KeymapsPopup", function() + show_keymaps_popup() +end, {}) + +vim.keymap.set("n", "", ":KeymapsPopup", { noremap = true, silent = true }) + +return { + show = show_keymaps_popup, +}