IDEA-93998 In overwrite mode it is impossible to add new line to the file

This commit is contained in:
Dmitry Batrak
2014-10-13 19:13:05 +04:00
parent 2e4463a295
commit 8f1514a2ab
3 changed files with 17 additions and 4 deletions
@@ -56,6 +56,7 @@ public interface IdeActions {
@NonNls String ACTION_EDITOR_CLONE_CARET_BELOW= "EditorCloneCaretBelow";
@NonNls String ACTION_EDITOR_CLONE_CARET_ABOVE= "EditorCloneCaretAbove";
@NonNls String ACTION_EDITOR_TOGGLE_STICKY_SELECTION= "EditorToggleStickySelection";
@NonNls String ACTION_EDITOR_TOGGLE_OVERWRITE_MODE= "EditorToggleInsertState";
@NonNls String ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE = "NextTemplateVariable";
@NonNls String ACTION_EDITOR_PREVIOUS_TEMPLATE_VARIABLE = "PreviousTemplateVariable";
@@ -58,9 +58,15 @@ public class EnterAction extends EditorAction {
public static void insertNewLineAtCaret(Editor editor) {
MacUIUtil.hideCursor();
Document document = editor.getDocument();
int caretLine = editor.getCaretModel().getLogicalPosition().line;
if(!editor.isInsertMode()) {
if(editor.getCaretModel().getLogicalPosition().line < editor.getDocument().getLineCount()-1) {
LogicalPosition pos = new LogicalPosition(editor.getCaretModel().getLogicalPosition().line+1, 0);
int lineCount = document.getLineCount();
if(caretLine < lineCount) {
if (caretLine == lineCount - 1) {
document.insertString(document.getTextLength(), "\n");
}
LogicalPosition pos = new LogicalPosition(caretLine + 1, 0);
editor.getCaretModel().moveToLogicalPosition(pos);
editor.getSelectionModel().removeSelection();
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
@@ -69,10 +75,9 @@ public class EnterAction extends EditorAction {
}
EditorModificationUtil.deleteSelectedText(editor);
// Smart indenting here:
Document document = editor.getDocument();
CharSequence text = document.getCharsSequence();
int indentLineNum = editor.getCaretModel().getLogicalPosition().line;
int indentLineNum = caretLine;
int lineLength = 0;
if (document.getLineCount() > 0) {
for(;indentLineNum >= 0; indentLineNum--) {
@@ -138,4 +138,11 @@ public class EditorActionTest extends AbstractEditorTest {
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT);
assertEquals(new VisualPosition(0, 6), myEditor.getCaretModel().getVisualPosition());
}
public void testEnterOnLastLineInOverwriteMode() throws Exception {
init("text<caret>", TestFileType.TEXT);
executeAction(IdeActions.ACTION_EDITOR_TOGGLE_OVERWRITE_MODE);
executeAction(IdeActions.ACTION_EDITOR_ENTER);
checkResultByText("text\n<caret>");
}
}