Hi Takayuki,
I saw your patch, and glad you did it.
And I tested latest v3.9 beta and your patch, it works fine.
And I agree with @nacin on this, as you don’t need a dialog box for pre.
Otherwise its working fine.
I think you should keep it simple,
don’t assume / detect anything in your code (like whether I should wrap “code” or “pre” around selected text, instead why not provide dropdown selection (similar to “Text Color” button, which list down colors), so you can show pre / code as two option and leave it upto the user to select which one, as the user who is going to use code / pre tags will surely be the one who knows what they do, and will have to select either function name, tag or word for applying code tag (inline) or for block level pre they have to select multiline text etc.
I am hoping my suggestion is useful for you.