add hotkey and unify config naming to snake_case
BREAKING CHANGE: The configuration option `pageSize` has been renamed to `page_size` to maintain a consistent style. Users need to update their personal configurations.
This commit is contained in:
30
README.md
30
README.md
@@ -63,17 +63,19 @@ You can override the default settings by passing a table to the `setup()` functi
|
|||||||
|
|
||||||
> **Note:** On first use, you will be prompted to enter your Memos host and token. You can choose to save these permanently.
|
> **Note:** On first use, you will be prompted to enter your Memos host and token. You can choose to save these permanently.
|
||||||
> The config file will be stored at:
|
> The config file will be stored at:
|
||||||
> - **macOS**: `~/.local/share/nvim/memos.nvim/memos_config.json`
|
> - **macOS / Linux**: `~/.local/share/nvim/memos.nvim/config.json`
|
||||||
> - **Linux**: `~/.local/share/nvim/memos.nvim/memos_config.json`
|
> - **Windows**: `~/AppData/Local/nvim-data/memos.nvim/config.json`
|
||||||
> - **Windows**: `~/AppData/Local/nvim-data/memos.nvim/memos_config.json`
|
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- lua/plugins/memos.lua
|
-- lua/plugins/memos.lua
|
||||||
require("memos").setup({
|
require("memos").setup({
|
||||||
|
|
||||||
-- Number of memos to fetch per page
|
-- Number of memos to fetch per page
|
||||||
pageSize = 50,
|
page_size = 50,
|
||||||
|
|
||||||
|
-- Auto-save the memo when leaving insert mode or holding the cursor.
|
||||||
auto_save = false,
|
auto_save = false,
|
||||||
|
|
||||||
-- Set to false or nil to disable a keymap
|
-- Set to false or nil to disable a keymap
|
||||||
keymaps = {
|
keymaps = {
|
||||||
-- Keymap to open the memos list. Default: <leader>mm
|
-- Keymap to open the memos list. Default: <leader>mm
|
||||||
@@ -84,8 +86,9 @@ require("memos").setup({
|
|||||||
add_memo = "a",
|
add_memo = "a",
|
||||||
delete_memo = "d",
|
delete_memo = "d",
|
||||||
delete_memo_visual = "dd",
|
delete_memo_visual = "dd",
|
||||||
edit_memo = "<CR>",
|
-- Assign both <CR> and 'i' to edit a memo
|
||||||
vsplit_edit_memo = "<Tab>",
|
edit_memo = { "<CR>", "i" },
|
||||||
|
vsplit_edit_memo = "<Tab>", -- Use Ctrl-x instead of Tab for better compatibility
|
||||||
search_memos = "s",
|
search_memos = "s",
|
||||||
refresh_list = "r",
|
refresh_list = "r",
|
||||||
next_page = ".",
|
next_page = ".",
|
||||||
@@ -166,17 +169,19 @@ require("memos").setup({
|
|||||||
|
|
||||||
> **注意:** 首次使用时会提示输入 Memos 的 host 和 token,并询问是否永久保存。
|
> **注意:** 首次使用时会提示输入 Memos 的 host 和 token,并询问是否永久保存。
|
||||||
> 配置文件将存储在:
|
> 配置文件将存储在:
|
||||||
> - **macOS**: `~/.local/share/nvim/memos.nvim/memos_config.json`
|
> - **macOS / Linux**: `~/.local/share/nvim/memos.nvim/config.json`
|
||||||
> - **Linux**: `~/.local/share/nvim/memos.nvim/memos_config.json`
|
> - **Windows**: `~/AppData/Local/nvim-data/memos.nvim/config.json`
|
||||||
> - **Windows**: `~/AppData/Local/nvim-data/memos.nvim/memos_config.json`
|
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- lua/plugins/memos.lua
|
-- lua/plugins/memos.lua
|
||||||
require("memos").setup({
|
require("memos").setup({
|
||||||
|
|
||||||
-- 每页获取的 memo 数量
|
-- 每页获取的 memo 数量
|
||||||
pageSize = 50,
|
page_size = 50,
|
||||||
|
|
||||||
|
-- 当离开插入模式或光标静止时,自动保存 memo。
|
||||||
auto_save = false,
|
auto_save = false,
|
||||||
|
|
||||||
-- 设置为 false 或 nil 可以禁用某个快捷键
|
-- 设置为 false 或 nil 可以禁用某个快捷键
|
||||||
keymaps = {
|
keymaps = {
|
||||||
-- 用于打开 Memos 列表的快捷键。默认值: <leader>mm
|
-- 用于打开 Memos 列表的快捷键。默认值: <leader>mm
|
||||||
@@ -187,8 +192,9 @@ require("memos").setup({
|
|||||||
add_memo = "a",
|
add_memo = "a",
|
||||||
delete_memo = "d",
|
delete_memo = "d",
|
||||||
delete_memo_visual = "dd",
|
delete_memo_visual = "dd",
|
||||||
edit_memo = "<CR>",
|
-- 将 <CR> 和 i 键都设置为编辑功能
|
||||||
vsplit_edit_memo = "<Tab>",
|
edit_memo = { "<CR>", "i" },
|
||||||
|
vsplit_edit_memo = "<Tab>", -- 使用 Ctrl-x 代替 Tab 以获得更好的兼容性
|
||||||
search_memos = "s",
|
search_memos = "s",
|
||||||
refresh_list = "r",
|
refresh_list = "r",
|
||||||
next_page = ".",
|
next_page = ".",
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ function M.get_current_user(callback)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.list_memos(parent, filter, pageSize, pageToken, callback)
|
function M.list_memos(parent, filter, page_size, pageToken, callback)
|
||||||
local list_url = config.host .. '/api/v1/memos'
|
local list_url = config.host .. '/api/v1/memos'
|
||||||
local params = {}
|
local params = {}
|
||||||
table.insert(params, "parent=" .. parent)
|
table.insert(params, "parent=" .. parent)
|
||||||
table.insert(params, "pageSize=" .. tostring(pageSize))
|
table.insert(params, "page_size=" .. tostring(page_size))
|
||||||
if pageToken and pageToken ~= "" then table.insert(params, "pageToken=" .. pageToken) end
|
if pageToken and pageToken ~= "" then table.insert(params, "pageToken=" .. pageToken) end
|
||||||
if filter and filter ~= '' then
|
if filter and filter ~= '' then
|
||||||
table.insert(params, 'filter=content.contains("' .. vim.fn.escape(filter, '\\"') .. '")')
|
table.insert(params, 'filter=content.contains("' .. vim.fn.escape(filter, '\\"') .. '")')
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ M.config = {
|
|||||||
host = nil,
|
host = nil,
|
||||||
token = nil,
|
token = nil,
|
||||||
auto_save = false,
|
auto_save = false,
|
||||||
pageSize = 50,
|
page_size = 50,
|
||||||
keymaps = {
|
keymaps = {
|
||||||
start_memos = "<leader>mm",
|
start_memos = "<leader>mm",
|
||||||
-- 在列表窗口中的快捷键
|
-- 在列表窗口中的快捷键
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ function M.refresh_list_silently()
|
|||||||
if not current_user or not current_user.name then
|
if not current_user or not current_user.name then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
api.list_memos(current_user.name, current_filter, config.pageSize, nil, function(data)
|
api.list_memos(current_user.name, current_filter, config.page_size, nil, function(data)
|
||||||
M.render_memos(data, false)
|
M.render_memos(data, false)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@@ -223,7 +223,7 @@ function M.show_memos_list(filter)
|
|||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.notify("Fetching memos for " .. user.name .. "...")
|
vim.notify("Fetching memos for " .. user.name .. "...")
|
||||||
end)
|
end)
|
||||||
api.list_memos(user.name, current_filter, config.pageSize, nil, function(data)
|
api.list_memos(user.name, current_filter, config.page_size, nil, function(data)
|
||||||
M.render_memos(data, false)
|
M.render_memos(data, false)
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
@@ -233,9 +233,24 @@ function M.show_memos_list(filter)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function set_keymap(key, command)
|
-- 【修改】这个函数现在可以处理单个按键(字符串)或多个按键(table)
|
||||||
if key and key ~= "" then
|
local function set_keymap(keys, command)
|
||||||
vim.api.nvim_buf_set_keymap(buf_id, "n", key, command, { noremap = true, silent = true })
|
if not keys then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if type(keys) == "table" then
|
||||||
|
-- 如果是 table,就为里面的每个按键都设置映射
|
||||||
|
for _, key in ipairs(keys) do
|
||||||
|
if key and key ~= "" then
|
||||||
|
vim.api.nvim_buf_set_keymap(buf_id, "n", key, command, { noremap = true, silent = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
-- 如果只是字符串,就按原来的方式设置
|
||||||
|
if keys and keys ~= "" then
|
||||||
|
vim.api.nvim_buf_set_keymap(buf_id, "n", keys, command, { noremap = true, silent = true })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -265,7 +280,7 @@ function M.load_next_page()
|
|||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.notify("Loading next page...")
|
vim.notify("Loading next page...")
|
||||||
end)
|
end)
|
||||||
api.list_memos(current_user.name, current_filter, config.pageSize, current_page_token, function(data)
|
api.list_memos(current_user.name, current_filter, config.page_size, current_page_token, function(data)
|
||||||
M.render_memos(data, true)
|
M.render_memos(data, true)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user