Skip to content

Commit

Permalink
feat: reorder tabs with mouse
Browse files Browse the repository at this point in the history
Depends on neovim/neovim##23947
  • Loading branch information
willothy committed Jun 10, 2023
1 parent 504989a commit abba927
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 2 deletions.
118 changes: 118 additions & 0 deletions devsession
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
let SessionLoad = 1
let s:so_save = &g:so | let s:siso_save = &g:siso | setg so=0 siso=0 | setl so=-1 siso=-1
let v:this_session=expand("<sfile>:p")
silent only
silent tabonly
cd ~/projects/lua/cokeline
if expand('%') == '' && !&modified && line('$') <= 1 && getline(1) == ''
let s:wipebuf = bufnr('%')
endif
let s:shortmess_save = &shortmess
if &shortmess =~ 'A'
set shortmess=aoOA
else
set shortmess=aoO
endif
badd +144 lua/cokeline/hover.lua
badd +89 lua/cokeline/handlers.lua
badd +349 lua/cokeline/buffers.lua
badd +1 lua/cokeline/mappings.lua
argglobal
%argdel
$argadd lua/cokeline/hover.lua
edit lua/cokeline/hover.lua
wincmd t
let s:save_winminheight = &winminheight
let s:save_winminwidth = &winminwidth
set winminheight=0
set winheight=1
set winminwidth=0
set winwidth=1
argglobal
balt lua/cokeline/mappings.lua
setlocal fdm=manual
setlocal fde=0
setlocal fmr={{{,}}}
setlocal fdi=#
setlocal fdl=99
setlocal fml=1
setlocal fdn=20
setlocal fen
silent! normal! zE
9,10fold
15,16fold
23,24fold
21,25fold
29,30fold
27,31fold
34,35fold
39,40fold
37,41fold
13,42fold
47,48fold
51,56fold
60,66fold
71,72fold
76,77fold
75,78fold
79,80fold
74,81fold
69,83fold
85,87fold
91,92fold
96,97fold
95,98fold
99,100fold
94,101fold
103,107fold
50,109fold
112,113fold
117,118fold
116,119fold
120,121fold
115,122fold
110,125fold
45,127fold
158,158fold
162,163fold
172,173fold
176,177fold
175,178fold
179,180fold
170,182fold
168,184fold
185,187fold
167,189fold
166,190fold
161,191fold
let &fdl = &fdl
161
normal! zo
166
normal! zo
167
normal! zo
let s:l = 144 - ((16 * winheight(0) + 22) / 45)
if s:l < 1 | let s:l = 1 | endif
keepjumps exe s:l
normal! zt
keepjumps 144
normal! 07|
tabnext 1
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 && getbufvar(s:wipebuf, '&buftype') isnot# 'terminal'
silent exe 'bwipe ' . s:wipebuf
endif
unlet! s:wipebuf
set winheight=1 winwidth=20
let &shortmess = s:shortmess_save
let &winminheight = s:save_winminheight
let &winminwidth = s:save_winminwidth
let s:sx = expand("<sfile>:p:r")."x.vim"
if filereadable(s:sx)
exe "source " . fnameescape(s:sx)
endif
let &g:so = s:so_save | let &g:siso = s:siso_save
nohlsearch
doautoall SessionLoadPost
unlet SessionLoad
" vim: set ft=vim :
57 changes: 55 additions & 2 deletions lua/cokeline/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,67 @@ local function on_hover(current)
last_position = current
end

local function on_drag(pos)
if pos.dragging == "l" then
-- TODO: handle drag events
local current = M.get_current(pos.screencol)
if not current or current.kind ~= "buffer" then
return
end

if not _G.cokeline.__dragging then
local buf = buffers.get_buffer(current.bufnr)
if not buf then
return
end
_G.cokeline.__dragging = {
bufnr = current.bufnr,
index = buf._valid_index,
}
end
if _G.cokeline.__dragging.bufnr == current.bufnr then
return
end
if _G.cokeline.__dragging.bufnr then
local buf = buffers.get_buffer(_G.cokeline.__dragging.bufnr)
if buf and current.index then
buffers.move_buffer(
buf,
buffers.get_buffer(current.bufnr)._valid_index
)
end
end
end
end

function M.setup()
if version.minor < 8 then
return
end

vim.api.nvim_create_autocmd("MouseMoved", {
vim.api.nvim_create_autocmd("MouseMove", {
callback = function(ev)
on_hover(ev.data)
if ev.data.dragging then
local hov = M.hovered()
if hov ~= nil then
local buf = buffers.get_buffer(hov.bufnr)
if buf then
buf.is_hovered = false
end
if hov.kind == "buffer" then
if buf and hov.on_mouse_leave then
hov.on_mouse_leave(buf)
end
elseif hov.on_mouse_leave then
hov.on_mouse_leave()
end
_G.cokeline.__hovered = nil
end
on_drag(ev.data)
else
_G.cokeline.__dragging = nil
on_hover(ev.data)
end
return "<MouseMove>"
end,
})
Expand Down

0 comments on commit abba927

Please sign in to comment.