void Textbox_SelectionChanged(object sender, EventArgs e) { if (stateLocked != IntPtr.Zero) { return; } if (SwitchContext == null) { return; } ParseNode newContext = GetCurrentContext(); if (currentContext == null) { currentContext = newContext; } if (newContext == null) { return; } if (newContext.Token.Type != currentContext.Token.Type) { SwitchContext.Invoke(this, new ContextSwitchEventArgs(currentContext, newContext)); currentContext = newContext; } }