Giter VIP home page Giter VIP logo

Comments (41)

siduck avatar siduck commented on July 18, 2024 3

@martin-braun agreed, however i'll try to make the function small, i'll push today

from ui.

kola-web avatar kola-web commented on July 18, 2024 2
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 avatar siduck commented on July 18, 2024 1

@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.

siduck avatar siduck commented on July 18, 2024 1

@kola-web i tested it now, it works well

vid.mp4

from ui.

siduck avatar siduck commented on July 18, 2024

ok i'll add some functions for this in sept

from ui.

kola-web avatar kola-web commented on July 18, 2024

Thank you, I am willing to actively cooperate with the test

from ui.

kola-web avatar kola-web commented on July 18, 2024

image
I saw this in an update today, very pleasant surprise

from ui.

siduck avatar siduck commented on July 18, 2024

Thank you, I am willing to actively cooperate with the test

or you can make your own functions for this :))

from ui.

siduck avatar siduck commented on July 18, 2024

image

current tab buffer numbers are stored in a table called vim.t.bufs

from ui.

siduck avatar siduck commented on July 18, 2024

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.

siduck avatar siduck commented on July 18, 2024
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.

siduck avatar siduck commented on July 18, 2024

i will clean the function later

from ui.

kola-web avatar kola-web commented on July 18, 2024

ok,I'll give it a try

from ui.

kola-web avatar kola-web commented on July 18, 2024

vim.t.bufs not fond

from ui.

siduck avatar siduck commented on July 18, 2024

vim.t.bufs not fond

do you use nvchad's tabufline? and what did you do till now

from ui.

kola-web avatar kola-web commented on July 18, 2024

I bound it to a keymap

from ui.

kola-web avatar kola-web commented on July 18, 2024

I will study again

from ui.

siduck avatar siduck commented on July 18, 2024

vim.t.bufs not fond

impossible

imageimage

from ui.

kola-web avatar kola-web commented on July 18, 2024

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.

siduck avatar siduck commented on July 18, 2024

hmm then if it works for u, i'll close this issue.

from ui.

kola-web avatar kola-web commented on July 18, 2024

ok

from ui.

kola-web avatar kola-web commented on July 18, 2024

thank you

from ui.

siduck avatar siduck commented on July 18, 2024

nice!

from ui.

martin-braun avatar martin-braun commented on July 18, 2024

@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.

martin-braun avatar martin-braun commented on July 18, 2024

@siduck it's not on main yet, is it?

from ui.

martin-braun avatar martin-braun commented on July 18, 2024

@siduck No worries :) Thanks a lot!

from ui.

siduck avatar siduck commented on July 18, 2024

really sorry for the delay, its been added now!

954a07f

@martin-braun @kola-web

from ui.

martin-braun avatar martin-braun commented on July 18, 2024

@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",
        },
    },
}

2022-10-30 2 17 23 PM

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.

siduck avatar siduck commented on July 18, 2024

@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.

kola-web avatar kola-web commented on July 18, 2024

@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.

siduck avatar siduck commented on July 18, 2024

whats the problem? @kola-web

from ui.

kola-web avatar kola-web commented on July 18, 2024

whats the problem? @kola-web

Left and right movements are not in sequence

from ui.

siduck avatar siduck commented on July 18, 2024

oh yea, i probably forgot to push the fix. Will catch up tonight!

from ui.

kola-web avatar kola-web commented on July 18, 2024

thanks for your effort

from ui.

siduck avatar siduck commented on July 18, 2024

@martin-braun @kola-web ok it should be fixed now!

from ui.

kola-web avatar kola-web commented on July 18, 2024

Here are the three tabs that are initially opened
image
Called in a loop require("nvchad_ui.tabufline").move_buf(1) will be presented separately as
image
image

The order is out of order

from ui.

kola-web avatar kola-web commented on July 18, 2024

@siduck Is it possible to reopen this question

from ui.

siduck avatar siduck commented on July 18, 2024

@kola-web why loop?

from ui.

kola-web avatar kola-web commented on July 18, 2024

repeated calls require("nvchad_ui.tabufline").move_buf(1) Tab order is shuffled

from ui.

siduck avatar siduck commented on July 18, 2024

repeated calls require("nvchad_ui.tabufline").move_buf(1) Tab order is shuffled

you cant use it that way at the moment

from ui.

kola-web avatar kola-web commented on July 18, 2024

Thanks a lot for your work, I'll test it again

from ui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.