@Override
  public void select(int startOffset, int endOffset) {
    // This method is called by the JDK on macOS, when the IME asks us to replace already committed text.
    // Doing this is a bit complicated, since we have to account for multi-caret.

    String selectedText = editor.getDocument().getText(new TextRange(startOffset, endOffset));

    int length = endOffset - startOffset;
    int offsetRelativeToCurrentCaret = startOffset - editor.getCaretModel().getCurrentCaret().getOffset();

    boolean allCaretsHaveTheSameText = true;

    for (var caret : editor.getCaretModel().getAllCarets()) {
      var caretStart = offsetRelativeToCurrentCaret + caret.getOffset();
      var caretEnd = caretStart + length;
      String caretText = editor.getDocument().getText(new TextRange(caretStart, caretEnd));
      if (!selectedText.equals(caretText)) {
        allCaretsHaveTheSameText = false;
        break;
      }
    }

    if (allCaretsHaveTheSameText) {
      for (var caret : editor.getCaretModel().getAllCarets()) {
        var caretStart = offsetRelativeToCurrentCaret + caret.getOffset();
        var caretEnd = caretStart + length;
        caret.setSelection(caretStart, caretEnd);
      }
    } else {
      // Fallback to the default implementation
      editor.getSelectionModel().setSelection(startOffset, endOffset);
    }
  }
@Override
  public void select(int startOffset, int endOffset)