mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
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
|
TypeSemanticClass
|
||||||
TypeSemanticSelected
|
TypeSemanticSelected
|
||||||
TypeSemanticEnabled
|
TypeSemanticEnabled
|
||||||
TypeSnippet
|
|
||||||
TypeActionInput
|
TypeActionInput
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -164,7 +163,6 @@ const (
|
|||||||
TypeSemanticClassLen = 2
|
TypeSemanticClassLen = 2
|
||||||
TypeSemanticSelectedLen = 2
|
TypeSemanticSelectedLen = 2
|
||||||
TypeSemanticEnabledLen = 2
|
TypeSemanticEnabledLen = 2
|
||||||
TypeSnippetLen = 1 + 4 + 4
|
|
||||||
TypeActionInputLen = 1 + 1
|
TypeActionInputLen = 1 + 1
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -444,7 +442,6 @@ var opProps = [0x100]opProp{
|
|||||||
TypeSemanticClass: {Size: TypeSemanticClassLen, NumRefs: 0},
|
TypeSemanticClass: {Size: TypeSemanticClassLen, NumRefs: 0},
|
||||||
TypeSemanticSelected: {Size: TypeSemanticSelectedLen, NumRefs: 0},
|
TypeSemanticSelected: {Size: TypeSemanticSelectedLen, NumRefs: 0},
|
||||||
TypeSemanticEnabled: {Size: TypeSemanticEnabledLen, NumRefs: 0},
|
TypeSemanticEnabled: {Size: TypeSemanticEnabledLen, NumRefs: 0},
|
||||||
TypeSnippet: {Size: TypeSnippetLen, NumRefs: 2},
|
|
||||||
TypeActionInput: {Size: TypeActionInputLen, NumRefs: 0},
|
TypeActionInput: {Size: TypeActionInputLen, NumRefs: 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -315,9 +315,9 @@ func (q *keyQueue) editorState() EditorState {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *keyQueue) snippetOp(op key.SnippetOp) {
|
func (q *keyQueue) setSnippet(req key.SnippetCmd) {
|
||||||
if op.Tag == q.focus {
|
if req.Tag == q.focus {
|
||||||
q.content.Snippet = op.Snippet
|
q.content.Snippet = req.Snippet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-12
@@ -219,6 +219,8 @@ func (q *Router) executeCommands() {
|
|||||||
q.key.queue.Focus(req.Tag, &q.handlers)
|
q.key.queue.Focus(req.Tag, &q.handlers)
|
||||||
case key.SoftKeyboardCmd:
|
case key.SoftKeyboardCmd:
|
||||||
q.key.queue.softKeyboard(req.Show)
|
q.key.queue.softKeyboard(req.Show)
|
||||||
|
case key.SnippetCmd:
|
||||||
|
q.key.queue.setSnippet(req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q.commands = nil
|
q.commands = nil
|
||||||
@@ -518,18 +520,6 @@ func (q *Router) collect() {
|
|||||||
b := pc.currentAreaBounds()
|
b := pc.currentAreaBounds()
|
||||||
pc.keyInputOp(op)
|
pc.keyInputOp(op)
|
||||||
kq.inputOp(op, t, a, b)
|
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.
|
// Semantic ops.
|
||||||
case ops.TypeSemanticLabel:
|
case ops.TypeSemanticLabel:
|
||||||
|
|||||||
+7
-15
@@ -10,7 +10,6 @@ events.
|
|||||||
package key
|
package key
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gioui.org/f32"
|
"gioui.org/f32"
|
||||||
@@ -45,6 +44,12 @@ type SelectionCmd struct {
|
|||||||
Caret
|
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
|
// Set is an expression that describes a set of key combinations, in the form
|
||||||
// "<modifiers>-<keyset>|...". Modifiers are separated by dashes, optional
|
// "<modifiers>-<keyset>|...". Modifiers are separated by dashes, optional
|
||||||
// modifiers are enclosed by parentheses. A key set is either a literal key
|
// 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.
|
// - Shift-(Ctrl)-A matches A if shift is pressed, and optionally ctrl.
|
||||||
type Set string
|
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.
|
// Range represents a range of text, such as an editor's selection.
|
||||||
// Start and End are in runes.
|
// Start and End are in runes.
|
||||||
type Range struct {
|
type Range struct {
|
||||||
@@ -335,14 +334,6 @@ func (h InputOp) Add(o *op.Ops) {
|
|||||||
data[1] = byte(h.Hint)
|
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 (EditEvent) ImplementsEvent() {}
|
||||||
func (Event) ImplementsEvent() {}
|
func (Event) ImplementsEvent() {}
|
||||||
func (FocusEvent) ImplementsEvent() {}
|
func (FocusEvent) ImplementsEvent() {}
|
||||||
@@ -352,6 +343,7 @@ func (SelectionEvent) ImplementsEvent() {}
|
|||||||
func (FocusCmd) ImplementsCommand() {}
|
func (FocusCmd) ImplementsCommand() {}
|
||||||
func (SoftKeyboardCmd) ImplementsCommand() {}
|
func (SoftKeyboardCmd) ImplementsCommand() {}
|
||||||
func (SelectionCmd) ImplementsCommand() {}
|
func (SelectionCmd) ImplementsCommand() {}
|
||||||
|
func (SnippetCmd) ImplementsCommand() {}
|
||||||
|
|
||||||
func (m Modifiers) String() string {
|
func (m Modifiers) String() string {
|
||||||
var strs []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)
|
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.
|
// have changed. off and len are in runes.
|
||||||
func (e *Editor) updateSnippet(gtx layout.Context, start, end int) {
|
func (e *Editor) updateSnippet(gtx layout.Context, start, end int) {
|
||||||
if start > end {
|
if start > end {
|
||||||
@@ -594,10 +594,7 @@ func (e *Editor) updateSnippet(gtx layout.Context, start, end int) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
e.ime.snippet = newSnip
|
e.ime.snippet = newSnip
|
||||||
key.SnippetOp{
|
gtx.Queue(key.SnippetCmd{Tag: &e.eventKey, Snippet: newSnip})
|
||||||
Tag: &e.eventKey,
|
|
||||||
Snippet: newSnip,
|
|
||||||
}.Add(gtx.Ops)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Editor) layout(gtx layout.Context, textMaterial, selectMaterial op.CallOp) layout.Dimensions {
|
func (e *Editor) layout(gtx layout.Context, textMaterial, selectMaterial op.CallOp) layout.Dimensions {
|
||||||
|
|||||||
Reference in New Issue
Block a user