Hi guys

I'm looking for the following information and I do not find it. I thought that 
I could ask a keyboardEvent for the character I typed in the following case:

When I press shift ' I should obtain "

self keyValue 
        39

but Character value: 39 is ' and not double quote

self keyCharacter
        $'

self modifiedCharacter
        $'

but this is wrong

modifiedCharacter
  self flag: #hack.
  "Hack me.  When Ctrl is pressed, the key ascii value is not right and we have 
to do something ugly"
  ^(self controlKeyPressed and: [ (#(MacOSX Windows) includes: Smalltalk os 
current platformFamily) and: [ keyValue <= 26 ]])
      ifTrue: [ (self keyValue + $a asciiValue - 1) asCharacter ]    
      ifFalse: [ self keyCharacter ]

Frankly the event logic is messy.

I do not understand, why we cannot have 
        ' the key that was pressed and shift

        and also " as an interpretation 

and that the system should not be most of the time using this high level 
operation.

Then I do not understand why when I pressed shift ' I get a CMD -'>' character 
it looks so bogus.


When I see

performCmdActionsWith: aKeyboardEvent shifted: aBoolean return: return
        | asciiValue actions action|
        asciiValue := aKeyboardEvent keyValue + 1.
                                                        ^^^^^^^^^^^^^ hardcoded 
in the smalltalkEditor logic 
        actions := aBoolean
                                ifTrue: [self class shiftCmdActions]
                                ifFalse: [self class cmdActions].
        action := (actions at: asciiValue).
        action == #noop: ifTrue: [ ^ false ].
        return value: ( self perform: action with: aKeyboardEvent).


and this really ugly code breaking any principle of layering….


dispatchCommandOn: aKeyboardEvent return: return
        |asciiValue honorCommandKeys char|

        asciiValue := aKeyboardEvent keyValue.
        honorCommandKeys := self cmdKeysInText.
        "Special keys overwrite crtl+key combinations - at least on Windows. To 
resolve this
        conflict, assume that keys other than cursor keys aren't used together 
with Crtl." 
        ((self class specialShiftCmdKeys includes: asciiValue) and: [ 
asciiValue < 27])
                ifTrue: [
                        ^ self performCmdActionsWith: aKeyboardEvent 
                                shifted: aKeyboardEvent controlKeyPressed
                                return: return].

        "backspace, and escape keys (ascii 8 and 27) are command keys"
        ((honorCommandKeys and: [aKeyboardEvent commandKeyPressed]) or: [self 
class specialShiftCmdKeys includes: asciiValue]) 
                ifTrue: [
                        ^ self performCmdActionsWith: aKeyboardEvent 
                                shifted: aKeyboardEvent shiftPressed
                                return: return].

        "the control key can be used to invoke shift-cmd shortcuts"
        (honorCommandKeys and: [aKeyboardEvent controlKeyPressed])
                ifTrue: [
                        ^ self performCmdActionsWith: aKeyboardEvent shifted: 
true return: return].
                        
        ^ false


Then of course

shiftEnclose: aKeyboardEvent
        "Insert or remove bracket characters around the current selection."

        | char left right startIndex stopIndex oldSelection which text |
        char := aKeyboardEvent keyCharacter.
        char = $9 ifTrue: [ char := $( ].
        char = $, ifTrue: [ char := $< ].
        char = $[ ifTrue: [ char := ${ ].
        char = $' ifTrue: [ char := $" ].


And in addition smart character use characters while textEditor methods such as 
enclose: …. require a keyboardEvent.
I will start to fix that part so that we can think a bit instead of been block 
in a rat hole.


Stef



Reply via email to