Add room alias autocompletion
This commit is contained in:
@ -45,7 +45,10 @@ type RoomView struct {
|
||||
input *widget.AdvancedInputField
|
||||
Room *rooms.Room
|
||||
|
||||
parent *MainView
|
||||
|
||||
typing []string
|
||||
|
||||
completions struct {
|
||||
list []string
|
||||
textCache string
|
||||
@ -53,7 +56,7 @@ type RoomView struct {
|
||||
}
|
||||
}
|
||||
|
||||
func NewRoomView(room *rooms.Room) *RoomView {
|
||||
func NewRoomView(parent *MainView, room *rooms.Room) *RoomView {
|
||||
view := &RoomView{
|
||||
Box: tview.NewBox(),
|
||||
topic: tview.NewTextView(),
|
||||
@ -62,6 +65,7 @@ func NewRoomView(room *rooms.Room) *RoomView {
|
||||
ulBorder: widget.NewBorder(),
|
||||
input: widget.NewAdvancedInputField(),
|
||||
Room: room,
|
||||
parent: parent,
|
||||
}
|
||||
view.content = NewMessageView(view)
|
||||
|
||||
@ -257,9 +261,18 @@ func (view *RoomView) autocompleteUser(existingText string) (completions []compl
|
||||
}
|
||||
|
||||
func (view *RoomView) autocompleteRoom(existingText string) (completions []completion) {
|
||||
// TODO - This was harder than I expected.
|
||||
|
||||
return []completion{}
|
||||
for _, room := range view.parent.rooms {
|
||||
alias := room.Room.GetCanonicalAlias()
|
||||
if alias == existingText {
|
||||
// Exact match, return that.
|
||||
return []completion{{alias, room.Room.ID}}
|
||||
}
|
||||
if strings.HasPrefix(alias, existingText) {
|
||||
completions = append(completions, completion{alias, room.Room.ID})
|
||||
continue
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (view *RoomView) InputTabComplete(text string, cursorOffset int) {
|
||||
|
@ -299,7 +299,7 @@ func (view *MainView) addRoom(index int, room string) {
|
||||
|
||||
view.roomList.Add(roomStore)
|
||||
if !view.roomView.HasPage(room) {
|
||||
roomView := NewRoomView(roomStore).
|
||||
roomView := NewRoomView(view, roomStore).
|
||||
SetInputSubmitFunc(view.InputSubmit).
|
||||
SetInputChangedFunc(view.InputChanged).
|
||||
SetInputCapture(view.KeyEventHandler).
|
||||
|
Reference in New Issue
Block a user