mirror of
https://github.com/felixangell/phi.git
synced 2024-08-16 19:20:21 +03:00
command palette now hides as well as clears the input
This commit is contained in:
parent
0992e6f73e
commit
d8fc3f0452
@ -15,7 +15,7 @@ type CommandPalette struct {
|
||||
parentBuff *Buffer
|
||||
}
|
||||
|
||||
func NewCommandPalette(conf cfg.TomlConfig) *CommandPalette {
|
||||
func NewCommandPalette(conf cfg.TomlConfig, view *View) *CommandPalette {
|
||||
conf.Editor.Show_Line_Numbers = false
|
||||
conf.Editor.Highlight_Line = false
|
||||
|
||||
@ -25,6 +25,12 @@ func NewCommandPalette(conf cfg.TomlConfig) *CommandPalette {
|
||||
HasFocus: false,
|
||||
}
|
||||
palette.buff.appendLine("")
|
||||
|
||||
palette.Resize(view.w/3, 48)
|
||||
palette.Translate((view.w/2)-(palette.w/2), 10)
|
||||
palette.buff.Resize(palette.w, palette.h)
|
||||
palette.buff.Translate((view.w/2)-(palette.w/2), 10)
|
||||
|
||||
return palette
|
||||
}
|
||||
|
||||
@ -46,6 +52,10 @@ func (b *CommandPalette) processCommand() {
|
||||
action(b.parentBuff)
|
||||
}
|
||||
|
||||
func (b *CommandPalette) clearInput() {
|
||||
actions["delete_line"](b.buff)
|
||||
}
|
||||
|
||||
func (b *CommandPalette) OnUpdate() bool {
|
||||
if !b.HasFocus {
|
||||
return true
|
||||
@ -57,13 +67,7 @@ func (b *CommandPalette) OnUpdate() bool {
|
||||
}
|
||||
|
||||
b.processCommand()
|
||||
|
||||
// regardless we close the command
|
||||
// palette and re-focus on the buffer
|
||||
// that we transferred from.
|
||||
b.parentBuff.SetInputHandler(b.inputHandler)
|
||||
b.parentBuff.HasFocus = true
|
||||
|
||||
b.parentBuff.parent.hidePalette()
|
||||
return true
|
||||
}
|
||||
return b.buff.doUpdate(override)
|
||||
|
12
gui/view.go
12
gui/view.go
@ -17,17 +17,14 @@ type View struct {
|
||||
|
||||
func NewView(width, height int, conf *cfg.TomlConfig) *View {
|
||||
view := &View{
|
||||
conf: conf,
|
||||
buffers: map[int]*Buffer{},
|
||||
commandPalette: NewCommandPalette(*conf),
|
||||
conf: conf,
|
||||
buffers: map[int]*Buffer{},
|
||||
}
|
||||
|
||||
view.Translate(width, height)
|
||||
view.Resize(width, height)
|
||||
|
||||
view.commandPalette.Resize(view.w/3, 48)
|
||||
view.commandPalette.Translate((view.w/2)-(view.commandPalette.w/2), 10)
|
||||
|
||||
view.commandPalette = NewCommandPalette(*conf, view)
|
||||
view.UnfocusBuffers()
|
||||
|
||||
return view
|
||||
@ -35,6 +32,7 @@ func NewView(width, height int, conf *cfg.TomlConfig) *View {
|
||||
|
||||
func (n *View) hidePalette() {
|
||||
p := n.commandPalette
|
||||
p.clearInput()
|
||||
p.HasFocus = false
|
||||
|
||||
// set focus to the buffer
|
||||
@ -79,7 +77,7 @@ func sign(dir int) int {
|
||||
}
|
||||
|
||||
func (n *View) ChangeFocus(dir int) {
|
||||
// TODO
|
||||
println("implement me! ", dir)
|
||||
}
|
||||
|
||||
func (n *View) OnInit() {
|
||||
|
Loading…
Reference in New Issue
Block a user