Skip to content

Commit 9adacca

Browse files
committed
Use tile field controller
1 parent 87c47a9 commit 9adacca

File tree

5 files changed

+27
-71
lines changed

5 files changed

+27
-71
lines changed

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
module github.com/codeation/lineation
22

3-
go 1.24.1
3+
go 1.24.2
44

55
require (
66
github.com/codeation/impress v1.0.1
7-
github.com/codeation/tile v0.1.9
7+
github.com/codeation/tile v0.1.10
88
)
99

1010
require github.com/codeation/lru v1.3.0 // indirect

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ github.com/codeation/impress v1.0.1 h1:X+jUirJArTUU6lumnSws+um86/IkWVFK4huSc/Q24
22
github.com/codeation/impress v1.0.1/go.mod h1:DzaGU4d6gCxsisc0PRZuJ0r8xwlFOEG8I546+yENPVk=
33
github.com/codeation/lru v1.3.0 h1:BZlD5G4bt0bis9FHV5q3zyyDCAx21ue2CvvM1T8hQl4=
44
github.com/codeation/lru v1.3.0/go.mod h1:1C9+zUoRETpelIbMxh6wj9APf2VnKh0tk9aRsrOQUsk=
5-
github.com/codeation/tile v0.1.9 h1:wZgCLeGHIv6+wcCBzPg4DUSRCJogAgIeQBAyZ2mIt9Q=
6-
github.com/codeation/tile v0.1.9/go.mod h1:XEw1ez5/RFGlDt8hhvqNNwLvfB0P6XXWuNxPg6lvZOQ=
5+
github.com/codeation/tile v0.1.10 h1:DX64Clzx1CHL/q60vW+19eGEyOVuLbvcX9Kgqm5SVpw=
6+
github.com/codeation/tile v0.1.10/go.mod h1:FbITYdsiEGhSqKOgeV3YxcLU+yg55TEdeWwI118qqMQ=

mapcontrol/control.go

+8-42
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"image"
7-
"unicode"
87

98
"github.com/codeation/impress/clipboard"
109
"github.com/codeation/impress/event"
@@ -18,15 +17,7 @@ import (
1817
"github.com/codeation/lineation/xmlfile"
1918
)
2019

21-
var keypadEnter = event.Keyboard{
22-
Name: "KP_Enter",
23-
}
24-
25-
var keyShiftEnter = event.Keyboard{
26-
Rune: 13,
27-
Shift: true,
28-
Name: "Return",
29-
}
20+
var keypadEnter = event.Keyboard{Name: "KP_Enter"}
3021

3122
type Control struct {
3223
mapModel *mapmodel.MindMap
@@ -43,8 +34,7 @@ func New(app eventlink.AppFramer, mapModel *mapmodel.MindMap, mapView *mapview.V
4334
}
4435
}
4536

46-
func (c *Control) Wait() {
47-
}
37+
func (c *Control) Wait() {}
4838

