From dd37ad5ce492ad6e35d402bdc2b1dc403c4f409e Mon Sep 17 00:00:00 2001 From: Saeed Rasooli Date: Mon, 4 Jan 2021 10:29:45 +0330 Subject: [PATCH] add settings option "findontype" to allow disabling search-on-type --- internal/action/actions.go | 31 +++++++++++++++++-------------- internal/config/settings.go | 1 + runtime/help/options.md | 5 +++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index ee9c78aa..6bcaaa4f 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -847,21 +847,24 @@ func (h *BufPane) find(useRegex bool) bool { if useRegex { prompt = "Find (regex): " } - InfoBar.Prompt(prompt, "", "Find", func(resp string) { - // Event callback - match, found, _ := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, useRegex) - if found { - h.Cursor.SetSelectionStart(match[0]) - h.Cursor.SetSelectionEnd(match[1]) - h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0] - h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1] - h.Cursor.GotoLoc(match[1]) - } else { - h.Cursor.GotoLoc(h.searchOrig) - h.Cursor.ResetSelection() + var eventCallback func(resp string) + if h.Buf.Settings["findontype"].(bool) { + eventCallback = func(resp string) { + match, found, _ := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, useRegex) + if found { + h.Cursor.SetSelectionStart(match[0]) + h.Cursor.SetSelectionEnd(match[1]) + h.Cursor.OrigSelection[0] = h.Cursor.CurSelection[0] + h.Cursor.OrigSelection[1] = h.Cursor.CurSelection[1] + h.Cursor.GotoLoc(match[1]) + } else { + h.Cursor.GotoLoc(h.searchOrig) + h.Cursor.ResetSelection() + } + h.Relocate() } - h.Relocate() - }, func(resp string, canceled bool) { + } + InfoBar.Prompt(prompt, "", "Find", eventCallback, func(resp string, canceled bool) { // Finished callback if !canceled { match, found, err := h.Buf.FindNext(resp, h.Buf.Start(), h.Buf.End(), h.searchOrig, true, useRegex) diff --git a/internal/config/settings.go b/internal/config/settings.go index 9b000cbe..aa4f1d4c 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -269,6 +269,7 @@ var defaultCommonSettings = map[string]interface{}{ "fastdirty": false, "fileformat": "unix", "filetype": "unknown", + "findontype": true, "ignorecase": true, "indentchar": " ", "keepautoindent": false, diff --git a/runtime/help/options.md b/runtime/help/options.md index 36341b8a..c2c3f853 100644 --- a/runtime/help/options.md +++ b/runtime/help/options.md @@ -159,6 +159,10 @@ Here are the available options: default value: `unknown`. This will be automatically overridden depending on the file you open. +* `findontype`: enable search-on-type in "Find" prompt (pattern input) + + default value: `true` + * `ignorecase`: perform case-insensitive searches. default value: `true` @@ -423,6 +427,7 @@ so that you can see what the formatting should look like. "fastdirty": false, "fileformat": "unix", "filetype": "unknown", + "findontype": true, "ftoptions": true, "ignorecase": false, "indentchar": " ",