Added Ctrl+C and search previous command
This commit is contained in:
parent
9267fc92a7
commit
a1df99860e
|
|
@ -164,6 +164,32 @@ func (cm *CommandMapping) RegisterViewCommands() {
|
|||
}
|
||||
}
|
||||
})
|
||||
cm.Define("search-prev", "Goto the previous cell", "", func(ctx *CommandContext) error {
|
||||
if ctx.session.LastSearch == nil {
|
||||
ctx.Session().Commands.Eval(ctx, "search")
|
||||
}
|
||||
|
||||
height, width := ctx.ModelVC().Model().Dimensions()
|
||||
startX, startY := ctx.Frame().Grid().CellPosition()
|
||||
cellX, cellY := startX, startY
|
||||
|
||||
for {
|
||||
cellX--
|
||||
if cellY < 0 {
|
||||
cellX = width - 1
|
||||
cellY--
|
||||
if cellY < 0 {
|
||||
cellY = height - 1
|
||||
}
|
||||
}
|
||||
if ctx.session.LastSearch.MatchString(ctx.ModelVC().Model().CellValue(cellY, cellX)) {
|
||||
ctx.Frame().Grid().MoveTo(cellX, cellY)
|
||||
return nil
|
||||
} else if (cellX == startX) && (cellY == startY) {
|
||||
return errors.New("No match found")
|
||||
}
|
||||
}
|
||||
})
|
||||
cm.Define("x-replace", "Performs a search and replace", "", func(ctx *CommandContext) error {
|
||||
if len(ctx.Args()) != 2 {
|
||||
return errors.New("Usage: x-replace MATCH REPLACEMENT")
|
||||
|
|
@ -482,6 +508,7 @@ func (cm *CommandMapping) RegisterViewKeyBindings() {
|
|||
cm.MapKey(ui.KeyCtrlK, cm.Command("row-bottom"))
|
||||
cm.MapKey(ui.KeyCtrlJ, cm.Command("col-left"))
|
||||
cm.MapKey(ui.KeyCtrlL, cm.Command("col-right"))
|
||||
cm.MapKey(ui.KeyCtrlC, cm.Command("quit"))
|
||||
|
||||
cm.MapKey(ui.KeyArrowUp, cm.Command("move-up"))
|
||||
cm.MapKey(ui.KeyArrowDown, cm.Command("move-down"))
|
||||
|
|
@ -498,6 +525,7 @@ func (cm *CommandMapping) RegisterViewKeyBindings() {
|
|||
|
||||
cm.MapKey('/', cm.Command("search"))
|
||||
cm.MapKey('n', cm.Command("search-next"))
|
||||
cm.MapKey('N', cm.Command("search-prev"))
|
||||
|
||||
cm.MapKey('y', cm.Command("yank"))
|
||||
cm.MapKey('p', cm.Command("paste"))
|
||||
|
|
|
|||
Loading…
Reference in a new issue