Skip to content

Commit fd7155f

Browse files
committed
Fix #37 moving caret to start or end of selection
Selecting a word now causes the caret to move to the end of the selection. If selection is done backward (ctrl + mouse) the caret is moved to the start of the selection. If it's selecting the whole line (triple click) the caret is moved to the end.
1 parent 532cab0 commit fd7155f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

ICSharpCode.AvalonEdit/Editing/SelectionMouseHandler.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,11 @@ void ExtendSelectionToMouse(MouseEventArgs e)
644644
textArea.Selection = Selection.Create(textArea,
645645
Math.Min(newWord.Offset, startWord.Offset),
646646
Math.Max(newWord.EndOffset, startWord.EndOffset));
647-
// Set caret offset, but limit the caret to stay inside the selection.
648-
// in whole-word selection, it's otherwise possible that we get the caret outside the
649-
// selection - but the TextArea doesn't like that and will reset the selection, causing
650-
// flickering.
651-
SetCaretOffsetToMousePosition(e, textArea.Selection.SurroundingSegment);
647+
// moves caret to start or end of selection
648+
if( newWord.Offset < startWord.Offset)
649+
textArea.Caret.Offset = newWord.Offset;
650+
else
651+
textArea.Caret.Offset = Math.Max(newWord.EndOffset, startWord.EndOffset);
652652
}
653653
}
654654
textArea.Caret.BringCaretToView(5.0);

0 commit comments

Comments
 (0)