mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-93998 In overwrite mode it is impossible to add new line to the file
This commit is contained in:
@@ -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--) {
|
||||
|
||||
+7
@@ -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>");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user