From ab8510291ecd397bf5327a23e921076e77dc5278 Mon Sep 17 00:00:00 2001 From: rxi Date: Fri, 1 May 2020 10:21:57 +0100 Subject: [PATCH] Added find-replace:select-next, bound to ctrl+d by default --- data/core/commands/findreplace.lua | 16 ++++++++++++++-- data/core/keymap.lua | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/data/core/commands/findreplace.lua b/data/core/commands/findreplace.lua index ba4c6120..3aff5f33 100644 --- a/data/core/commands/findreplace.lua +++ b/data/core/commands/findreplace.lua @@ -1,7 +1,5 @@ local core = require "core" -local common = require "core.common" local command = require "core.command" -local config = require "core.config" local search = require "core.doc.search" local DocView = require "core.docview" @@ -85,6 +83,20 @@ local function replace(pattern_escape) end +local function has_selection() + return core.active_view:is(DocView) + and core.active_view.doc:has_selection() +end + +command.add(has_selection, { + ["find-replace:select-next"] = function() + local l1, c1, l2, c2 = doc():get_selection(true) + local text = doc():get_text(l1, c1, l2, c2) + local l1, c1, l2, c2 = search.find(doc(), l2, c2, text, { wrap = true }) + doc():set_selection(l2, c2, l1, c1) + end +}) + command.add("core.docview", { ["find-replace:find"] = function() find("Find Text", function(doc, line, col, text) diff --git a/data/core/keymap.lua b/data/core/keymap.lua index e506d24f..e3ec74c5 100644 --- a/data/core/keymap.lua +++ b/data/core/keymap.lua @@ -140,7 +140,7 @@ keymap.add { ["ctrl+shift+return"] = "doc:newline-above", ["ctrl+j"] = "doc:join-lines", ["ctrl+a"] = "doc:select-all", - ["ctrl+d"] = "doc:select-word", + ["ctrl+d"] = { "find-replace:select-next", "doc:select-word" }, ["ctrl+l"] = "doc:select-lines", ["ctrl+/"] = "doc:toggle-line-comments", ["ctrl+up"] = "doc:move-lines-up",