Merge branch 'PR-find-on-type' of https://github.com/ilius/micro into ilius-PR-find-on-type

This commit is contained in:
Zachary Yedidia
2021-01-27 13:48:01 -05:00
3 changed files with 23 additions and 14 deletions

View File

@@ -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)

View File

@@ -269,6 +269,7 @@ var defaultCommonSettings = map[string]interface{}{
"fastdirty": false,
"fileformat": "unix",
"filetype": "unknown",
"findontype": true,
"ignorecase": true,
"indentchar": " ",
"keepautoindent": false,

View File

@@ -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": " ",