Skip to content

Commit 079c049

Browse files
committed
Stop the tokenizer thread and start it again when setting a grammar
1 parent a8369f3 commit 079c049

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/TextMateSharp/Model/TMModel.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,25 +272,21 @@ public void SetGrammar(IGrammar grammar)
272272
{
273273
if (!Object.Equals(grammar, this.grammar))
274274
{
275+
Stop();
276+
275277
this.grammar = grammar;
276278
this.tokenizer = new Tokenizer(grammar);
277279
lines.ForEach((line) => line.ResetTokenizationState());
278280
lines.Get(0).SetState(tokenizer.GetInitialState());
281+
282+
Start();
279283
InvalidateLine(0);
280284
}
281285
}
282286

283287
public void AddModelTokensChangedListener(IModelTokensChangedListener listener)
284288
{
285-
if (this.fThread == null || this.fThread.IsStopped)
286-
{
287-
this.fThread = new TokenizerThread("TMModelThread", this);
288-
}
289-
290-
if (this.fThread.IsStopped)
291-
{
292-
this.fThread.Run();
293-
}
289+
Start();
294290

295291
if (!listeners.Contains(listener))
296292
{
@@ -326,6 +322,19 @@ private void Stop()
326322
this.fThread = null;
327323
}
328324

325+
private void Start()
326+
{
327+
if (this.fThread == null || this.fThread.IsStopped)
328+
{
329+
this.fThread = new TokenizerThread("TMModelThread", this);
330+
}
331+
332+
if (this.fThread.IsStopped)
333+
{
334+
this.fThread.Run();
335+
}
336+
}
337+
329338
private void BuildEventWithCallback(Action<ModelTokensChangedEventBuilder> callback)
330339
{
331340
if (this.fThread == null || this.fThread.IsStopped)

0 commit comments

Comments
 (0)