While commit 6e8224c5 implemented the correct logic, it is only valid if the current tool is the Reference Image tool.
There's a method for just this purpose, KoToolBase::hasSelection(), but the existing flow stems from SelectionHandler::hasSelection, which operates only with shapes. So this commit implements the corresponding override and changes the check to query the current tool instead.
Build Krita. Open an image, insert a reference image, then draw on the canvas. Check that selecting something and copy-pasting it returns the existing selection in all cases.
I confirmed this builds.
I confirmed Krita ran and the relevant functions work.
I tested the relevant unit tests and can confirm they are not broken. (If not possible, don't hesitate to ask for help!)
I made sure my commits build individually and have good descriptions as per KDE guidelines.
I made sure my code conforms to the standards set in the HACKING file.
I can confirm the code is licensed and attributed appropriately, and that unattributed code is mine, as per KDE Licensing Policy.