~taiite/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH senpai] ui: add commands completion

Details
Message ID
<0101017dbbecd681-00366930-132c-4522-ad50-e0ce04ed3a91-000000@us-west-2.amazonses.com>
DKIM signature
missing
Download raw message
Patch: +21 -0
---
 app.go         |  1 +
 completions.go | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/app.go b/app.go
index 1144560..4706536 100644
--- a/app.go
+++ b/app.go
@@ -938,6 +938,7 @@ func (app *App) completions(cursorIdx int, text []rune) []ui.Completion {
		cs = app.completionsChannelMembers(cs, cursorIdx, text)
	}
	cs = app.completionsMsg(cs, cursorIdx, text)
	cs = app.completionsCommands(cs, cursorIdx, text)

	if cs != nil {
		cs = append(cs, ui.Completion{
diff --git a/completions.go b/completions.go
index 3e4a516..6f99a60 100644
--- a/completions.go
+++ b/completions.go
@@ -99,6 +99,26 @@ func (app *App) completionsMsg(cs []ui.Completion, cursorIdx int, text []rune) [
	return cs
}

func (app *App) completionsCommands(cs []ui.Completion, cursorIdx int, text []rune) []ui.Completion {
	if !hasPrefix(text, []rune("/")) {
		return cs
	}
	uText := strings.ToUpper(string(text[1:]))
	for name, _ := range commands {
		if strings.HasPrefix(name, uText) {
			c := make([]rune, 1+len(name))
			copy(c[:1], []rune("/"))
			copy(c[1:], []rune(name))

			cs = append(cs, ui.Completion{
				Text:      c,
				CursorIdx: 1 + len(name),
			})
		}
	}
	return cs
}

func hasPrefix(s, prefix []rune) bool {
	return len(prefix) <= len(s) && equal(prefix, s[:len(prefix)])
}
-- 
2.34.1
Details
Message ID
<e3c81f82-3ae3-f039-826a-4a096469c650@hirtz.pm>
In-Reply-To
<0101017dbbecd681-00366930-132c-4522-ad50-e0ce04ed3a91-000000@us-west-2.amazonses.com> (view parent)
DKIM signature
missing
Download raw message
Thanks for the patch. It works well, just an edge case that needs to be 
handled:

1. type "/m #channel +b"
2. place cursor after "/m"
3. press tab

You'll need to take the first word of "text" only, and append the rest 
of "text" to each completion.
Reply to thread Export thread (mbox)