mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-62589 Soft wraps: the caret is shown in a position where nothing can be actually typed
1. Performing 'soft wrap -> hard wrap' conversion if user starts typing in soft wrap-introduced virtual space; 2. Corresponding test is added;
This commit is contained in:
@@ -446,11 +446,14 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
|
||||
if (!isInsideSoftWrap(visualCaretPosition)) {
|
||||
return;
|
||||
}
|
||||
//TODO den implement
|
||||
//if (myDocumentChangeManager.makeHardWrap(caretModel.getOffset())) {
|
||||
// // Restore caret position.
|
||||
// caretModel.moveToVisualPosition(visualCaretPosition);
|
||||
//}
|
||||
|
||||
SoftWrap softWrap = myStorage.getSoftWrap(caretModel.getOffset());
|
||||
if (softWrap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
myEditor.getDocument().replaceString(softWrap.getStart(), softWrap.getEnd(), softWrap.getText());
|
||||
caretModel.moveToVisualPosition(visualCaretPosition);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+30
@@ -538,6 +538,36 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorP
|
||||
assertEquals(expectedVisualLine, caretModel.getVisualPosition().line);
|
||||
}
|
||||
|
||||
public void testSoftWrapToHardWrapConversion() throws IOException {
|
||||
String text =
|
||||
"this is line 1\n" +
|
||||
"this is line 2\n" +
|
||||
"this is line 3\n" +
|
||||
"this is line 4\n" +
|
||||
"this is line 5";
|
||||
|
||||
init(50, text);
|
||||
VisualPosition changePosition = new VisualPosition(1, 0);
|
||||
myEditor.getCaretModel().moveToVisualPosition(changePosition);
|
||||
|
||||
int logicalLinesBefore = myEditor.offsetToLogicalPosition(text.length()).line;
|
||||
int offsetBefore = myEditor.getCaretModel().getOffset();
|
||||
|
||||
LogicalPosition logicalPositionBefore = myEditor.visualToLogicalPosition(changePosition);
|
||||
assertEquals(1, logicalPositionBefore.softWrapLinesOnCurrentLogicalLine);
|
||||
assertTrue(logicalPositionBefore.column > 0);
|
||||
|
||||
SoftWrap softWrap = getSoftWrapModel().getSoftWrap(offsetBefore);
|
||||
assertNotNull(softWrap);
|
||||
|
||||
type('a');
|
||||
|
||||
LogicalPosition logicalPositionAfter = myEditor.visualToLogicalPosition(changePosition);
|
||||
assertEquals(new LogicalPosition(1, 0, 0, 0, 0, 0, 0), logicalPositionAfter);
|
||||
assertEquals(offsetBefore + softWrap.getText().length() + 1, myEditor.getCaretModel().getOffset());
|
||||
assertEquals(logicalLinesBefore + 1, myEditor.offsetToLogicalPosition(text.length()).line);
|
||||
}
|
||||
|
||||
//public void testPastingInsideSelection() throws IOException {
|
||||
// String text =
|
||||
// "this is line number 0\n" +
|
||||
|
||||
Reference in New Issue
Block a user