4939
func (c *Control) Action(ctx context.Context, app eventlink.App) {
5040
maybeChanged := true
@@ -94,19 +84,6 @@ func (c *Control) Action(ctx context.Context, app eventlink.App) {
9484
c.modView.Set(true)
9585
}
9686

97-
case event.KeyLeft:
98-
c.mapModel.Left()
99-
case event.KeyRight:
100-
c.mapModel.Right()
101-
case event.KeyBackSpace:
102-
if c.mapModel.Selected.Value.Cursor() > 0 {
103-
c.mapModel.Backspace()
104-
c.modView.Set(true)
105-
}
106-
case keyShiftEnter:
107-
c.mapModel.InsertNL()
108-
c.modView.Set(true)
109-
11087
case event.KeyCopy, menuevent.Copy:
11188
app.Application().ClipboardPut(clipboard.Text(c.mapModel.Selected.Value.String()))
11289
case event.KeyPaste, menuevent.Paste:
@@ -117,12 +94,6 @@ func (c *Control) Action(ctx context.Context, app eventlink.App) {
11794
case event.Configure:
11895
c.mapView.Configure(ev.InnerSize)
11996

120-
case event.Keyboard:
121-
if ev.IsGraphic() {
122-
c.mapModel.Insert(ev.Rune)
123-
c.modView.Set(true)
124-
}
125-
12697
case event.Button:
12798
if ev.Action == event.ButtonActionPress && ev.Button == event.ButtonLeft {
12899
if node, ok := c.mapView.Select(ev.Point); ok {
@@ -133,19 +104,14 @@ func (c *Control) Action(ctx context.Context, app eventlink.App) {
133104
}
134105
}
135106

136-
case event.Clipboard:
137-
if text, ok := ev.Data.(clipboard.Text); ok {
138-
for _, r := range text {
139-
if !unicode.IsGraphic(r) {
140-
continue
141-
}
142-
c.mapModel.Insert(r)
143-
}
107+
default:
108+
oldValue := c.mapModel.Selected.Value.String()
109+
c.mapModel.NodeControl(ctx, app, e, func(ctx context.Context, app eventlink.App, e event.Eventer) {
110+
anyEvent = false
111+
})
112+
if oldValue != c.mapModel.Selected.Value.String() {
144113
c.modView.Set(true)
145114
}
146-
147-
default:
148-
anyEvent = false
149115
}
150116
}
151117

mapmodel/model.go

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package mapmodel
22

33
import (
4+
"context"
5+
6+
"github.com/codeation/impress/event"
47
"github.com/codeation/lineation/xmlfile"
8+
"github.com/codeation/tile/control"
9+
"github.com/codeation/tile/eventlink"
510
)
611

712
type MindMap struct {
@@ -79,22 +84,6 @@ func (m *MindMap) Adopt(node *Node, newParent *Node, beforeNode *Node) {
7984
m.Selected.Value.End()
8085
}
8186

82-
func (m *MindMap) Right() {
83-
m.Selected.Value.Right()
84-
}
85-
86-
func (m *MindMap) Left() {
87-
m.Selected.Value.Left()
88-
}
89-
90-
func (m *MindMap) Insert(alpha rune) {
91-
m.Selected.Value.Insert(alpha)
92-
}
93-
94-
func (m *MindMap) InsertNL() {
95-
m.Selected.Value.InsertNL()
96-
}
97-
98-
func (m *MindMap) Backspace() {
99-
m.Selected.Value.Backspace()
87+
func (m *MindMap) NodeControl(ctx context.Context, app eventlink.App, e event.Eventer, prior control.DoFunc) {
88+
m.Selected.Control.Control(ctx, app, e, prior)
10089
}

mapmodel/node.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ package mapmodel
33
import (
44
"slices"
55

6+
"github.com/codeation/tile/control/fieldcontrol"
67
"github.com/codeation/tile/elem/field"
78

89
"github.com/codeation/lineation/xmlfile"
910
)
1011

1112
type Node struct {
12-
Value *field.Field
13-
Parent *Node
14-
Childs []*Node
13+
Value *field.Field
14+
Control *fieldcontrol.FieldControl
15+
Parent *Node
16+
Childs []*Node
1517
}
1618

1719
func newXMLNode(elem *xmlfile.Node, parent *Node) *Node {
@@ -21,10 +23,7 @@ func newXMLNode(elem *xmlfile.Node, parent *Node) *Node {
2123
Childs: make([]*Node, 0, len(elem.Childs)),
2224
}
2325
node.Value.Home()
24-
if len(elem.Childs) == 0 {
25-
return node
26-
}
27-
node.Childs = make([]*Node, 0, len(elem.Childs))
26+
node.Control = fieldcontrol.New(node.Value)
2827
for _, child := range elem.Childs {
2928
node.Childs = append(node.Childs, newXMLNode(child, node))
3029
}
@@ -46,6 +45,7 @@ func (parent *Node) newChild() *Node {
4645
Value: field.New(""),
4746
Parent: parent,
4847
}
48+
newNode.Control = fieldcontrol.New(newNode.Value)
4949
parent.Childs = append([]*Node{newNode}, parent.Childs...)
5050
return newNode
5151
}
@@ -56,6 +56,7 @@ func (node *Node) newNext() *Node {
5656
Value: field.New(""),
5757
Parent: node.Parent,
5858
}
59+
newNode.Control = fieldcontrol.New(newNode.Value)
5960
node.Parent.Childs = slices.Insert(node.Parent.Childs, i+1, newNode)
6061
return newNode
6162
}

0 commit comments

Comments
 (0)