Created
January 22, 2016 10:32
-
-
Save bjoerntx/eb4188e9884f7d6dd780 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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