Created
December 11, 2011 04:41
-
-
Save Dremora/1458384 to your computer and use it in GitHub Desktop.
Monochrome — Ctrl+Backspace/Ctrl+Delete key support
This file contains hidden or 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
*** InputBoxOriginal.cs Thu May 22 14:19:10 2008 | |
--- InputBox.cs Sun Dec 11 05:44:10 2011 | |
*************** | |
*** 6,11 **** | |
--- 6,12 ---- | |
using System.Text; | |
using System.Windows.Forms; | |
using IRCUtils; | |
+ using System.Text.RegularExpressions; | |
namespace monochrome | |
{ | |
*************** | |
*** 47,53 **** | |
--- 48,98 ---- | |
e.Handled = true; | |
} | |
break; | |
+ case Keys.Back: | |
+ if (ModifierKeys == Keys.Control) { | |
+ if (SelectionLength != 0) { | |
+ Paste(""); | |
+ } else { | |
+ RemovePreviousWord(); | |
+ } | |
+ e.Handled = true; | |
+ e.SuppressKeyPress = true; | |
+ } | |
+ break; | |
+ case Keys.Delete: | |
+ if (ModifierKeys == Keys.Control) { | |
+ if (SelectionLength != 0) { | |
+ Paste(""); | |
+ } else { | |
+ RemoveNextWord(); | |
+ } | |
+ e.Handled = true; | |
+ e.SuppressKeyPress = true; | |
+ } | |
+ break; | |
} | |
+ } | |
+ } | |
+ | |
+ private static Regex previousWordPattern = new Regex(@"(?:\w*|[^\w\s]*)\s*$"); | |
+ private void RemovePreviousWord() | |
+ { | |
+ if (SelectionStart > 0) { | |
+ String beginning = Text.Substring(0, SelectionStart); | |
+ int matched = previousWordPattern.Match(beginning).Length; | |
+ SelectionStart -= matched; | |
+ SelectionLength = matched; | |
+ Paste(""); | |
+ } | |
+ } | |
+ | |
+ private static Regex nextWordPattern = new Regex(@"^\s*(?:\w+|[^\w\s]+)"); | |
+ private void RemoveNextWord() | |
+ { | |
+ String end = Text.Substring(SelectionStart); | |
+ if (end.Length > 0) { | |
+ SelectionLength = nextWordPattern.Match(end).Length; | |
+ Paste(""); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment