@@ -71,6 +71,9 @@ var inputWYSIWYG = prefs.NewBool(true, prefs.PropMeta{
71
71
Description : "Enable a semi-WYSIWYG feature that decorates the input Markdown text." ,
72
72
})
73
73
74
+ // inputStateKey is the app state that stores the last input message.
75
+ var inputStateKey = app.NewStateKey [string ]("input-state" )
76
+
74
77
// NewInput creates a new Input widget.
75
78
func NewInput (ctx context.Context , ctrl InputController , chID discord.ChannelID ) * Input {
76
79
i := Input {
@@ -119,12 +122,12 @@ func NewInput(ctx context.Context, ctrl InputController, chID discord.ChannelID)
119
122
start , end := i .Buffer .Bounds ()
120
123
121
124
// Persist input.
122
- cfg := app . AcquireState (ctx , "input-state" )
125
+ inputState := inputStateKey . Acquire (ctx )
123
126
if end .Offset () == 0 {
124
- cfg .Delete (chID .String ())
127
+ inputState .Delete (chID .String ())
125
128
} else {
126
129
text := i .Buffer .Text (start , end , false )
127
- cfg .Set (chID .String (), text )
130
+ inputState .Set (chID .String (), text )
128
131
}
129
132
})
130
133
@@ -133,10 +136,10 @@ func NewInput(ctx context.Context, ctrl InputController, chID discord.ChannelID)
133
136
i .AddController (enterKeyer )
134
137
135
138
gtkutil .Async (ctx , func () func () {
136
- var oldMessage string
139
+ inputState := inputStateKey . Acquire ( ctx )
137
140
138
- cfg := app . AcquireState ( ctx , "input-state" )
139
- if ! cfg . Get ( chID . String (), & oldMessage ) {
141
+ oldMessage , ok := inputState . Get ( chID . String () )
142
+ if ! ok {
140
143
return nil
141
144
}
142
145
0 commit comments