discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: keyboard selection


From: Richard Frith-Macdonald
Subject: Re: keyboard selection
Date: Mon, 20 Aug 2007 14:39:06 +0100


On 20 Aug 2007, at 14:26, Fred Kiefer wrote:

Riccardo wrote:
Hello,

inside textfields (GNUMail message editing and Ink are an example) I
think I used to be able to select text using shift + arrows movment. I notice today that it is not possible. Is it a bug? Or am I just used to
do it on other platforms?


Thank you for spotting this. The reason for this was really hard to
track down. It turns out to be the following line in NSInputManager:

BOOL isFunctionKey = [theEvent modifierFlags] & NSFunctionKeyMask;

This used to work while the value for NSFunctionKeyMask was in the first
byte, but now it is 1<<24 and the resulting BOOL was NO.
This should be a warning to all of us to program more careful and always
use explicit comparisons for integer masks. This code does the trick:

BOOL isFunctionKey = ([theEvent modifierFlags] & NSFunctionKeyMask)
        == NSFunctionKeyMask;

Well spotted!

though I prefer the even more explicit setting of YES or NO as in

BOOL isFunctionKey = (([theEvent modifierFlags] & NSFunctionKeyMask) == NSFunctionKeyMask) ? YES : NO;

as this guarantees that a test of the form 'if (isFunctionkey == YES)' will work correctly.

I also try to always write code to test 'if (x == YES)' rather than 'if (x)', as it will fail in more cases (and hopefully cause us to spot errors like that) if someone has done something like assigning a bitmask to a boolean.

Not a big issue, just a bit of coding style that I've found helps code reliability over the years.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]