A number of fixes so the selector for RichTextBoxes will work properly.
* If you press a left arrow when a link starts a line, the cursor will go to the end of the previous line. * If you press the END key, the cursor will not go beyond the end of the line. * If you place the cursor at the beginning of a line, and then click beyond the end of the previous line, the cursor will go to the end of the previous line
This commit is contained in:
parent
f49aae2e7c
commit
a6c0dcddd0
@ -489,6 +489,7 @@ namespace Volian.Controls.Library
|
||||
if (!_ContextMenuStripChanged && this.MyStepItem != null)
|
||||
this.MyStepItem.MyStepPanel.MyStepTabPanel.MyStepTabRibbon.SetContextMenu();
|
||||
_ContextMenuStripChanged = false;
|
||||
CorrectSelectionAtEndOfLine();
|
||||
}
|
||||
void StepRTB_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
@ -1110,6 +1111,9 @@ namespace Volian.Controls.Library
|
||||
//vlnStackTrace.ShowStackLocal("HandleSelectionChangeStack", 1, 10);
|
||||
bool startingValue = _AdjustingSelection;
|
||||
if (_IdentifyingLinks || _ProcessingDelete) return;
|
||||
// If the cursor is beyond the end of the line then move the cursor back one character
|
||||
if (CorrectSelectionAtEndOfLine())
|
||||
return;
|
||||
if (ProcessKeystrokes)
|
||||
{
|
||||
if (!_MouseDown && !_AdjustingSelection)
|
||||
@ -1130,7 +1134,7 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
// If the cursor is at the beginning of the line and a link is at the beginning of the line
|
||||
// then select the link rather than postitioning the cursor at the end of the previous line
|
||||
if (GetFirstCharIndexOfCurrentLine() == SelectionStart)
|
||||
if (!_LastWasLeftArrow && GetFirstCharIndexOfCurrentLine() == SelectionStart)
|
||||
SetSelection(ll);
|
||||
else
|
||||
{
|
||||
@ -1187,6 +1191,22 @@ namespace Volian.Controls.Library
|
||||
else
|
||||
MyLinkText = null;
|
||||
OnRTBSelectionChanged(this, new EventArgs());
|
||||
_LastWasLeftArrow = false;
|
||||
}
|
||||
/// <summary>
|
||||
/// If the Selection is beyond the end of the line, move the selection back one character
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool CorrectSelectionAtEndOfLine()
|
||||
{
|
||||
if (SelectionStart > 0 && SelectionLength == 0 &&
|
||||
GetFirstCharIndexFromLine(GetLineFromCharIndex(SelectionStart)) >
|
||||
GetFirstCharIndexOfCurrentLine())
|
||||
{
|
||||
SelectionStart--; // Move the cursor back one character
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//private void HandleOverWrite()
|
||||
@ -2634,12 +2654,18 @@ namespace Volian.Controls.Library
|
||||
DebugPrint(where, ": {0} {1} '{2}'", SelectionStart, SelectionLength, SelectedText);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private bool _LastWasLeftArrow = false;
|
||||
private void StepRTB_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
||||
{
|
||||
//Console.WriteLine("StepRTB_PreviewKeyDown");
|
||||
if ((e.KeyCode == Keys.Tab) && (!e.Alt && !e.Control))
|
||||
e.IsInputKey = true;
|
||||
// Remember if the last key pressed was a left arrow. This is used in HandleSelectionChanged
|
||||
// When a Link overlaps the beginning of a line. Normally a left arrow will move the cursor
|
||||
// back one character, or if a Link is selected, it will move the cursor to the space before
|
||||
// the link. Since the Link overlaps the line, special consideration must be given to assure
|
||||
// that the cursor goes to the proper place.
|
||||
_LastWasLeftArrow = (!e.Shift && !e.Control && !e.Alt && e.KeyCode == Keys.Left);
|
||||
}
|
||||
}
|
||||
public partial class StepRTBModeChangeEventArgs : EventArgs
|
||||
|
Loading…
x
Reference in New Issue
Block a user