-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
83 additions
and
20 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package components | ||
|
||
import ( | ||
"fyne.io/fyne/v2" | ||
"fyne.io/fyne/v2/driver/desktop" | ||
"fyne.io/fyne/v2/widget" | ||
|
||
"github.com/Jacalz/rymdport/v3/completion" | ||
) | ||
|
||
// NewCompletionEntry returns a new entry widget that allows completing on tab. | ||
func NewCompletionEntry(driver desktop.Driver, generator func(string) []string) *CompletionEntry { | ||
entry := &CompletionEntry{driver: driver} | ||
entry.completer.Generate = generator | ||
entry.ExtendBaseWidget(entry) | ||
return entry | ||
} | ||
|
||
// CompletionEntry allows using tab and shift+tab to | ||
// move forwards and backwards from a set of completions. | ||
type CompletionEntry struct { | ||
widget.Entry | ||
driver desktop.Driver | ||
completer completion.TabCompleter | ||
} | ||
|
||
// AcceptsTab overrides tab handling to allow tabs as input. | ||
func (c *CompletionEntry) AcceptsTab() bool { | ||
return true | ||
} | ||
|
||
// TypedKey adapts the key inputs to handle tab completion. | ||
func (c *CompletionEntry) TypedKey(key *fyne.KeyEvent) { | ||
switch key.Name { | ||
case desktop.KeyShiftLeft, desktop.KeyShiftRight: | ||
case fyne.KeyTab: | ||
completed := "" | ||
|
||
if c.driver.CurrentKeyModifiers()&fyne.KeyModifierShift != 0 { | ||
completed = c.completer.Previous(c.Text) | ||
} else { | ||
completed = c.completer.Next(c.Text) | ||
} | ||
|
||
c.CursorColumn = len(completed) | ||
c.SetText(completed) | ||
default: | ||
c.completer.Reset() | ||
c.Entry.TypedKey(key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
internal/transport/completion_test.go → internal/wormhole/completion_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package transport | ||
package wormhole | ||
|
||
import ( | ||
"testing" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Package wormhole is a helper around the wormhole package. | ||
package wormhole | ||
|
||
import ( | ||
"github.com/rymdport/wormhole/wormhole" | ||
) | ||
|
||
// NewClient creates a new client object. | ||
func NewClient() *Client { | ||
return &Client{} | ||
} | ||
|
||
// Client defines the client for handling sending and receiving. | ||
type Client struct { | ||
connection wormhole.Client | ||
} |