aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2018-04-22 21:05:42 +0300
committerTulir Asokan <tulir@maunium.net>2018-04-22 21:05:42 +0300
commitbfb5f0dd457be326b1ae7638a64d2e79cbace371 (patch)
tree32c6af4204600e160d22751f047bf192d72ad069 /ui
parent9c4788f6e2706fe7bb038b845c0973031a26a6e9 (diff)
Add room alias autocompletion
Diffstat (limited to 'ui')
-rw-r--r--ui/room-view.go21
-rw-r--r--ui/view-main.go2
2 files changed, 18 insertions, 5 deletions
diff --git a/ui/room-view.go b/ui/room-view.go
index bfcb547..4cf7320 100644
--- a/ui/room-view.go
+++ b/ui/room-view.go
@@ -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) {
diff --git a/ui/view-main.go b/ui/view-main.go
index 0b0708c..ba98719 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -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).