Cheaters Never Prosper
By Adrian Sutton
The development I seem to do these days tends to run at the extremes of reliability – either it has to be fully tested, nice, clean, production ready code, or it’s complete throw away code where development time is the only consideration.
The advantage of doing this rapid fire development is that you wind up with proof of concept code for most situations you’re every likely to run into. The disadvantage is that the code is rubbish and probably no use to you at all. That bit me once again today. I wanted to quickly whip up a plugin that makes pasting plain text into EditLive! work the way I want it to. I have a plugin that filters pasted content to wrap it in a blockquote for my blog so clearly I could just reuse that as a starting point. Sadly, I cheated:
protected void pasteAsQuote() { getBean().insertHTMLAtCursor("<blockquote> </blockquote>"); getHTMLPane().setSelectionStart(getHTMLPane().getCaretPosition() - 2); getHTMLPane().setSelectionEnd(getHTMLPane().getCaretPosition() - 1); getHTMLPane().paste(); }
Why bother actually filtering the clipboard content when you can just insert a blockquote tag manually, select it’s content and then paste. The hard coded offsets are pretty much guaranteed to cause sudden hair loss in the future when something changes, but I’ve got to admit, it’s been working really well for now.
It just doesn’t help me with my currently task…