mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
backspace unindent handler from Python integrated into Ruby
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
package com.jetbrains.python.editor;
|
||||
|
||||
import com.intellij.codeInsight.editorActions.BackspaceHandler;
|
||||
import com.intellij.codeInsight.editorActions.BackspaceHandlerDelegate;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.jetbrains.python.PythonFileType;
|
||||
|
||||
/**
|
||||
@@ -15,32 +14,8 @@ public class PythonBackspaceHandler extends BackspaceHandlerDelegate {
|
||||
private LogicalPosition myTargetPosition;
|
||||
|
||||
public void beforeCharDeleted(final char c, final PsiFile file, final Editor editor) {
|
||||
myTargetPosition = null;
|
||||
if (PythonFileType.INSTANCE != file.getFileType()) return;
|
||||
if (editor.getSelectionModel().hasSelection() || editor.getSelectionModel().hasBlockSelection()) return;
|
||||
|
||||
LogicalPosition caretPos = editor.getCaretModel().getLogicalPosition();
|
||||
if (caretPos.line == 1 || caretPos.column == 0) {
|
||||
return;
|
||||
}
|
||||
int lineStartOffset = editor.getDocument().getLineStartOffset(caretPos.line);
|
||||
int lineEndOffset = editor.getDocument().getLineEndOffset(caretPos.line);
|
||||
|
||||
CharSequence charSeq = editor.getDocument().getCharsSequence();
|
||||
// smart backspace is activated only if all characters in the caret line
|
||||
// are whitespace characters
|
||||
for(int pos=lineStartOffset; pos<lineEndOffset; pos++) {
|
||||
if (charSeq.charAt(pos) != '\t' && charSeq.charAt(pos) != ' ' &&
|
||||
charSeq.charAt(pos) != '\n') {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(file.getProject());
|
||||
int column = caretPos.column - settings.getIndentSize(PythonFileType.INSTANCE);
|
||||
if (column < 0) column = 0;
|
||||
|
||||
myTargetPosition = new LogicalPosition(caretPos.line, column);
|
||||
myTargetPosition = BackspaceHandler.getBackspaceUnindentPosition(file, editor);
|
||||
}
|
||||
|
||||
public boolean charDeleted(final char c, final PsiFile file, final Editor editor) {
|
||||
|
||||
Reference in New Issue
Block a user