Started working on opening down and right
This commit is contained in:
parent
3a7c4d764b
commit
b658536ad1
|
|
@ -1,8 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/lmika/ted/ui"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/lmika/ted/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -97,13 +99,55 @@ func (cm *CommandMapping) RegisterViewCommands() {
|
||||||
_, cellY := grid.CellPosition()
|
_, cellY := grid.CellPosition()
|
||||||
grid.MoveTo(0, cellY)
|
grid.MoveTo(0, cellY)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
cm.Define("col-right", "Moves the cursor to the right-most column", "", gridNavOperation(func(grid *ui.Grid) {
|
cm.Define("col-right", "Moves the cursor to the right-most column", "", gridNavOperation(func(grid *ui.Grid) {
|
||||||
_, cellY := grid.CellPosition()
|
_, cellY := grid.CellPosition()
|
||||||
dimX, _ := grid.Model().Dimensions()
|
dimX, _ := grid.Model().Dimensions()
|
||||||
grid.MoveTo(dimX-1, cellY)
|
grid.MoveTo(dimX-1, cellY)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
cm.Define("open-right", "Inserts a column to the right of the curser", "", func(ctx *CommandContext) error {
|
||||||
|
grid := ctx.Frame().Grid()
|
||||||
|
cellX, _ := grid.CellPosition()
|
||||||
|
|
||||||
|
if rwModel, isRwModel := ctx.Session().Model.(RWModel); isRwModel {
|
||||||
|
height, width := rwModel.Dimensions()
|
||||||
|
if cellX == width-1 {
|
||||||
|
rwModel.Resize(height, width+1)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New("model is read-only")
|
||||||
|
})
|
||||||
|
|
||||||
|
cm.Define("open-down", "Inserts a row below the curser", "", func(ctx *CommandContext) error {
|
||||||
|
grid := ctx.Frame().Grid()
|
||||||
|
_, cellY := grid.CellPosition()
|
||||||
|
|
||||||
|
if rwModel, isRwModel := ctx.Session().Model.(RWModel); isRwModel {
|
||||||
|
height, width := rwModel.Dimensions()
|
||||||
|
if cellY == height-1 {
|
||||||
|
rwModel.Resize(height+1, width)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.New("model is read-only")
|
||||||
|
})
|
||||||
|
|
||||||
|
cm.Define("append", "Inserts a row below the curser", "", func(ctx *CommandContext) error {
|
||||||
|
if err := ctx.Session().Commands.Eval(ctx, "open-down"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := ctx.Session().Commands.Eval(ctx, "move-down"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Session().UIManager.Redraw()
|
||||||
|
|
||||||
|
return ctx.Session().Commands.Eval(ctx, "set-cell")
|
||||||
|
})
|
||||||
|
|
||||||
cm.Define("enter-command", "Enter command", "", func(ctx *CommandContext) error {
|
cm.Define("enter-command", "Enter command", "", func(ctx *CommandContext) error {
|
||||||
ctx.Frame().Prompt(":", func(res string) {
|
ctx.Frame().Prompt(":", func(res string) {
|
||||||
cm.DoEval(ctx, res)
|
cm.DoEval(ctx, res)
|
||||||
|
|
@ -149,7 +193,6 @@ func (cm *CommandMapping) RegisterViewCommands() {
|
||||||
return cm.Eval(ctx, "quit")
|
return cm.Eval(ctx, "quit")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// Aliases
|
// Aliases
|
||||||
cm.Commands["w"] = cm.Command("save")
|
cm.Commands["w"] = cm.Command("save")
|
||||||
cm.Commands["q"] = cm.Command("quit")
|
cm.Commands["q"] = cm.Command("quit")
|
||||||
|
|
@ -178,6 +221,8 @@ func (cm *CommandMapping) RegisterViewKeyBindings() {
|
||||||
|
|
||||||
cm.MapKey('e', cm.Command("set-cell"))
|
cm.MapKey('e', cm.Command("set-cell"))
|
||||||
|
|
||||||
|
cm.MapKey('a', cm.Command("append"))
|
||||||
|
|
||||||
cm.MapKey(':', cm.Command("enter-command"))
|
cm.MapKey(':', cm.Command("enter-command"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue