Skip to content

Commit 798869a

Browse files
authored
Merge pull request #17 from unv-unv/enter-handler-refactoring
Refactoring of enter handlers and configuration producers
2 parents df04896 + de2d422 commit 798869a

File tree

9 files changed

+1133
-1161
lines changed

9 files changed

+1133
-1161
lines changed

python-impl/src/main/java/com/jetbrains/python/impl/editor/PyEnterAtIndentHandler.java

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,37 @@
2626
import consulo.language.editor.inject.EditorWindow;
2727
import consulo.language.inject.InjectedLanguageManager;
2828
import consulo.language.psi.PsiFile;
29-
import consulo.util.lang.ref.Ref;
30-
29+
import consulo.util.lang.ref.SimpleReference;
3130
import jakarta.annotation.Nonnull;
3231

3332
/**
3433
* @author yole
3534
*/
3635
@ExtensionImpl
3736
public class PyEnterAtIndentHandler extends EnterHandlerDelegateAdapter {
38-
@Override
39-
public Result preprocessEnter(@Nonnull PsiFile file,
40-
@Nonnull Editor editor,
41-
@Nonnull Ref<Integer> caretOffset,
42-
@Nonnull Ref<Integer> caretAdvance,
43-
@Nonnull DataContext dataContext,
44-
EditorActionHandler originalHandler) {
45-
int offset = caretOffset.get();
46-
if (editor instanceof EditorWindow) {
47-
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
48-
editor = EditorWindow.getTopLevelEditor(editor);
49-
offset = editor.getCaretModel().getOffset();
50-
}
51-
if (!(file instanceof PyFile)) {
52-
return Result.Continue;
53-
}
37+
@Override
38+
public Result preprocessEnter(
39+
@Nonnull PsiFile file,
40+
@Nonnull Editor editor,
41+
@Nonnull SimpleReference<Integer> caretOffset,
42+
@Nonnull SimpleReference<Integer> caretAdvance,
43+
@Nonnull DataContext dataContext,
44+
EditorActionHandler originalHandler
45+
) {
46+
int offset = caretOffset.get();
47+
if (editor instanceof EditorWindow) {
48+
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
49+
editor = EditorWindow.getTopLevelEditor(editor);
50+
offset = editor.getCaretModel().getOffset();
51+
}
52+
if (!(file instanceof PyFile)) {
53+
return Result.Continue;
54+
}
5455

55-
// honor dedent (PY-3009)
56-
if (EditorBackspaceUtil.isWhitespaceBeforeCaret(editor)) {
57-
return Result.DefaultSkipIndent;
56+
// honor dedent (PY-3009)
57+
if (EditorBackspaceUtil.isWhitespaceBeforeCaret(editor)) {
58+
return Result.DefaultSkipIndent;
59+
}
60+
return Result.Continue;
5861
}
59-
return Result.Continue;
60-
}
6162
}

python-impl/src/main/java/com/jetbrains/python/impl/editor/PyEnterBetweenBracketsHandler.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,42 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package com.jetbrains.python.impl.editor;
1817

18+
import com.jetbrains.python.PythonLanguage;
19+
import consulo.annotation.access.RequiredReadAction;
1920
import consulo.annotation.component.ExtensionImpl;
20-
import consulo.ide.impl.idea.codeInsight.editorActions.enter.EnterBetweenBracesHandler;
21-
import consulo.dataContext.DataContext;
2221
import consulo.codeEditor.Editor;
2322
import consulo.codeEditor.action.EditorActionHandler;
24-
import consulo.util.lang.ref.Ref;
23+
import consulo.dataContext.DataContext;
24+
import consulo.ide.impl.idea.codeInsight.editorActions.enter.EnterBetweenBracesHandler;
2525
import consulo.language.psi.PsiFile;
26-
import com.jetbrains.python.PythonLanguage;
26+
import consulo.util.lang.ref.SimpleReference;
2727
import jakarta.annotation.Nonnull;
2828

2929
/**
3030
* @author yole
3131
*/
3232
@ExtensionImpl
3333
public class PyEnterBetweenBracketsHandler extends EnterBetweenBracesHandler {
34-
@Override
35-
public Result preprocessEnter(@Nonnull PsiFile file,
36-
@Nonnull Editor editor,
37-
@Nonnull Ref<Integer> caretOffsetRef,
38-
@Nonnull Ref<Integer> caretAdvance,
39-
@Nonnull DataContext dataContext,
40-
EditorActionHandler originalHandler) {
41-
if (!file.getLanguage().is(PythonLanguage.getInstance())) {
42-
return Result.Continue;
34+
@Override
35+
@RequiredReadAction
36+
public Result preprocessEnter(
37+
@Nonnull PsiFile file,
38+
@Nonnull Editor editor,
39+
@Nonnull SimpleReference<Integer> caretOffsetRef,
40+
@Nonnull SimpleReference<Integer> caretAdvance,
41+
@Nonnull DataContext dataContext,
42+
EditorActionHandler originalHandler
43+
) {
44+
if (!file.getLanguage().is(PythonLanguage.getInstance())) {
45+
return Result.Continue;
46+
}
47+
return super.preprocessEnter(file, editor, caretOffsetRef, caretAdvance, dataContext, originalHandler);
4348
}
44-
return super.preprocessEnter(file, editor, caretOffsetRef, caretAdvance, dataContext, originalHandler);
45-
}
4649

47-
@Override
48-
protected boolean isBracePair(char c1, char c2) {
49-
return c1 == '[' && c2 == ']';
50-
}
50+
@Override
51+
protected boolean isBracePair(char c1, char c2) {
52+
return c1 == '[' && c2 == ']';
53+
}
5154
}

0 commit comments

Comments
 (0)