mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
add getCaretCount method to caret model API (IDEA-80056)
This commit is contained in:
@@ -180,6 +180,11 @@ public interface CaretModel {
|
||||
@NotNull
|
||||
Caret getPrimaryCaret();
|
||||
|
||||
/**
|
||||
* Returns number of carets currently existing in the document
|
||||
*/
|
||||
int getCaretCount();
|
||||
|
||||
/**
|
||||
* Returns all carets currently existing in the document, ordered by their position in the document.
|
||||
*/
|
||||
|
||||
@@ -90,7 +90,7 @@ public class PasteHandler extends EditorActionHandler implements EditorTextInser
|
||||
|
||||
final Project project = editor.getProject();
|
||||
if (project == null || editor.isColumnMode() || editor.getSelectionModel().hasBlockSelection()
|
||||
|| editor.getCaretModel().getAllCarets().size() > 1) {
|
||||
|| editor.getCaretModel().getCaretCount() > 1) {
|
||||
if (myOriginalHandler != null) {
|
||||
myOriginalHandler.execute(editor, context);
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ public class TypedHandler extends TypedActionHandlerBase {
|
||||
}
|
||||
}
|
||||
|
||||
if (!editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getAllCarets().size() == 1) {
|
||||
if (!editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getCaretCount() == 1) {
|
||||
if (')' == charTyped || ']' == charTyped || '}' == charTyped) {
|
||||
if (FileTypes.PLAIN_TEXT != fileType) {
|
||||
if (handleRParen(editor, fileType, charTyped)) return;
|
||||
@@ -210,7 +210,7 @@ public class TypedHandler extends TypedActionHandlerBase {
|
||||
|
||||
if (('(' == charTyped || '[' == charTyped || '{' == charTyped) &&
|
||||
CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET &&
|
||||
!editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getAllCarets().size() == 1 && fileType != FileTypes.PLAIN_TEXT) {
|
||||
!editor.getSelectionModel().hasBlockSelection() && editor.getCaretModel().getCaretCount() == 1 && fileType != FileTypes.PLAIN_TEXT) {
|
||||
handleAfterLParen(editor, fileType, charTyped);
|
||||
}
|
||||
else if ('}' == charTyped) {
|
||||
|
||||
@@ -167,7 +167,7 @@ public class TemplateState implements Disposable {
|
||||
}
|
||||
|
||||
private boolean isMultiCaretMode() {
|
||||
return myEditor != null && myEditor.getCaretModel().supportsMultipleCarets() && myEditor.getCaretModel().getAllCarets().size() > 1;
|
||||
return myEditor != null && myEditor.getCaretModel().getCaretCount() > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -165,6 +165,11 @@ public class CaretModelWindow implements CaretModel {
|
||||
return createInjectedCaret(myDelegate.getPrimaryCaret());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCaretCount() {
|
||||
return myDelegate.getCaretCount();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Caret> getAllCarets() {
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class UnselectPreviousOccurrenceAction extends EditorAction {
|
||||
|
||||
@Override
|
||||
public void execute(Editor editor, @Nullable Caret caret, DataContext dataContext) {
|
||||
if (editor.getCaretModel().getAllCarets().size() > 1) {
|
||||
if (editor.getCaretModel().getCaretCount() > 1) {
|
||||
editor.getCaretModel().removeCaret(editor.getCaretModel().getPrimaryCaret());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -165,7 +165,7 @@ public class EditorModificationUtil {
|
||||
if (text == null) return null;
|
||||
|
||||
if (editor.getCaretModel().supportsMultipleCarets()) {
|
||||
int caretCount = editor.getCaretModel().getAllCarets().size();
|
||||
int caretCount = editor.getCaretModel().getCaretCount();
|
||||
final Iterator<String> segments = new ClipboardTextPerCaretSplitter().split(text, caretCount).iterator();
|
||||
editor.getCaretModel().runForEachCaret(new CaretAction() {
|
||||
@Override
|
||||
|
||||
@@ -50,7 +50,7 @@ public class EscapeAction extends EditorAction {
|
||||
public boolean isEnabled(Editor editor, DataContext dataContext) {
|
||||
SelectionModel selectionModel = editor.getSelectionModel();
|
||||
CaretModel caretModel = editor.getCaretModel();
|
||||
return selectionModel.hasSelection() || selectionModel.hasBlockSelection() || caretModel.getAllCarets().size() > 1;
|
||||
return selectionModel.hasSelection() || selectionModel.hasBlockSelection() || caretModel.getCaretCount() > 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,6 +240,13 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCaretCount() {
|
||||
synchronized (myCarets) {
|
||||
return myCarets.size();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Caret> getAllCarets() {
|
||||
|
||||
+5
@@ -150,6 +150,11 @@ public class TextComponentCaretModel implements CaretModel {
|
||||
return myCaret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCaretCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<Caret> getAllCarets() {
|
||||
|
||||
Reference in New Issue
Block a user