Skip to content

Commit

Permalink
insert a newline if at the end of file
Browse files Browse the repository at this point in the history
  • Loading branch information
guoci committed Sep 18, 2023
1 parent 70c0c44 commit 72178fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.jetbrains.python.actions;

import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.editor.VisualPosition;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiDocumentManager;
Expand Down Expand Up @@ -169,7 +171,17 @@ static void smartExecuteCode(final AnActionEvent e, final Editor editor, final C
if (codeToSend != null) {
if (cursorMoveAfterExecute == CursorMoveAfterExecute.TO_NEXT_CODE_REGION
|| cursorMoveAfterExecute == CursorMoveAfterExecute.TO_THE_END_OF_CODE_BLOCK) {
final LogicalPosition posStart = editor.getCaretModel().getLogicalPosition();
moveCaretDown(editor, numLinesToSubmit);
final LogicalPosition posEnd = editor.getCaretModel().getLogicalPosition();
if (posStart.line + numLinesToSubmit != posEnd.line) { // if lines moved less than lines submitted, insert newline
// https://plugins.jetbrains.com/docs/intellij/working-with-text.html
Project project = e.getRequiredData(CommonDataKeys.PROJECT);
Document doc = editor.getDocument();
WriteCommandAction.runWriteCommandAction(project,
() -> doc.insertString(editor.logicalPositionToOffset(posEnd), "\n"));
moveCaretDown(editor, 1);
}
}
if (cursorMoveAfterExecute == CursorMoveAfterExecute.TO_NEXT_CODE_REGION) {
int currentOffset = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<idea-plugin>
<id>python-smart-execute</id>
<name>Python Smart Execute</name>
<version>0.3.1</version>
<version>0.3.2</version>
<vendor email="[email protected]" url="https://github.com/guoci">Guo Ci</vendor>

<description><![CDATA[
Expand Down

0 comments on commit 72178fd

Please sign in to comment.