SmiteshP / nvim-navbuddy

A simple popup display that provides breadcrumbs feature using LSP server
Apache License 2.0
770 stars 30 forks source link

Feat: Add possibility to move elements up and down #18

Closed zbindenren closed 1 year ago

zbindenren commented 1 year ago

I am not sure if this is possible, but it would be great for refactoring, to navigate a buffer with navbuddy and move functions, structs etc. up and down.

SmiteshP commented 1 year ago

This is a very interesting idea!! This should definitely be possible to do. Although this might be a little tricky to implement, I can see there being lots of corners cases to be handled. Will definitely try it though

SmiteshP commented 1 year ago

Added the move up and down actions. Although I implemented it only for nodes on different lines with no overlaps in lines. I am still pleased with how it works right now.

SmiteshP commented 1 year ago

Had tried adding code to move the comments (above the node) as well with the node, but had trouble writting code to consistently identify comments lines. If any one has any ideas about this do let me know.

This was the best attempt I had made using Comment.nvim to detect if entire line above the node is comment or not

local utils = require("Comment.utils")
local config = require("Comment.config")

local function isComment()
    local lcs, rcs = utils.parse_cstr(config:get(), {
        ctype = utils.ctype.linewise,
        -- ctype = utils.ctype.blockwise,
        cmode = utils.cmode.uncomment,
        cmotion = utils.cmotion.line,
        range = {
            srow = 0,
            scol = 0,
            erow = 0,
            ecol = 1
        }
    })

    local check_comment = utils.is_commented(lcs, rcs, config:get().padding)

       -- This is comment
    local row, _ = unpack(vim.api.nvim_win_get_cursor(0))
    local lines = vim.api.nvim_buf_get_lines(0, row-1, row, false)
    print(check_comment(lines[1]))
end
zbindenren commented 1 year ago

Added the move up and down actions. Although I implemented it only for nodes on different lines with no overlaps in lines. I am still pleased with how it works right now.

Feature is working for me, so I am closing issue.

THX.