[squeak-dev] The Trunk: Morphic-mt.1812.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Wed Dec 15 09:11:01 UTC 2021


Hi all --

Let me summarize the challenge here once more. :-)

Given that we want to have a way to enclose the current text selection with brackets, we need a way to do so across keyboard layouts (and languages).

Text input works via key-stroke events and KeyboardEvent >> #keyCharacter. Not key-down, not key-up, but key-stroke.

Keyboard shortcuts implemented over keystroke events -- which is our status quo mostly -- must never use #shiftPressed to remain cross-language compatible. Unless it is a special key such as Enter/Space/..., but that's irrelevant to this issue. The shift state is already encoded in #keyCharacter.

Our current VM exhibits cross-platform differences regarding keyboard processing. For example, pressing CTRL+SHIFT+8 in Windows on a German layout will omit the shift state. Therefore, we cannot currently use #controlPressed when implementing shortcuts such as for "enclose selection".

Now, ALT+SHIFT+8 would work on a German layout in Windows. However, it does not work when typing { or [ because we folks need to press AltGr for that, too. :-( And Alt+AltGr+8 does not arrive in the image.

***


Yes, there might be the time, when we can cleanly implement "enclose selection" with dedicated keyboard shortcuts to avoid having to use that general preference. Unfortunately, that's not possible at the moment.

Sorry for inconveniences. I know that it can be hard to re-learn familiar habits. Please try to use the "enclose selection" preference for now. The keyboard shortcuts are no longer there for the reasons I just explained.

Best,
Marcel
Am 15.12.2021 09:37:38 schrieb Marcel Taeumel <marcel.taeumel at hpi.de>:
Hi Eliot --

>  I can't see how to do it at all.  I have no "enclose" preferences set.

Please enable that preference. The older "shortcuts" were in no way cross-language compatible. They even broke on a German keyboard layout.

TextEditor encloseSelection: true.

Then make a text selection and type the opening bracket of your choice, which is on a US-Layout:

Shift+9 for ( ... )
[ for [ ... ]
Shift+[ for { ... }

Best,
Marcel
Am 14.12.2021 23:06:17 schrieb Eliot Miranda <eliot.miranda at gmail.com>:
Hi Marcel,

On Sat, Dec 4, 2021 at 3:26 AM <commits at source.squeak.org [mailto:commits at source.squeak.org]> wrote:

Marcel Taeumel uploaded a new version of Morphic to project The Trunk:
http://source.squeak.org/trunk/Morphic-mt.1812.mcz [http://source.squeak.org/trunk/Morphic-mt.1812.mcz]

==================== Summary ====================

Name: Morphic-mt.1812
Author: mt
Time: 4 December 2021, 12:26:07.860493 pm
UUID: 89876df1-baaa-314b-9274-bc585d62f388
Ancestors: Morphic-mt.1811

Removes US-layout specific keyboard shortcuts for 'Enclose selection' in favor of the cross-platform compatible preference 'Enclose selection with brackets'. Just type the bracket character like you would in normal text editing. No extra shortcut to remember.

Note that the "replace expression" operation needs an extra Del/Backspace hit if "Enclose selection with brackets" is enabled (by default).

Note that dead keys might be an issue when the second key press yields two characters, which effectively toggles the brackets around the selection twice. I did observe that with the single-quote/double-quote key in an US-layout on Windows 10.


So how do I enclose the selection with brackets now?  I can't see how to do it at all.  I have no "enclose" preferences set.

Also, if I select something in a class definition in a browser, type Command-9 I get "MessageNotUnderstood: TextKern>>turnOff.

Frustratedly...


=============== Diff against Morphic-mt.1811 ===============

Item was changed:
  ----- Method: TextEditor class>>encloseSelection (in category 'preferences') -----
  encloseSelection
        <preference: 'Enclose selection with brackets () {} [] '''' "" || <>'
                categoryList: #('Morphic' 'editing')
                description: 'When true, selecting text and typing an opening parenthesis, bracket, square-bracket, single quote, or double quote will add corresponding character around the selection without requiring a cmd key.'
                type: #Boolean>

+       ^ EncloseSelection ifNil: [ true ]!
-       ^ EncloseSelection ifNil: [ false ]!

Item was changed:
  ----- Method: TextEditor class>>initializeCmdKeyShortcuts (in category 'keyboard shortcut tables') -----
  initializeCmdKeyShortcuts
        "Initialize the (unshifted) command-key (or alt-key) shortcut table."

        "NOTE: if you don't know what your keyboard generates, use Sensor kbdTest"

        "TextEditor initialize"

        | cmdMap cmds |
        cmdMap := Array new: 256 withAll: #noop:.               "use temp in case of a crash"
        cmdMap at: 1 + 1 put: #cursorHome:.                             "home key"
        cmdMap at: 4 + 1 put: #cursorEnd:.                              "end key"
        cmdMap at: 8 + 1 put: #backspace:.                              "ctrl-H or delete key"
        cmdMap at: 11 + 1 put: #cursorPageUp:.                  "page up key"
        cmdMap at: 12 + 1 put: #cursorPageDown:.                "page down key"
        cmdMap at: 13 + 1 put: #crWithIndent:.                  "cmd-Return"
        cmdMap at: 27 + 1 put: #offerMenuFromEsc:.              "escape key"
        cmdMap at: 28 + 1 put: #cursorLeft:.                            "left arrow key"
        cmdMap at: 29 + 1 put: #cursorRight:.                           "right arrow key"
        cmdMap at: 30 + 1 put: #cursorUp:.                              "up arrow key"
        cmdMap at: 31 + 1 put: #cursorDown:.                            "down arrow key"
        cmdMap at: 32 + 1 put: #selectWord:.                            "space bar key"
        cmdMap at: 127 + 1 put: #forwardDelete:.                "del key"

        '0123456789-='
                do: [:char | cmdMap at: char asciiValue + 1 put: #changeEmphasis:].
-               
-       '([<{|"''' do: [:char | cmdMap at: char asciiValue + 1 put: #enclose:].

        cmds := #($a #selectAll: $c #copySelection: $e #exchange: $f #find: $g #findAgain: $j #doAgain: $k #offerFontMenu: $u #align: $v #paste: $w #backWord: $x #cut: $y #swapChars: $z #undo:).
        1 to: cmds size
                by: 2
                do: [:i | cmdMap at: (cmds at: i) asciiValue + 1 put: (cmds at: i + 1)].

        cmdActions := cmdMap!

Item was changed:
  ----- Method: TextEditor class>>initializeShiftCmdKeyShortcuts (in category 'keyboard shortcut tables') -----
  initializeShiftCmdKeyShortcuts
        "Initialize the shift-command-key (or control-key) shortcut table."
        "NOTE: if you don't know what your keyboard generates, use Sensor kbdTest"
        "wod 11/3/1998: Fix setting of cmdMap for shifted keys to actually use the
        capitalized versions of the letters.
        TPR 2/18/99: add the plain ascii values back in for those VMs that don't return the shifted values."

        "TextEditor initialize"

        | cmdMap cmds |

        "shift-command and control shortcuts"
        cmdMap := Array new: 256 withAll: #noop:.               "use temp in case of a crash"
        cmdMap at: ( 1 + 1) put: #cursorHome:.                  "home key"
        cmdMap at: ( 4 + 1) put: #cursorEnd:.                           "end key"
        cmdMap at: ( 8 + 1) put: #forwardDelete:.                       "ctrl-H or delete key"
        cmdMap at: (11 + 1) put: #cursorPageUp:.                        "page up key"
        cmdMap at: (12 + 1) put: #cursorPageDown:.              "page down key"
        cmdMap at: (13 + 1) put: #crWithIndent:.                        "ctrl-Return"
        cmdMap at: (27 + 1) put: #offerMenuFromEsc:.    "escape key"
        cmdMap at: (28 + 1) put: #cursorLeft:.                  "left arrow key"
        cmdMap at: (29 + 1) put: #cursorRight:.                 "right arrow key"
        cmdMap at: (30 + 1) put: #cursorUp:.                            "up arrow key"
        cmdMap at: (31 + 1) put: #cursorDown:.                  "down arrow key"
        cmdMap at: (32 + 1) put: #selectWord:.                  "space bar key"
        cmdMap at: (45 + 1) put: #changeEmphasis:.              "cmd-sh-minus"
        cmdMap at: (61 + 1) put: #changeEmphasis:.              "cmd-sh-plus"
        cmdMap at: (127 + 1) put: #forwardDelete:.              "del key"

-       "On some keyboards, these characters require a shift"
-       '([<{|"''9' do: [:char | cmdMap at: char asciiValue + 1 put: #enclose:].
-
-       "NB: sw 12/9/2001 commented out the idiosyncratic line just below, which was grabbing shift-esc in the text editor and hence which argued with the wish to have shift-esc be a universal gesture for escaping the local context and calling up the desktop menu." 
-       "cmdMap at: (27 + 1) put: #shiftEnclose:."      "ctrl-["
-
-       "'""''(' do: [ :char | cmdMap at: (char asciiValue + 1) put: #enclose:]."
-
        cmds := #(
                $c      compareToClipboard:
                $h      cursorTopHome:
                $j      doAgainUpToEnd:
                $k      changeStyle:
                $m      selectCurrentTypeIn:
                $s      findAgain:
                $u      changeLfToCr:
                $x      makeLowercase:
                $y      makeUppercase:
                $z      redo: "makeCapitalized:"
        ).
        1 to: cmds size by: 2 do: [ :i |
                cmdMap at: ((cmds at: i) asciiValue + 1) put: (cmds at: i + 1).                 "plain keys"
                cmdMap at: ((cmds at: i) asciiValue - 32 + 1) put: (cmds at: i + 1).            "shifted keys"
                cmdMap at: ((cmds at: i) asciiValue - 96 + 1) put: (cmds at: i + 1).            "ctrl keys"
        ].
        shiftCmdActions := cmdMap!

Item was changed:
  ----- Method: TextEditor>>enclose: (in category 'editing keys') -----
  enclose: aKeyboardEvent
        "Insert or remove bracket characters around the current selection."

        | character left right startIndex stopIndex oldSelection which t |
+       character := aKeyboardEvent keyCharacter.
-       character := aKeyboardEvent shiftPressed
-                                       ifTrue: ['{}|"<>' at: ('[]\'',.' indexOf: aKeyboardEvent keyCharacter) ifAbsent: [aKeyboardEvent keyCharacter]]
-                                       ifFalse: [aKeyboardEvent keyCharacter].
        self closeTypeIn.
        startIndex := self startIndex.
        stopIndex := self stopIndex.
        oldSelection := self selection.
+       which := '([<{|"''' indexOf: character ifAbsent: [ ^ false ].
+       left := '([<{|"''' at: which.
+       right := ')]>}|"''' at: which.
-       which := '([<{|"''9' indexOf: character ifAbsent: [ ^ false ].
-       "Allow Control key in lieu of Alt+Shift for (, {, and double-quote."
-       left := ((Preferences cmdKeysInText and: [ aKeyboardEvent controlKeyPressed ])
-               ifTrue: [ '({<{|""(' ]
-               ifFalse: ['([<{|"''(']) at: which.
-       right := ((Preferences cmdKeysInText and: [ aKeyboardEvent controlKeyPressed ])
-               ifTrue: [ ')}>}|"")' ]
-               ifFalse: [')]>}|"'')']) at: which.
        t := self text.
        ((startIndex > 1 and: [stopIndex <= t size])
                        and: [ (t at: startIndex-1) = left and: [(t at: stopIndex) = right]])
                ifTrue:
                        ["already enclosed; strip off brackets"
                        self selectFrom: startIndex-1 to: stopIndex.
                        self replaceSelectionWith: oldSelection]
                ifFalse:
                        ["not enclosed; enclose by matching brackets"
                        self replaceSelectionWith:
                                (Text string: (String with: left), oldSelection string, (String with: right) attributes: emphasisHere).
                        self selectFrom: startIndex+1 to: stopIndex].
        ^true!

Item was changed:
+ (PackageInfo named: 'Morphic') postscript: 'Editor initialize. "Removes US-layout specific keyboard shortcuts for ''Enclose selection'' in favor of the cross-platform compatible preference ''Enclose selection with brackets''."'!
- (PackageInfo named: 'Morphic') postscript: 'SystemProgressMorph reset. "New layer number"
-
- "Morphic-ct.1796 - Inverts the preference ''halo encloses full bounds'' by pressing the control key while invocating a halo."
- (Preferences preferenceAt: #haloEnclosesFullBounds) instVarNamed: ''helpString'' put: ''If enabled, halos will enclose the full bounds of the target morph, rather than just the bounds. You can also invert this behavior temporarily by holding down Ctrl while invoking a halo on a morph.''.'!





--

_,,,^..^,,,_

best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20211215/d3d351c6/attachment.html>


More information about the Squeak-dev mailing list