Mention results only search from the @ symbol to the cursor.
MODIFY
ui/editor.go
ui/editor.go
@@ -112,6 +112,25 @@ func (e *Editor) MoveCursorRight(left, right, selection []rune) {
e.setAndFixText(newText)
}
+func (e *Editor) MoveCursorToIndex(left, right, selection []rune, index int) {
+ var newText string
+ if index < len(left) {
+ newText = leftRegion + string(left[:index]) + selRegion + string(left[index]) + rightRegion + string(left[index+1:]) + string(right) + endRegion
+ } else {
+ indexSelection := index - len(left)
+ if indexSelection < len(selection) {
+ newText = leftRegion + string(left) + string(left[:indexSelection]) + selRegion + string(selection[indexSelection]) + rightRegion + string(selection[indexSelection+1:]) + string(right) + endRegion
+ } else {
+ indexRight := index - len(left) - len(selection)
+ if indexRight < len(right) {
+ newText = leftRegion + string(left) + string(selection) + string(right[:indexRight]) + selRegion + string(right[indexRight]) + rightRegion + string(right[indexRight+1:]) + endRegion
+ }
+ }
+ }
+
+ e.setAndFixText(newText)
+}
+
func (e *Editor) SelectWordLeft(left, right, selection []rune) {
if len(left) > 0 {
selectionFrom := 0
@@ -363,7 +382,8 @@ func (editor *Editor) UpdateMentionHandler() {
}
func (editor *Editor) ShowMentionHandler(atSymbolIndex int) {
- lookupKeyword := editor.GetText()[atSymbolIndex+1:]
+ text := editor.internalTextView.GetRegionText("left")
+ lookupKeyword := text[atSymbolIndex+1:]
editor.currentMentionBeginIndex = atSymbolIndex + 1
editor.currentMentionEndIndex = len(lookupKeyword) + atSymbolIndex
if editor.mentionShowHandler != nil {

MODIFY
ui/window.go
ui/window.go
@@ -842,13 +842,17 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
data, ok := node.GetReference().(string)
oldText := window.messageInput.GetText()
if ok {
- newText := oldText[:beginIndex] + strings.TrimSpace(data) + oldText[endIndex+1:] + " "
- window.messageInput.SetText(newText)
+ left := oldText[:beginIndex] + strings.TrimSpace(data) + " "
+ right := oldText[endIndex+1:]
+ window.messageInput.SetText(left + right)
+ window.messageInput.MoveCursorToIndex([]rune(left), []rune(right), []rune{}, len(left))
} else {
role, ok := node.GetReference().(*discordgo.Role)
if ok {
- newText := oldText[:beginIndex-1] + "<@&" + strings.TrimSpace(role.ID) + ">" + oldText[endIndex+1:] + " "
- window.messageInput.SetText(newText)
+ left := "<@&" + strings.TrimSpace(role.ID) + "> "
+ right := oldText[endIndex+1:]
+ window.messageInput.SetText(left + right)
+ window.messageInput.MoveCursorToIndex([]rune(left), []rune(right), []rune{}, len(left))
}
}
window.messageInput.mentionHideHandler()

Mention results only search from the @ symbol to the cursor.