Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,37 @@
import consulo.language.editor.inject.EditorWindow;
import consulo.language.inject.InjectedLanguageManager;
import consulo.language.psi.PsiFile;
import consulo.util.lang.ref.Ref;

import consulo.util.lang.ref.SimpleReference;
import jakarta.annotation.Nonnull;

/**
* @author yole
*/
@ExtensionImpl
public class PyEnterAtIndentHandler extends EnterHandlerDelegateAdapter {
@Override
public Result preprocessEnter(@Nonnull PsiFile file,
@Nonnull Editor editor,
@Nonnull Ref<Integer> caretOffset,
@Nonnull Ref<Integer> caretAdvance,
@Nonnull DataContext dataContext,
EditorActionHandler originalHandler) {
int offset = caretOffset.get();
if (editor instanceof EditorWindow) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
editor = EditorWindow.getTopLevelEditor(editor);
offset = editor.getCaretModel().getOffset();
}
if (!(file instanceof PyFile)) {
return Result.Continue;
}
@Override
public Result preprocessEnter(
@Nonnull PsiFile file,
@Nonnull Editor editor,
@Nonnull SimpleReference<Integer> caretOffset,
@Nonnull SimpleReference<Integer> caretAdvance,
@Nonnull DataContext dataContext,
EditorActionHandler originalHandler
) {
int offset = caretOffset.get();
if (editor instanceof EditorWindow) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
editor = EditorWindow.getTopLevelEditor(editor);
offset = editor.getCaretModel().getOffset();
}
if (!(file instanceof PyFile)) {
return Result.Continue;
}

// honor dedent (PY-3009)
if (EditorBackspaceUtil.isWhitespaceBeforeCaret(editor)) {
return Result.DefaultSkipIndent;
// honor dedent (PY-3009)
if (EditorBackspaceUtil.isWhitespaceBeforeCaret(editor)) {
return Result.DefaultSkipIndent;
}
return Result.Continue;
}
return Result.Continue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,42 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.jetbrains.python.impl.editor;

import com.jetbrains.python.PythonLanguage;
import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.component.ExtensionImpl;
import consulo.ide.impl.idea.codeInsight.editorActions.enter.EnterBetweenBracesHandler;
import consulo.dataContext.DataContext;
import consulo.codeEditor.Editor;
import consulo.codeEditor.action.EditorActionHandler;
import consulo.util.lang.ref.Ref;
import consulo.dataContext.DataContext;
import consulo.ide.impl.idea.codeInsight.editorActions.enter.EnterBetweenBracesHandler;
import consulo.language.psi.PsiFile;
import com.jetbrains.python.PythonLanguage;
import consulo.util.lang.ref.SimpleReference;
import jakarta.annotation.Nonnull;

/**
* @author yole
*/
@ExtensionImpl
public class PyEnterBetweenBracketsHandler extends EnterBetweenBracesHandler {
@Override
public Result preprocessEnter(@Nonnull PsiFile file,
@Nonnull Editor editor,
@Nonnull Ref<Integer> caretOffsetRef,
@Nonnull Ref<Integer> caretAdvance,
@Nonnull DataContext dataContext,
EditorActionHandler originalHandler) {
if (!file.getLanguage().is(PythonLanguage.getInstance())) {
return Result.Continue;
@Override
@RequiredReadAction
public Result preprocessEnter(
@Nonnull PsiFile file,
@Nonnull Editor editor,
@Nonnull SimpleReference<Integer> caretOffsetRef,
@Nonnull SimpleReference<Integer> caretAdvance,
@Nonnull DataContext dataContext,
EditorActionHandler originalHandler
) {
if (!file.getLanguage().is(PythonLanguage.getInstance())) {
return Result.Continue;
}
return super.preprocessEnter(file, editor, caretOffsetRef, caretAdvance, dataContext, originalHandler);
}
return super.preprocessEnter(file, editor, caretOffsetRef, caretAdvance, dataContext, originalHandler);
}

@Override
protected boolean isBracePair(char c1, char c2) {
return c1 == '[' && c2 == ']';
}
@Override
protected boolean isBracePair(char c1, char c2) {
return c1 == '[' && c2 == ']';
}
}
Loading
Loading