IDEABKL-6984 Add Eclipse Style Paren/Bracket/Quote Completiton

API refactoring (following IDEA-CR-31740)
This commit is contained in:
Dmitry Batrak
2018-04-16 11:32:16 +03:00
parent 519598d1f2
commit 6c8cb2d1c4
3 changed files with 24 additions and 6 deletions
@@ -26,8 +26,15 @@ public interface TabOutScopesTracker {
/**
* Checks whether given offset is at the end of tracked scope (so if caret is located at that offset, Tab key can be used to move out of
* the scope).
*
* @param removeScope if {@code true}, corresponding scope (if any) will be removed after the call
*/
boolean hasScopeEndingAt(@NotNull Editor editor, int offset, boolean removeScope);
boolean hasScopeEndingAt(@NotNull Editor editor, int offset);
/**
* Removes a tracked scope (if any) ending at the given offset.
*
* @return whether there was a scope ending at given offset
*
* @see #hasScopeEndingAt(Editor, int)
*/
boolean removeScopeEndingAt(@NotNull Editor editor, int offset);
}
@@ -22,14 +22,14 @@ public class BraceOrQuoteOutAction extends EditorAction {
@Override
protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
int caretOffset = caret.getOffset();
return TabOutScopesTracker.getInstance().hasScopeEndingAt(editor, caretOffset, false);
return TabOutScopesTracker.getInstance().hasScopeEndingAt(editor, caretOffset);
}
@Override
protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
assert caret != null;
int caretOffset = caret.getOffset();
if (TabOutScopesTracker.getInstance().hasScopeEndingAt(editor, caretOffset, true)) {
if (TabOutScopesTracker.getInstance().removeScopeEndingAt(editor, caretOffset)) {
caret.moveToOffset(caretOffset + 1);
}
}
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.List;
public class TabOutScopesTrackerImpl implements TabOutScopesTracker {
@Override
public void registerEmptyScope(@NotNull Editor editor, int offset) {
ApplicationManager.getApplication().assertIsDispatchThread();
assert !editor.isDisposed() : "Disposed editor";
@@ -39,7 +40,17 @@ public class TabOutScopesTrackerImpl implements TabOutScopesTracker {
tracker.registerScope(offset);
}
public boolean hasScopeEndingAt(@NotNull Editor editor, int offset, boolean removeScope) {
@Override
public boolean hasScopeEndingAt(@NotNull Editor editor, int offset) {
return checkOrRemoveScopeEndingAt(editor, offset, false);
}
@Override
public boolean removeScopeEndingAt(@NotNull Editor editor, int offset) {
return checkOrRemoveScopeEndingAt(editor, offset, true);
}
private static boolean checkOrRemoveScopeEndingAt(@NotNull Editor editor, int offset, boolean removeScope) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (!CodeInsightSettings.getInstance().TAB_EXITS_BRACKETS_AND_QUOTES) return false;