mirror of
https://github.com/zyedidia/micro.git
synced 2025-06-19 15:25:42 -04:00
Basic autocomplete box
This commit is contained in:
parent
132630a9a5
commit
724cedd37b
@ -18,6 +18,7 @@ type BufWindow struct {
|
|||||||
|
|
||||||
// Buffer being shown in this window
|
// Buffer being shown in this window
|
||||||
Buf *buffer.Buffer
|
Buf *buffer.Buffer
|
||||||
|
completeBox buffer.Loc
|
||||||
|
|
||||||
active bool
|
active bool
|
||||||
|
|
||||||
@ -583,6 +584,13 @@ func (w *BufWindow) displayBuffer() {
|
|||||||
|
|
||||||
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, r, combc, style)
|
screen.SetContent(w.X+vloc.X, w.Y+vloc.Y, r, combc, style)
|
||||||
|
|
||||||
|
if w.Buf.HasSuggestions && len(w.Buf.Completions) > 0 {
|
||||||
|
compl := w.Buf.Completions[0].Edits[0].Start
|
||||||
|
if bloc.X == compl.X && bloc.Y == compl.Y {
|
||||||
|
w.completeBox = buffer.Loc{w.X + vloc.X, w.Y + vloc.Y}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if showcursor {
|
if showcursor {
|
||||||
for _, c := range cursors {
|
for _, c := range cursors {
|
||||||
if c.X == bloc.X && c.Y == bloc.Y && !c.HasSelection() {
|
if c.X == bloc.X && c.Y == bloc.Y && !c.HasSelection() {
|
||||||
@ -742,9 +750,43 @@ func (w *BufWindow) displayScrollBar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *BufWindow) displayCompleteBox() {
|
||||||
|
if !w.Buf.HasSuggestions || w.Buf.NumCursors() > 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
width := 0
|
||||||
|
for _, comp := range w.Buf.Completions {
|
||||||
|
charcount := util.CharacterCountInString(comp.Label)
|
||||||
|
if charcount > width {
|
||||||
|
width = charcount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
width++
|
||||||
|
|
||||||
|
for i, comp := range w.Buf.Completions {
|
||||||
|
label := comp.Label
|
||||||
|
for j := 0; j < width; j++ {
|
||||||
|
r := ' '
|
||||||
|
var combc []rune
|
||||||
|
var size int
|
||||||
|
if len(label) > 0 {
|
||||||
|
r, combc, size = util.DecodeCharacterInString(label)
|
||||||
|
label = label[size:]
|
||||||
|
}
|
||||||
|
st := config.DefStyle.Reverse(true)
|
||||||
|
if i == w.Buf.CurCompletion {
|
||||||
|
st = st.Reverse(false)
|
||||||
|
}
|
||||||
|
screen.SetContent(w.completeBox.X+j, w.completeBox.Y+i+1, r, combc, st)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Display displays the buffer and the statusline
|
// Display displays the buffer and the statusline
|
||||||
func (w *BufWindow) Display() {
|
func (w *BufWindow) Display() {
|
||||||
w.displayStatusLine()
|
w.displayStatusLine()
|
||||||
w.displayScrollBar()
|
w.displayScrollBar()
|
||||||
w.displayBuffer()
|
w.displayBuffer()
|
||||||
|
w.displayCompleteBox()
|
||||||
}
|
}
|
||||||
|
@ -98,44 +98,6 @@ func (s *StatusLine) Display() {
|
|||||||
// We'll draw the line at the lowest line in the window
|
// We'll draw the line at the lowest line in the window
|
||||||
y := s.win.Height + s.win.Y - 1
|
y := s.win.Height + s.win.Y - 1
|
||||||
|
|
||||||
b := s.win.Buf
|
|
||||||
// autocomplete suggestions (for the buffer, not for the infowindow)
|
|
||||||
if b.HasSuggestions && len(b.Completions) > 1 {
|
|
||||||
statusLineStyle := config.DefStyle.Reverse(true)
|
|
||||||
if style, ok := config.Colorscheme["statusline"]; ok {
|
|
||||||
statusLineStyle = style
|
|
||||||
}
|
|
||||||
keymenuOffset := 0
|
|
||||||
if config.GetGlobalOption("keymenu").(bool) {
|
|
||||||
keymenuOffset = len(keydisplay)
|
|
||||||
}
|
|
||||||
x := 0
|
|
||||||
for j, sug := range b.Completions {
|
|
||||||
style := statusLineStyle
|
|
||||||
if b.CurCompletion == j {
|
|
||||||
style = style.Reverse(true)
|
|
||||||
}
|
|
||||||
for _, r := range sug.Label {
|
|
||||||
screen.SetContent(x, y-keymenuOffset, r, nil, style)
|
|
||||||
x++
|
|
||||||
if x >= s.win.Width {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
screen.SetContent(x, y-keymenuOffset, ' ', nil, statusLineStyle)
|
|
||||||
x++
|
|
||||||
if x >= s.win.Width {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for x < s.win.Width {
|
|
||||||
screen.SetContent(x, y-keymenuOffset, ' ', nil, statusLineStyle)
|
|
||||||
x++
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
formatter := func(match []byte) []byte {
|
formatter := func(match []byte) []byte {
|
||||||
name := match[2 : len(match)-1]
|
name := match[2 : len(match)-1]
|
||||||
if bytes.HasPrefix(name, []byte("opt")) {
|
if bytes.HasPrefix(name, []byte("opt")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user