Comments (41)
@martin-braun agreed, however i'll try to make the function small, i'll push today
from ui.
local M = {}
function moveItemRight(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
print(v)
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == #originTbl + 1 then
table.insert(originTbl, 1, n)
else
table.insert(originTbl, index + 1, n)
end
return originTbl
end
function moveItemLeft(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == 1 then
table.insert(originTbl, #originTbl + 1, n)
else
table.insert(originTbl, index - 1, n)
end
return originTbl
end
M.move_buf_left = function()
local bufs = vim.t.bufs
bufs = moveItemLeft(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
M.move_buf_right = function()
local bufs = vim.t.bufs
bufs = moveItemRight(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
return M
from ui.
@siduck it's not on main yet, is it?
oh oops! i totally forgot about it, i'll push it in main tomorrow. A lil busy these days!
from ui.
@kola-web i tested it now, it works well
vid.mp4
from ui.
ok i'll add some functions for this in sept
from ui.
Thank you, I am willing to actively cooperate with the test
from ui.
I saw this in an update today, very pleasant surprise
from ui.
Thank you, I am willing to actively cooperate with the test
or you can make your own functions for this :))
from ui.
current tab buffer numbers are stored in a table called vim.t.bufs
from ui.
So in the above image, init.lua is at index 1 , stylua at index 2 and so on.
gitignore file's buffer name is 5
from ui.
local move_buf_left = function()
local bufs = vim.t.bufs
for index, bufnr in ipairs(bufs) do
if bufnr == vim.api.nvim_get_current_buf() then
if index == 1 then
bufs[1] = bufs[#bufs]
bufs[#bufs] = bufnr
else
bufs[index] = bufs[index - 1]
bufs[index - 1] = bufnr
end
break
end
end
vim.t.bufs = bufs
vim.cmd "redrawtabline"
end
make a command out of it & test it
from ui.
i will clean the function later
from ui.
ok,I'll give it a try
from ui.
vim.t.bufs not fond
from ui.
vim.t.bufs not fond
do you use nvchad's tabufline? and what did you do till now
from ui.
I bound it to a keymap
from ui.
I will study again
from ui.
vim.t.bufs not fond
impossible
from ui.
Can be used normally
local M = {}
function moveAllEleTest(originTbl, n)
if type(originTbl) ~= "table" then
return
end
if #originTbl == 0 then
return
end
local newTbl = {}
for i = 1, #originTbl do
newTbl[i] = originTbl[(n - 1 + i) % #originTbl + 1]
end
return newTbl
end
M.move_buf_left = function()
local bufs = vim.t.bufs
bufs = moveAllEleTest(bufs, 1)
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
M.move_buf_right = function()
local bufs = vim.t.bufs
bufs = moveAllEleTest(bufs, -1)
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
return M
from ui.
hmm then if it works for u, i'll close this issue.
from ui.
ok
from ui.
thank you
from ui.
nice!
from ui.
@siduck I think it would be nice to implement @kola-web's implementation right into NvChad/ui
, so it's easier to map this functionality in the own custom tabufline
mappings.
(I can make a PR, if you like, let me know. I would also like to suggest to re-open this issue for the implementation of such)
from ui.
@siduck it's not on main yet, is it?
from ui.
@siduck No worries :) Thanks a lot!
from ui.
really sorry for the delay, its been added now!
from ui.
@siduck Thanks, however, the logic still misbehaves on the edges when trying to move further after it's rolling over:
M.tabufline = {
n = {
["<C-j>"] = {
function()
require("nvchad_ui.tabufline").tabuflineNext()
end, "goto next buffer",
},
["<C-S-j>"] = {
function()
require("nvchad_ui.tabufline").move_buf(1)
end, "move buffer forward",
},
["<C-k>"] = {
function()
require("nvchad_ui.tabufline").tabuflinePrev()
end,
"goto prev buffer",
},
["<C-S-k>"] = {
function()
require("nvchad_ui.tabufline").move_buf(-1)
end,
"move buffer backwards",
},
["<leader>c"] = {
function()
require("nvchad_ui.tabufline").close_buffer()
end,
"close buffer",
},
},
}
You cannot just do if i == 1 or i == #bufs then
and move it to a different side, because you have to take the direction into consideration.
Instead use if n < 0 and i == 1 or n > 0 and i == #bufs then
and it will work for -1 and 1
.
However, if you choose to provide a variable n
as an input, you have to account for things like -2
or less and 2
or more on the edges, so simply moving it to the opposite side would not behave correctly.
My suggestion was to simply implement two functions instead (tabuflineMoveNext()
and tabuflineMovePrev()
). Then you would not face this inconsistency at all and it would even play nicely with tabuflineNext()
and tabuflinePrev()
when it comes to name consistencies.
Please tell me what you think. :)
from ui.
@martin-braun hmm i thought it was normal to swap out indexes 1
and the last value
. I made this function based on this function #8 (comment)
from ui.
@siduck @martin-braun This is the move method I'm using now, I don't know how to make this streamlined without this problem
local M = {}
function moveItemRight(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
print(v)
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == #originTbl + 1 then
table.insert(originTbl, 1, n)
else
table.insert(originTbl, index + 1, n)
end
return originTbl
end
function moveItemLeft(originTbl, n)
local index = nil
for k, v in ipairs(originTbl) do
if v == n then
index = k
end
end
table.remove(originTbl, index)
if index == 1 then
table.insert(originTbl, #originTbl + 1, n)
else
table.insert(originTbl, index - 1, n)
end
return originTbl
end
M.move_buf_left = function()
local bufs = vim.t.bufs
bufs = moveItemLeft(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
M.move_buf_right = function()
local bufs = vim.t.bufs
bufs = moveItemRight(bufs, vim.api.nvim_get_current_buf())
vim.t.bufs = bufs
vim.cmd("redrawtabline")
end
return M
from ui.
whats the problem? @kola-web
from ui.
whats the problem? @kola-web
Left and right movements are not in sequence
from ui.
oh yea, i probably forgot to push the fix. Will catch up tonight!
from ui.
thanks for your effort
from ui.
@martin-braun @kola-web ok it should be fixed now!
from ui.
Here are the three tabs that are initially opened
Called in a loop require("nvchad_ui.tabufline").move_buf(1) will be presented separately as
The order is out of order
from ui.
@siduck Is it possible to reopen this question
from ui.
@kola-web why loop?
from ui.
repeated calls require("nvchad_ui.tabufline").move_buf(1) Tab order is shuffled
from ui.
repeated calls require("nvchad_ui.tabufline").move_buf(1) Tab order is shuffled
you cant use it that way at the moment
from ui.
Thanks a lot for your work, I'll test it again
from ui.
Related Issues (20)
- Buffer that are hiding because 4 or 5 buffer didn't get active when the current buffer is change
- Telescope hidden term picker opens a new terminal instead of the selected terminal
- Bugs when Interacting with mbbill/undotree HOT 2
- Opening neovim in / directory causes the status line to error. HOT 5
- "kylechui/nvim-surround" bricks nvcheatsheet
- Statusline overide_modules not working after v2.5 HOT 6
- Error when selecting a terminal from the terminal picker
- Disable or Set order and modules for status line in v2.0 HOT 2
- terminal error on msys2 windows HOT 2
- git not following diagnostic color on changing the position of diagnostic in statusline
- Setting of sp or vsp terminal size not work after migrate to v2.5 HOT 3
- Disable buffer close X icon? HOT 2
- Can't use `Ctrl + i` to navigate forward through jump list HOT 4
- Tabufline treeOffset doesn't align with nvim tree when it's on the right side HOT 2
- Can't close NvChadCheatsheet when no other buffers are open HOT 1
- Cursor seems to be in the wrong position in nvterm? HOT 8
- NVim exits without any message when I scroll the list of themes HOT 7
- Add support for lazy.nvim defined keymaps in cheatsheet? HOT 9
- Insert mode signature_help not work? HOT 1
- Allow name of modified buffers to be styled HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ui.