Skip to content

Commit aee2e97

Browse files
committed
docs: add new dark colors and optimize path display
- Add new dark_ext3 and dark_ext4 color definitions in gruvboxl.lua - Use dark_ext4 for CursorLine background - Add kide.path module with shorten function for terminal-safe file paths - Various improvements to file path length handling in rg and qflist features - Add stopinsert() to close_window action feat: improve fzy experience with basic fixes and optimizations - Ensure empty lines returns table with meaningful notification - Show sorted/categorized files by path in selection UX properly perform its actual?
1 parent 5a18225 commit aee2e97

5 files changed

Lines changed: 40 additions & 13 deletions

File tree

colors/gruvboxl.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ local dark4_256 = "#7c6f64"
1111

1212
local dark_ext1 = "#2e2e2e"
1313
local dark_ext2 = "#2c2c2c"
14+
local dark_ext3 = "#343434"
15+
local dark_ext4 = "#444040"
1416

1517
local gray_ext1 = "#423e3c"
1618
local gray_ext2 = "#4b4b4b"
@@ -84,7 +86,7 @@ hl({
8486
NvimLightGrey2 = { fg = light2 },
8587

8688
Normal = { fg = light2, bg = dark0 },
87-
CursorLine = { bg = dark_ext1 },
89+
CursorLine = { bg = dark_ext4 },
8890
CursorLineNr = {},
8991
WildMenu = { fg = bright_red, bg = bright_yellow },
9092

lua/kide/fzy.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ local function close_window(state)
7979
if state.closed then
8080
return
8181
end
82+
stopinsert()
8283
state.closed = true
8384
if state.group then
8485
pcall(vim.api.nvim_del_augroup_by_id, state.group)
@@ -219,11 +220,7 @@ end
219220

220221
local function run_lines(lines, opts)
221222
opts = opts or {}
222-
223-
if vim.tbl_isempty(lines) then
224-
vim.notify(opts.empty_message or "没有可供查找的内容", vim.log.levels.INFO)
225-
return
226-
end
223+
lines = lines or {}
227224

228225
stopinsert()
229226

@@ -477,6 +474,7 @@ end
477474

478475
local function qflist_lines()
479476
local lines = {}
477+
local path = require("kide.path")
480478

481479
for idx, item in ipairs(vim.fn.getqflist()) do
482480
if item.valid == 1 then
@@ -494,7 +492,7 @@ local function qflist_lines()
494492
lines,
495493
("%d\t%s:%d:%d\t%s"):format(
496494
idx,
497-
vim.fn.fnamemodify(filename, ":~:."),
495+
path.shorten(vim.fn.fnamemodify(filename, ":~:."), 40),
498496
item.lnum or 1,
499497
item.col or 1,
500498
text

lua/kide/path.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local M = {}
2+
3+
function M.shorten(filename, limit)
4+
filename = filename or ""
5+
limit = limit or 40
6+
7+
if filename == "" or vim.fn.strdisplaywidth(filename) <= limit then
8+
return filename
9+
end
10+
11+
local shortened = vim.fn.pathshorten(filename)
12+
if shortened ~= "" then
13+
return shortened
14+
end
15+
16+
return filename
17+
end
18+
19+
return M

lua/kide/rg.lua

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ local count_ns = vim.api.nvim_create_namespace("kide_rg_live_grep_count")
66
local preview_ns = vim.api.nvim_create_namespace("kide_rg_live_grep_preview")
77
local session = 0
88
local uv = vim.uv or vim.loop
9+
local path_utils = require("kide.path")
10+
11+
local file_path_limit = 40
912

1013
local function stopinsert()
1114
if vim.api.nvim_get_mode().mode == "i" then
@@ -481,11 +484,11 @@ local function parse_json(line)
481484
end
482485

483486
local data = item.data or {}
484-
local path = data.path or {}
487+
local result_path = data.path or {}
485488
local lines = data.lines or {}
486489
local submatches = data.submatches or {}
487490
local first_match = submatches[1] or {}
488-
local filename = path.text
491+
local filename = result_path.text
489492
local lnum = data.line_number
490493
if not filename or not lnum then
491494
return nil
@@ -495,7 +498,8 @@ local function parse_json(line)
495498
local text = lines.text or ""
496499
text = text:gsub("[\r\n]+$", "")
497500
local col = (first_match.start or 0) + 1
498-
local prefix = ("%s:%d:%d:"):format(filename, lnum, col)
501+
local display_file = path_utils.shorten(filename, file_path_limit)
502+
local prefix = ("%s:%d:%d:"):format(display_file, lnum, col)
499503
local matches = {}
500504
for _, match in ipairs(submatches) do
501505
if match.start and match["end"] then
@@ -508,10 +512,11 @@ local function parse_json(line)
508512

509513
return {
510514
file = filename,
515+
display_file = display_file,
511516
lnum = lnum,
512517
col = col,
513518
text = text,
514-
file_len = #filename,
519+
file_len = #display_file,
515520
prefix_len = #prefix,
516521
matches = matches,
517522
display = prefix .. text,
@@ -741,7 +746,8 @@ local function truncate_text(text, max_width)
741746
end
742747

743748
local function fzy_item_line(item, index, max_width)
744-
local line = ("%04d %s:%d:%d: %s"):format(index, item.file, item.lnum, item.col, terminal_safe_text(item.text))
749+
local display_file = item.display_file or path_utils.shorten(item.file, file_path_limit)
750+
local line = ("%04d %s:%d:%d: %s"):format(index, display_file, item.lnum, item.col, terminal_safe_text(item.text))
745751
return truncate_text(line, max_width)
746752
end
747753

lua/options.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local fn = vim.fn
22
local opt = vim.opt
33
local o = vim.o
4+
local path = require("kide.path")
45

56
vim.opt.statusline = "%!v:lua.require('kide.stl').statusline()"
67

@@ -101,7 +102,7 @@ function _G.qftf(info)
101102
else
102103
items = fn.getloclist(info.winid, { id = info.id, items = 0 }).items
103104
end
104-
local limit = 44
105+
local limit = 40
105106
local fnameFmt1, fnameFmt2 = "%-" .. limit .. "s", "…%." .. (limit - 1) .. "s"
106107
local validFmt = "%s │%5d:%-3d│%s %s"
107108
local fmt = true
@@ -129,6 +130,7 @@ function _G.qftf(info)
129130
fmt = false
130131
else
131132
fname = vim.fn.fnamemodify(fname, ":.")
133+
fname = path.shorten(fname, limit)
132134
end
133135
-- char in fname may occur more than 1 width, ignore this issue in order to keep performance
134136
if fmt then

0 commit comments

Comments
 (0)