Skip to content

Commit

Permalink
fix: vV 모드에서 visual section 영역을 가져올 수 있도록 타이밍 변경
Browse files Browse the repository at this point in the history
- 가져올때 핸들러가 여러개에 매치되어 선택하는 화면에 오게되면, 이미 vV모드가 아닌
n모드가 되면서 텍스트 영역을 가지고 오지 못하게 되는 문제가 있어서
핸들러를 매칭하는 타이밍에 영역을 가져와서 처리
- named parameter 적용
  • Loading branch information
deptno committed Oct 22, 2023
1 parent 74418d0 commit b253387
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
18 changes: 7 additions & 11 deletions lua/lab/gx/handlers_v/github_commit_file_permalink.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
local get_git_root = require('lab/gx/lib/get_git_root')
local get_git_remote_info = require('lab/gx/lib/get_git_remote_info')
local get_directory_of_current_file = require("lab/gx/lib/get_directory_of_current_file")
local get_visual_selection = require('custom.lib.get_visual_selection')
local handler = function(lines, matched)
local M = {}

M.handler = function(args)
local range = args.range
local cwd = get_directory_of_current_file()
local git_root = get_git_root(cwd)
local remote_info = get_git_remote_info(cwd)
Expand All @@ -21,7 +23,6 @@ local handler = function(lines, matched)

local Job = require("plenary.job")
local command = "open"
local range = get_visual_selection()
local url

if range and range[1] then
Expand All @@ -43,14 +44,9 @@ local handler = function(lines, matched)

vim.notify(string.format("Open github permalink: %s", sha1), vim.log.levels.INFO)
end
local match = function(lines)
vim.notify(tostring(get_git_root()))
M.match = function(lines)
return get_git_root()
end
local name = 'github commit file permalink'
M.name = 'github commit file permalink'

return {
handler = handler,
match = match,
name = name,
}
return M
15 changes: 7 additions & 8 deletions lua/lab/gx/handlers_v/grep.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
local trim = require("custom/lib/trim")
local handler = function(lines, matched)
local M = {}

M.handler = function(args)
local matched = M.match(args.lines)
if not pcall(require, 'telescope') then
return vim.notify('fail to require "telescope"')
end

vim.cmd(':Telescope live_grep default_text=' .. matched)
end
local match = function (lines)
M.match = function (lines)
if #lines == 1 then
local line = lines[1]

Expand All @@ -17,10 +20,6 @@ local match = function (lines)

return nil
end
local name = 'grep text'
M.name = 'grep text'

return {
handler = handler,
match = match,
name = name,
}
return M
15 changes: 7 additions & 8 deletions lua/lab/gx/handlers_v/papago.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local map = require("custom/lib/map")
local trim= require("custom/lib/trim")
local handler = function(lines, matched)
local M = {}

M.handler = function(args)
local matched = M.match(args.lines)
local Job = require("plenary.job")
local command = "open"
local url = string.format('https://papago.naver.com/?sk=en&tk=ko&hn=1&st=%s', matched)
Expand All @@ -14,7 +17,7 @@ local handler = function(lines, matched)

vim.notify(string.format("Open papago: %s", matched), vim.log.levels.INFO)
end
local match = function (lines)
M.match = function (lines)
for _, line in ipairs(lines) do
if line:gmatch('%w+') then
return trim(table.concat(map(trim, lines), ' '))
Expand All @@ -23,10 +26,6 @@ local match = function (lines)

return nil
end
local name = 'translator:papago'
M.name = 'translator:papago'

return {
handler = handler,
match = match,
name = name,
}
return M
4 changes: 3 additions & 1 deletion lua/lab/gx/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local get_visual_selection = require "custom/lib/get_visual_selection"
local get_visual_selection_text = require("custom/lib/get_visual_selection_text")
local handle_n = function ()
local line = vim.api.nvim_get_current_line()
Expand Down Expand Up @@ -31,6 +32,7 @@ local handle_n = function ()
end
local handle_vV = function ()
local handlers = require('lab/gx/handlers_v')
local range = get_visual_selection()
local lines = get_visual_selection_text()
local matched_handlers = {}

Expand All @@ -54,7 +56,7 @@ local handle_vV = function ()
end
},
function(selected)
selected.handler(lines, selected.match(lines))
selected.handler({ range = range, lines = lines })
end
)
end
Expand Down

0 comments on commit b253387

Please sign in to comment.