Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created January 22, 2016 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjoerntx/eb4188e9884f7d6dd780 to your computer and use it in GitHub Desktop.
Save bjoerntx/eb4188e9884f7d6dd780 to your computer and use it in GitHub Desktop.
private void textControl1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.Delete)
{
// get the current paragraph at the input position
TXTextControl.Paragraph curParagraph =
textControl1.Paragraphs.GetItem(textControl1.Selection.Start);
// return the text beginning at the input position
// until the end of the paragraph
string sParagraph = curParagraph.Text.Substring(
textControl1.Selection.Start - curParagraph.Start + 1);
// search for delimiters and return the positions
List<int> indexes = Regex.Matches(sParagraph, @"[^\w]+").Cast<Match>()
.Select(m => m.Index)
.ToList();
// if delimiters are found, select the text until the next
// delimiter and remove the text
if (indexes.Count > 0)
{
textControl1.Selection.Length = indexes[0] + 1;
textControl1.Selection.Text = "";
// cancel the original event handling
e.Handled = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment