mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
io/input,io/key: [API] replace SnippetOp with command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+3
-3
@@ -315,9 +315,9 @@ func (q *keyQueue) editorState() EditorState {
|
||||
return s
|
||||
}
|
||||
|
||||
func (q *keyQueue) snippetOp(op key.SnippetOp) {
|
||||
if op.Tag == q.focus {
|
||||
q.content.Snippet = op.Snippet
|
||||
func (q *keyQueue) setSnippet(req key.SnippetCmd) {
|
||||
if req.Tag == q.focus {
|
||||
q.content.Snippet = req.Snippet
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-12
@@ -219,6 +219,8 @@ func (q *Router) executeCommands() {
|
||||
q.key.queue.Focus(req.Tag, &q.handlers)
|
||||
case key.SoftKeyboardCmd:
|
||||
q.key.queue.softKeyboard(req.Show)
|
||||
case key.SnippetCmd:
|
||||
q.key.queue.setSnippet(req)
|
||||
}
|
||||
}
|
||||
q.commands = nil
|
||||
@@ -518,18 +520,6 @@ func (q *Router) collect() {
|
||||
b := pc.currentAreaBounds()
|
||||
pc.keyInputOp(op)
|
||||
kq.inputOp(op, t, a, b)
|
||||
case ops.TypeSnippet:
|
||||
op := key.SnippetOp{
|
||||
Tag: encOp.Refs[0].(event.Tag),
|
||||
Snippet: key.Snippet{
|
||||
Range: key.Range{
|
||||
Start: int(int32(bo.Uint32(encOp.Data[1:]))),
|
||||
End: int(int32(bo.Uint32(encOp.Data[5:]))),
|
||||
},
|
||||
Text: *(encOp.Refs[1].(*string)),
|
||||
},
|
||||
}
|
||||
kq.snippetOp(op)
|
||||
|
||||
// Semantic ops.
|
||||
case ops.TypeSemanticLabel:
|
||||
|
||||
+7
-15
@@ -10,7 +10,6 @@ events.
|
||||
package key
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"strings"
|
||||
|
||||
"gioui.org/f32"
|
||||
@@ -45,6 +44,12 @@ type SelectionCmd struct {
|
||||
Caret
|
||||
}
|
||||
|
||||
// SnippetCmd updates the content snippet for an input handler.
|
||||
type SnippetCmd struct {
|
||||
Tag event.Tag
|
||||
Snippet
|
||||
}
|
||||
|
||||
// Set is an expression that describes a set of key combinations, in the form
|
||||
// "<modifiers>-<keyset>|...". Modifiers are separated by dashes, optional
|
||||
// modifiers are enclosed by parentheses. A key set is either a literal key
|
||||
@@ -61,12 +66,6 @@ type SelectionCmd struct {
|
||||
// - Shift-(Ctrl)-A matches A if shift is pressed, and optionally ctrl.
|
||||
type Set string
|
||||
|
||||
// SnippetOp updates the content snippet for an input handler.
|
||||
type SnippetOp struct {
|
||||
Tag event.Tag
|
||||
Snippet
|
||||
}
|
||||
|
||||
// Range represents a range of text, such as an editor's selection.
|
||||
// Start and End are in runes.
|
||||
type Range struct {
|
||||
@@ -335,14 +334,6 @@ func (h InputOp) Add(o *op.Ops) {
|
||||
data[1] = byte(h.Hint)
|
||||
}
|
||||
|
||||
func (s SnippetOp) Add(o *op.Ops) {
|
||||
data := ops.Write2String(&o.Internal, ops.TypeSnippetLen, s.Tag, s.Text)
|
||||
data[0] = byte(ops.TypeSnippet)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[1:], uint32(s.Range.Start))
|
||||
bo.PutUint32(data[5:], uint32(s.Range.End))
|
||||
}
|
||||
|
||||
func (EditEvent) ImplementsEvent() {}
|
||||
func (Event) ImplementsEvent() {}
|
||||
func (FocusEvent) ImplementsEvent() {}
|
||||
@@ -352,6 +343,7 @@ func (SelectionEvent) ImplementsEvent() {}
|
||||
func (FocusCmd) ImplementsCommand() {}
|
||||
func (SoftKeyboardCmd) ImplementsCommand() {}
|
||||
func (SelectionCmd) ImplementsCommand() {}
|
||||
func (SnippetCmd) ImplementsCommand() {}
|
||||
|
||||
func (m Modifiers) String() string {
|
||||
var strs []string
|
||||
|
||||
Reference in New Issue
Block a user