icsharpcode / AvalonEdit

The WPF-based text editor component used in SharpDevelop
http://avalonedit.net/
MIT License
1.86k stars 472 forks source link

Double click on word should move caret to end of selection #37

Closed nippur72 closed 9 years ago

nippur72 commented 9 years ago

If you double click on a word to select it, selection is correct but caret isn't moved at the end of word/selection as in normal text editors.

I tried to fix it myself in SelectionMouseHandler.cs\textArea_MouseLeftButtonDown() with

textArea.Caret.Offset = startWord.EndOffset;                     

but the caret keeps returning on the old position. Perhaps it's related to this comment:

// Set caret offset, but limit the caret to stay inside the selection.
// in whole-word selection, it's otherwise possible that we get the caret outside the
// selection - but the TextArea doesn't like that and will reset the selection, causing
// flickering.

but I don't know how to handle it.

dgrunwald commented 9 years ago

This is intentional behavior: textArea_MouseMove in word-selection mode calls SetCaretOffsetToMousePosition (directly below the comment you quoted). You could replace that call with

textArea.Caret.Offset = newWord.Offset > startWord.Offset ? newWord.EndOffset : newWord.Offset;

That change would make the comment and the allowedSegment parameter redundant.