Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Replace default "tab means tab to next control" action.
- // Note: This isn't even an alpha; I'm fiddling with this problem now.
- case VirtualKey.Tab:
- if (Window.Current.CoreWindow.GetKeyState(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down))
- {
- StringBuilder builder = new StringBuilder();
- string[] astrLines = this.SelectedText.Split(this.SelectionLineEnding); // I'm doing lots of xplat stuff. SelectionLineEnding in a UWP TextBox is \r
- string toAppend = string.Empty;
- if (astrLines.Length > 0 && astrLines[astrLines.Length - 1].EndsWith(this.SelectionLineEnding))
- {
- astrLines[astrLines.Length - 1] = astrLines[astrLines.Length - 1].RemoveLastNewLine(true); // In this case, blasts last \r if it exists
- toAppend = this.SelectionLineEnding;
- }
- foreach (string line in astrLines)
- {
- // See below for _deleteATab...
- builder.Append(_deleteATabWorthOfLeadingSpaces(line) + this.SelectionLineEnding);
- }
- this.SelectedText = builder.ToString().RemoveLastNewLine(true) + toAppend;
- }
- else
- {
- // MdTextBox is an extension of TextBox, and Tab is just a string of spaces that's whatever the user says Tab should be (default " ")
- this.SelectedText = MdTextBox.Tab + this.SelectedText.Replace(this.SelectionLineEnding, this.SelectionLineEnding + MdTextBox.Tab);
- if (this.SelectedText.EndsWith(this.SelectionLineEnding))
- {
- this.SelectedText = this.SelectedText.DeleteLastNChars(MdTextBox.Tab.Length); // Does what it seems to; Removes X characters from the end of the string.
- }
- }
- e.Handled = true;
- break;
- // ...
- private string _deleteATabWorthOfLeadingSpaces(string value)
- {
- string ret = value;
- int intTabSize = MdTextBox.Tab.Length;
- Tuple<string, string> tupe = value.PullLeadingAndTrailingSpaces(); // Tuple will have Item1 with spaces at front & Item2 with spaces at end
- if (tupe.Item1.Length >= intTabSize)
- {
- ret = value.Substring(intTabSize);
- }
- else if (tupe.Item1.Length > 0)
- {
- ret = value.Substring(tupe.Item1.Length);
- }
- return ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement