Merge pull request #694 from adamharrison/fix-context-menu
Added in cut, copy and paste to the context menu, amongst other things.
This commit is contained in:
commit
1b22c85dd5
|
@ -41,6 +41,9 @@ function command.get_all_valid()
|
|||
return res
|
||||
end
|
||||
|
||||
function command.is_valid(name, ...)
|
||||
return command.map[name] and command.map[name].predicate(...)
|
||||
end
|
||||
|
||||
local function perform(name, ...)
|
||||
local cmd = command.map[name]
|
||||
|
|
|
@ -92,6 +92,21 @@ local function set_cursor(x, y, snap_type)
|
|||
core.blink_reset()
|
||||
end
|
||||
|
||||
local selection_commands = {
|
||||
["doc:cut"] = function()
|
||||
cut_or_copy(true)
|
||||
end,
|
||||
|
||||
["doc:copy"] = function()
|
||||
cut_or_copy(false)
|
||||
end,
|
||||
|
||||
["doc:select-none"] = function()
|
||||
local line, col = doc():get_selection()
|
||||
doc():set_selection(line, col)
|
||||
end
|
||||
}
|
||||
|
||||
local commands = {
|
||||
["doc:undo"] = function()
|
||||
doc():undo()
|
||||
|
@ -101,14 +116,6 @@ local commands = {
|
|||
doc():redo()
|
||||
end,
|
||||
|
||||
["doc:cut"] = function()
|
||||
cut_or_copy(true)
|
||||
end,
|
||||
|
||||
["doc:copy"] = function()
|
||||
cut_or_copy(false)
|
||||
end,
|
||||
|
||||
["doc:paste"] = function()
|
||||
local clipboard = system.get_clipboard()
|
||||
-- If the clipboard has changed since our last look, use that instead
|
||||
|
@ -173,11 +180,6 @@ local commands = {
|
|||
doc():set_selection(1, 1, math.huge, math.huge)
|
||||
end,
|
||||
|
||||
["doc:select-none"] = function()
|
||||
local line, col = doc():get_selection()
|
||||
doc():set_selection(line, col)
|
||||
end,
|
||||
|
||||
["doc:select-lines"] = function()
|
||||
for idx, line1, _, line2 in doc():get_selections(true) do
|
||||
append_line_if_last_line(line2)
|
||||
|
@ -481,3 +483,6 @@ commands["doc:move-to-next-char"] = function()
|
|||
end
|
||||
|
||||
command.add("core.docview", commands)
|
||||
command.add(function()
|
||||
return core.active_view:is(DocView) and core.active_view.doc:has_any_selection()
|
||||
end ,selection_commands)
|
||||
|
|
|
@ -66,12 +66,16 @@ function ContextMenu:show(x, y)
|
|||
for _, items in ipairs(self.itemset) do
|
||||
if items.predicate(x, y) then
|
||||
items_list.width = math.max(items_list.width, items.items.width)
|
||||
items_list.height = items_list.height + items.items.height
|
||||
items_list.height = items_list.height
|
||||
for _, subitems in ipairs(items.items) do
|
||||
if not subitems.command or command.is_valid(subitems.command) then
|
||||
local lw, lh = get_item_size(subitems)
|
||||
items_list.height = items_list.height + lh
|
||||
table.insert(items_list, subitems)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #items_list > 0 then
|
||||
self.items = items_list
|
||||
|
|
|
@ -149,6 +149,13 @@ function Doc:has_selection()
|
|||
return line1 ~= line2 or col1 ~= col2
|
||||
end
|
||||
|
||||
function Doc:has_any_selection()
|
||||
for idx, line1, col1, line2, col2 in self:get_selections() do
|
||||
if line1 ~= line2 or col1 ~= col2 then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function Doc:sanitize_selection()
|
||||
for idx, line1, col1, line2, col2 in self:get_selections() do
|
||||
self:set_selections(idx, line1, col1, line2, col2)
|
||||
|
|
|
@ -900,9 +900,7 @@ function RootView:on_mouse_pressed(button, x, y, clicks)
|
|||
end
|
||||
elseif not self.dragged_node then -- avoid sending on_mouse_pressed events when dragging tabs
|
||||
core.set_active_view(node.active_view)
|
||||
if not self.on_view_mouse_pressed(button, x, y, clicks) then
|
||||
return node.active_view:on_mouse_pressed(button, x, y, clicks)
|
||||
end
|
||||
return self.on_view_mouse_pressed(button, x, y, clicks) or node.active_view:on_mouse_pressed(button, x, y, clicks)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -62,15 +62,15 @@ menu:register("core.logview", {
|
|||
|
||||
if require("plugins.scale") then
|
||||
menu:register("core.docview", {
|
||||
{ text = "Cut", command = "doc:cut" },
|
||||
{ text = "Copy", command = "doc:copy" },
|
||||
{ text = "Paste", command = "doc:paste" },
|
||||
{ text = "Font +", command = "scale:increase" },
|
||||
{ text = "Font -", command = "scale:decrease" },
|
||||
{ text = "Font Reset", command = "scale:reset" },
|
||||
ContextMenu.DIVIDER,
|
||||
{ text = "Find", command = "find-replace:find" },
|
||||
{ text = "Replace", command = "find-replace:replace" },
|
||||
ContextMenu.DIVIDER,
|
||||
{ text = "Find Pattern", command = "find-replace:find-pattern" },
|
||||
{ text = "Replace Pattern", command = "find-replace:replace-pattern" },
|
||||
{ text = "Replace", command = "find-replace:replace" }
|
||||
})
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue