mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
fixed some focus issues; change focus behaviour is now mostly sound!
in addition, the command palette shows all of the open buffers and you can switch to a buffer using the command palette.
This commit is contained in:
parent
c20675b2a6
commit
8ad459755d
@ -34,6 +34,11 @@ func NewBufferPane(buff *Buffer) *BufferPane {
|
|||||||
|
|
||||||
var lastWidth int
|
var lastWidth int
|
||||||
|
|
||||||
|
func (b *BufferPane) SetFocus(focus bool) {
|
||||||
|
b.Buff.SetFocus(focus)
|
||||||
|
b.BaseComponent.SetFocus(focus)
|
||||||
|
}
|
||||||
|
|
||||||
func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
|
func (b *BufferPane) renderMetaPanel(ctx *strife.Renderer) {
|
||||||
conf := b.Buff.cfg.Theme.Palette
|
conf := b.Buff.cfg.Theme.Palette
|
||||||
|
|
||||||
|
@ -26,10 +26,17 @@ type CommandPalette struct {
|
|||||||
conf *cfg.TomlConfig
|
conf *cfg.TomlConfig
|
||||||
parent *View
|
parent *View
|
||||||
|
|
||||||
|
pathToIndex map[string]int
|
||||||
|
|
||||||
suggestionIndex int
|
suggestionIndex int
|
||||||
recentSuggestions *[]suggestion
|
recentSuggestions *[]suggestion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *CommandPalette) SetFocus(focus bool) {
|
||||||
|
p.buff.SetFocus(focus)
|
||||||
|
p.BaseComponent.SetFocus(focus)
|
||||||
|
}
|
||||||
|
|
||||||
var suggestionBoxHeight, suggestionBoxWidth = 48, 0
|
var suggestionBoxHeight, suggestionBoxWidth = 48, 0
|
||||||
|
|
||||||
type suggestion struct {
|
type suggestion struct {
|
||||||
@ -123,22 +130,42 @@ func NewCommandPalette(conf cfg.TomlConfig, view *View) *CommandPalette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *CommandPalette) processCommand() {
|
func (b *CommandPalette) processCommand() {
|
||||||
tokenizedLine := strings.Split(b.buff.contents[0].String(), " ")
|
input := b.buff.contents[0].String()
|
||||||
command := tokenizedLine[0]
|
input = strings.TrimSpace(input)
|
||||||
|
tokenizedLine := strings.Split(input, " ")
|
||||||
|
|
||||||
log.Println("command palette: ", tokenizedLine)
|
// command
|
||||||
|
if strings.Compare(tokenizedLine[0], "!") == 0 {
|
||||||
|
tokenizedLine := strings.Split(input, " ")
|
||||||
|
log.Println("COMMAND TING '", input, "', ", tokenizedLine)
|
||||||
|
command := tokenizedLine[0]
|
||||||
|
|
||||||
action, exists := actions[command]
|
log.Println("command palette: ", tokenizedLine)
|
||||||
if !exists {
|
|
||||||
|
action, exists := actions[command]
|
||||||
|
if !exists {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
action.proc(b.parent, tokenizedLine[1:])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
action.proc(b.parent, tokenizedLine[1:])
|
if index, ok := b.pathToIndex[input]; ok {
|
||||||
|
b.parent.setFocusTo(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *CommandPalette) calculateSuggestions() {
|
func (b *CommandPalette) calculateCommandSuggestions() {
|
||||||
tokenizedLine := strings.Split(b.buff.contents[0].String(), " ")
|
input := b.buff.contents[0].String()
|
||||||
command := tokenizedLine[0]
|
input = strings.TrimSpace(input)
|
||||||
|
|
||||||
|
tokenizedLine := strings.Split(input, " ")
|
||||||
|
if strings.Compare(tokenizedLine[0], "!") == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
command := tokenizedLine[1]
|
||||||
|
|
||||||
if command == "" {
|
if command == "" {
|
||||||
b.recentSuggestions = nil
|
b.recentSuggestions = nil
|
||||||
@ -159,6 +186,47 @@ func (b *CommandPalette) calculateSuggestions() {
|
|||||||
b.recentSuggestions = &suggestions
|
b.recentSuggestions = &suggestions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *CommandPalette) calculateSuggestions() {
|
||||||
|
input := b.buff.contents[0].String()
|
||||||
|
input = strings.TrimSpace(input)
|
||||||
|
|
||||||
|
if len(input) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if input[0] == '!' {
|
||||||
|
b.calculateCommandSuggestions()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill it with the currently open files!
|
||||||
|
|
||||||
|
openFiles := make([]string, len(b.parent.buffers))
|
||||||
|
|
||||||
|
b.pathToIndex = map[string]int{}
|
||||||
|
|
||||||
|
for i, pane := range b.parent.buffers {
|
||||||
|
path := pane.Buff.filePath
|
||||||
|
openFiles[i] = path
|
||||||
|
b.pathToIndex[path] = i
|
||||||
|
}
|
||||||
|
|
||||||
|
ranks := fuzzy.RankFind(input, openFiles)
|
||||||
|
suggestions := []suggestion{}
|
||||||
|
for _, r := range ranks {
|
||||||
|
pane := b.parent.buffers[r.Index]
|
||||||
|
if pane != nil {
|
||||||
|
sugg := suggestion{
|
||||||
|
b,
|
||||||
|
pane.Buff.filePath,
|
||||||
|
}
|
||||||
|
suggestions = append(suggestions, sugg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.recentSuggestions = &suggestions
|
||||||
|
}
|
||||||
|
|
||||||
func (b *CommandPalette) scrollSuggestion(dir int) {
|
func (b *CommandPalette) scrollSuggestion(dir int) {
|
||||||
if b.recentSuggestions != nil {
|
if b.recentSuggestions != nil {
|
||||||
b.suggestionIndex += dir
|
b.suggestionIndex += dir
|
||||||
|
44
gui/view.go
44
gui/view.go
@ -40,13 +40,6 @@ func (n *View) hidePalette() {
|
|||||||
p.clearInput()
|
p.clearInput()
|
||||||
p.SetFocus(false)
|
p.SetFocus(false)
|
||||||
|
|
||||||
// set focus to the buffer
|
|
||||||
// that invoked the cmd palette
|
|
||||||
if p.parentBuff != nil {
|
|
||||||
p.parentBuff.SetFocus(true)
|
|
||||||
n.focusedBuff = p.parentBuff.index
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove focus from palette
|
// remove focus from palette
|
||||||
p.buff.SetFocus(false)
|
p.buff.SetFocus(false)
|
||||||
}
|
}
|
||||||
@ -55,9 +48,6 @@ func (n *View) focusPalette(buff *Buffer) {
|
|||||||
p := n.commandPalette
|
p := n.commandPalette
|
||||||
p.SetFocus(true)
|
p.SetFocus(true)
|
||||||
|
|
||||||
// focus the command palette
|
|
||||||
p.buff.SetFocus(true)
|
|
||||||
|
|
||||||
// remove focus from the buffer
|
// remove focus from the buffer
|
||||||
// that invoked the command palette
|
// that invoked the command palette
|
||||||
p.parentBuff = buff
|
p.parentBuff = buff
|
||||||
@ -66,7 +56,7 @@ func (n *View) focusPalette(buff *Buffer) {
|
|||||||
func (n *View) UnfocusBuffers() {
|
func (n *View) UnfocusBuffers() {
|
||||||
// clear focus from buffers
|
// clear focus from buffers
|
||||||
for _, buffPane := range n.buffers {
|
for _, buffPane := range n.buffers {
|
||||||
buffPane.Buff.SetFocus(false)
|
buffPane.SetFocus(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +98,15 @@ func (n *View) removeBuffer(index int) {
|
|||||||
n.ChangeFocus(dir)
|
n.ChangeFocus(dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *View) setFocusTo(index int) {
|
||||||
|
log.Println("Moving focus from ", n.focusedBuff, " to ", index)
|
||||||
|
|
||||||
|
n.UnfocusBuffers()
|
||||||
|
n.focusedBuff = index
|
||||||
|
buff := n.getCurrentBuffPane()
|
||||||
|
buff.SetFocus(true)
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
func (n *View) ChangeFocus(dir int) {
|
func (n *View) ChangeFocus(dir int) {
|
||||||
// we cant change focus if there are no
|
// we cant change focus if there are no
|
||||||
@ -116,27 +115,22 @@ func (n *View) ChangeFocus(dir int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
prevBuff := n.buffers[n.focusedBuff]
|
newFocus := n.focusedBuff
|
||||||
|
|
||||||
if dir == -1 {
|
if dir == -1 {
|
||||||
n.focusedBuff--
|
newFocus--
|
||||||
} else if dir == 1 {
|
} else if dir == 1 {
|
||||||
n.focusedBuff++
|
newFocus++
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.focusedBuff < 0 {
|
if newFocus < 0 {
|
||||||
n.focusedBuff = len(n.buffers) - 1
|
newFocus = len(n.buffers) - 1
|
||||||
} else if n.focusedBuff >= len(n.buffers) {
|
} else if newFocus >= len(n.buffers) {
|
||||||
n.focusedBuff = 0
|
newFocus = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if prevBuff != nil {
|
n.UnfocusBuffers()
|
||||||
prevBuff.Buff.SetFocus(false)
|
n.setFocusTo(newFocus)
|
||||||
}
|
|
||||||
|
|
||||||
if buffPane := n.getCurrentBuffPane(); buffPane != nil {
|
|
||||||
buffPane.Buff.SetFocus(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *View) getCurrentBuffPane() *BufferPane {
|
func (n *View) getCurrentBuffPane() *BufferPane {
|
||||||
|
Loading…
Reference in New Issue
Block a user