Fixed issue single-letter mention issue.
Previously, if @ followed by a single letter were used to select an item
from the completion menu, the menu would exit and not complete. Now, it
does.
MODIFY
ui/editor.go
ui/editor.go
@@ -38,8 +38,8 @@ type Editor struct {
mentionHideHandler func()
heightRequestHandler func(requestHeight int)
requestedHeight int
- currentMentionBeginIdx int
- currentMentionEndIdx int
+ currentMentionBeginIndex int
+ currentMentionEndIndex int
}
func (e *Editor) ExpandSelectionToLeft(left, right, selection []rune) {
@@ -352,16 +352,16 @@ func (editor *Editor) UpdateMentionHandler() {
func (editor *Editor) ShowMentionHandler(atSymbolIndex int) {
lookupKeyword := editor.GetText()[atSymbolIndex+1:]
- editor.currentMentionBeginIdx = atSymbolIndex + 1
- editor.currentMentionEndIdx = len(lookupKeyword) + atSymbolIndex
+ editor.currentMentionBeginIndex = atSymbolIndex + 1
+ editor.currentMentionEndIndex = len(lookupKeyword) + atSymbolIndex
if editor.mentionShowHandler != nil {
editor.mentionShowHandler(lookupKeyword)
}
}
func (editor *Editor) HideAndResetMentionHandler() {
- editor.currentMentionBeginIdx = 0
- editor.currentMentionEndIdx = 0
+ editor.currentMentionBeginIndex = 0
+ editor.currentMentionEndIndex = 0
if editor.mentionHideHandler != nil {
editor.mentionHideHandler()
}
@@ -478,7 +478,7 @@ func (editor *Editor) SetMentionHideHandler(handlerFunc func()) {
// GetCurrentMentionIndices gets the starting and ending indices of the input box text
// which are to be replaced
func (editor *Editor) GetCurrentMentionIndices() (int, int) {
- return editor.currentMentionBeginIdx, editor.currentMentionEndIdx
+ return editor.currentMentionBeginIndex, editor.currentMentionEndIndex
}
// GetText returns the text without color tags, region tags and so on.

MODIFY
ui/window.go
ui/window.go
@@ -845,22 +845,22 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
}
return event
})
+
+ // Invoked when enter is pressed
mentionWindow.SetSelectedFunc(func(node *tview.TreeNode) {
- beginIdx, endIdx := window.messageInput.GetCurrentMentionIndices()
- if beginIdx != endIdx {
+ beginIndex, endIndex := window.messageInput.GetCurrentMentionIndices()
data, ok := node.GetReference().(string)
oldText := window.messageInput.GetText()
if ok {
- newText := oldText[:beginIdx] + strings.TrimSpace(data) + oldText[endIdx+1:] + " "
+ newText := oldText[:beginIndex] + strings.TrimSpace(data) + oldText[endIndex+1:] + " "
window.messageInput.SetText(newText)
} else {
role, ok := node.GetReference().(*discordgo.Role)
if ok {
- newText := oldText[:beginIdx-1] + "<@&" + strings.TrimSpace(role.ID) + ">" + oldText[endIdx+1:] + " "
+ newText := oldText[:beginIndex-1] + "<@&" + strings.TrimSpace(role.ID) + ">" + oldText[endIndex+1:] + " "
window.messageInput.SetText(newText)
}
}
- }
window.messageInput.mentionHideHandler()
})

Fixed issue single-letter mention issue.

Previously, if @ followed by a single letter were used to select an item
from the completion menu, the menu would exit and not complete. Now, it
does.