IDEA-178809 Issue with sticky selection near the end of document

This commit is contained in:
Dmitry Batrak
2017-09-12 18:38:56 +03:00
parent 56d02ca28a
commit 92bc10ed20
2 changed files with 8 additions and 1 deletions
@@ -458,7 +458,7 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
@Override
public void caretPositionChanged(CaretEvent e) {
if (myStickySelection) {
int selectionStart = Math.min(myStickySelectionStart, getDocument().getTextLength() - 1);
int selectionStart = Math.min(myStickySelectionStart, getDocument().getTextLength());
mySelectionModel.setSelection(selectionStart, myCaretModel.getVisualPosition(), myCaretModel.getOffset());
}
@@ -514,4 +514,11 @@ public class EditorImplTest extends AbstractEditorTest {
assertFalse(inlay.isValid() && inlay.getOffset() == 1);
assertFalse(region.isValid() && (region.getStartOffset() == 1 || region.getEndOffset() == 1));
}
public void testStickySelectionAtDocumentEnd() {
initText("ab<caret>");
((EditorEx)myEditor).setStickySelection(true);
left();
checkResultByText("a<selection><caret>b</selection>");
}
}