forked from joejulian/gio
io/input,io/key: [API] replace SnippetOp with command
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -82,7 +82,6 @@ const (
|
||||
TypeSemanticClass
|
||||
TypeSemanticSelected
|
||||
TypeSemanticEnabled
|
||||
TypeSnippet
|
||||
TypeActionInput
|
||||
)
|
||||
|
||||
@@ -164,7 +163,6 @@ const (
|
||||
TypeSemanticClassLen = 2
|
||||
TypeSemanticSelectedLen = 2
|
||||
TypeSemanticEnabledLen = 2
|
||||
TypeSnippetLen = 1 + 4 + 4
|
||||
TypeActionInputLen = 1 + 1
|
||||
)
|
||||
|
||||
@@ -444,7 +442,6 @@ var opProps = [0x100]opProp{
|
||||
TypeSemanticClass: {Size: TypeSemanticClassLen, NumRefs: 0},
|
||||
TypeSemanticSelected: {Size: TypeSemanticSelectedLen, NumRefs: 0},
|
||||
TypeSemanticEnabled: {Size: TypeSemanticEnabledLen, NumRefs: 0},
|
||||
TypeSnippet: {Size: TypeSnippetLen, NumRefs: 2},
|
||||
TypeActionInput: {Size: TypeActionInputLen, NumRefs: 0},
|
||||
}
|
||||
|
||||
|
||||
+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
|
||||
|
||||
+2
-5
@@ -554,7 +554,7 @@ func (e *Editor) Layout(gtx layout.Context, lt *text.Shaper, font font.Font, siz
|
||||
return e.layout(gtx, textMaterial, selectMaterial)
|
||||
}
|
||||
|
||||
// updateSnippet adds a key.SnippetOp if the snippet content or position
|
||||
// updateSnippet queues a key.SnippetCmd if the snippet content or position
|
||||
// have changed. off and len are in runes.
|
||||
func (e *Editor) updateSnippet(gtx layout.Context, start, end int) {
|
||||
if start > end {
|
||||
@@ -594,10 +594,7 @@ func (e *Editor) updateSnippet(gtx layout.Context, start, end int) {
|
||||
return
|
||||
}
|
||||
e.ime.snippet = newSnip
|
||||
key.SnippetOp{
|
||||
Tag: &e.eventKey,
|
||||
Snippet: newSnip,
|
||||
}.Add(gtx.Ops)
|
||||
gtx.Queue(key.SnippetCmd{Tag: &e.eventKey, Snippet: newSnip})
|
||||
}
|
||||
|
||||
func (e *Editor) layout(gtx layout.Context, textMaterial, selectMaterial op.CallOp) layout.Dimensions {
|
||||
|
||||
Reference in New Issue
Block a user