Adobe AIR 1.5 OS X shift-space bug workaround
Savvas Malamas just retweeted Mike Chambers's tweet on how the Adobe AIR 1.5 shift-space bug is apparently fixed in an internal build. In doing so, he reminded me to release my own workaround for it so you don't have to wait for the official release to patch your AIR apps. (This is especially true for those Twitter clients out there!)
So, here goes, until the official fix is in, you can use this workaround that extends the TextArea component to re-enable shift-spaces:
<?xml version="1.0" encoding="utf-8"?>
<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml" addedToStage="init(event)">
<mx:Script>
<![CDATA[
// This fixes the shift-space bug in Adobe AIR 1.5
// Released under the open source MIT License.
// Copyright (c) 2009 Aral Balkan. http://aralbalkan.com
import flash.events.KeyboardEvent;
private function init(event)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownListener);
}
private function keyDownListener(e:KeyboardEvent):void
{
// If shift and space are being held down together...
if (e.keyCode == 32 && e.shiftKey)
{
// ... add the space at the current location.
var caretIndex:int = textField.caretIndex;
var firstPart:String = textField.text.substr(0, caretIndex);
var secondPart:String = textField.text.substr(caretIndex, textField.length);
var newString = firstPart + ' ' + secondPart;
textField.text = newString;
var newCaretIndex = caretIndex + 1;
textField.setSelection(newCaretIndex, newCaretIndex);
}
}
]]>
</mx:Script>
</mx:TextArea>
Enjoy!
(So Twhirl, get to it and implement this already!) :)
Comments
by Spike on 2009-02-21 21:11:16
by localToGlobal » Blog Archive » news review -> 5th week of 2009 on 2009-01-30 21:15:10