Example usage for com.intellij.openapi.ide KillRingTransferable getEndOffset

List of usage examples for com.intellij.openapi.ide KillRingTransferable getEndOffset

Introduction

In this page you can find the example usage for com.intellij.openapi.ide KillRingTransferable getEndOffset.

Prototype

public int getEndOffset() 

Source Link

Usage

From source file:com.intellij.ide.CopyPasteManagerEx.java

License:Apache License

/**
 * Merges given new data with the given old one and returns merge result in case of success.
 *
 * @param newData new data to merge//w w  w  . j  ava 2 s .c om
 * @param oldData old data to merge
 * @return merge result of the given data if possible; <code>null</code> otherwise
 * @throws IOException                as defined by {@link Transferable#getTransferData(DataFlavor)}
 * @throws UnsupportedFlavorException as defined by {@link Transferable#getTransferData(DataFlavor)}
 */
@Nullable
private static Transferable merge(@NotNull KillRingTransferable newData, @NotNull KillRingTransferable oldData)
        throws IOException, UnsupportedFlavorException {
    if (!oldData.isReadyToCombine() || !newData.isReadyToCombine()) {
        return null;
    }

    Document document = newData.getDocument();
    if (document == null || document != oldData.getDocument()) {
        return null;
    }

    Object newDataText = newData.getTransferData(DataFlavor.stringFlavor);
    Object oldDataText = oldData.getTransferData(DataFlavor.stringFlavor);
    if (newDataText == null || oldDataText == null) {
        return null;
    }

    if (oldData.isCut()) {
        if (newData.getStartOffset() == oldData.getStartOffset()) {
            return new KillRingTransferable(oldDataText.toString() + newDataText, document,
                    oldData.getStartOffset(), newData.getEndOffset(), newData.isCut());
        }
    }

    if (newData.getStartOffset() == oldData.getEndOffset()) {
        return new KillRingTransferable(oldDataText.toString() + newDataText, document,
                oldData.getStartOffset(), newData.getEndOffset(), false);
    }

    if (newData.getEndOffset() == oldData.getStartOffset()) {
        return new KillRingTransferable(newDataText.toString() + oldDataText, document,
                newData.getStartOffset(), oldData.getEndOffset(), false);
    }

    return null;
}