A new version of Morphic was added to project The Inbox: http://source.squeak.org/inbox/Morphic-jar.1815.mcz
==================== Summary ====================
Name: Morphic-jar.1815 Author: jar Time: 6 December 2021, 8:56:48.006443 pm UUID: b73bc9c0-eec1-a645-80f7-39eb98778d2c Ancestors: Morphic-ct.1814
Allow enclosing a selection with multiple levels of brackets with EncloseTextSelections preference on. Both opening and closing brackets on a selection enclose the selection with the first level of brackets; on higher levels opening brackets add and closing brackets remove one level...
Currently, enclosing a selection with only one level of brackets is supported; pressing an opening bracket for the second time removes the enclosing brackets; pressing a closing bracket replaces the selection altogether.
=============== Diff against Morphic-ct.1814 ===============
Item was changed: ----- Method: TextEditor>>enclose: (in category 'editing keys') ----- enclose: aKeyboardEvent + "Insert or remove bracket characters around the current selection. + Pressing a right bracket removes one level of brackets of the same kind if there are any." - "Insert or remove bracket characters around the current selection."
+ | character left right startIndex stopIndex oldSelection which closingBracket t | - | character left right startIndex stopIndex oldSelection which t | character := aKeyboardEvent keyCharacter. self closeTypeIn. startIndex := self startIndex. stopIndex := self stopIndex. oldSelection := self selection. + closingBracket := false. + which := '([<{|"''' indexOf: character ifAbsent: [ + closingBracket := true. + ')]>}|"''' indexOf: character ifAbsent: [^ false ]]. - which := '([<{|"''' indexOf: character ifAbsent: [ ^ false ]. left := '([<{|"''' at: which. right := ')]>}|"''' at: which. t := self text. ((startIndex > 1 and: [stopIndex <= t size]) + and: [ (t at: startIndex-1) = left and: [(t at: stopIndex) = right]] + and: [closingBracket]) - and: [ (t at: startIndex-1) = left and: [(t at: stopIndex) = right]]) ifTrue: + ["already enclosed and the pressed character is a closing bracket; strip off brackets" - ["already enclosed; strip off brackets" self selectFrom: startIndex-1 to: stopIndex. self replaceSelectionWith: oldSelection] ifFalse: + ["not enclosed or the pressed character is an opening bracket; enclose by matching brackets" - ["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!
Here is the discussion: http://lists.squeakfoundation.org/pipermail/squeak-dev/2021-December/217330....
Best, Marcel Am 06.12.2021 20:57:07 schrieb commits@source.squeak.org commits@source.squeak.org: A new version of Morphic was added to project The Inbox: http://source.squeak.org/inbox/Morphic-jar.1815.mcz
==================== Summary ====================
Name: Morphic-jar.1815 Author: jar Time: 6 December 2021, 8:56:48.006443 pm UUID: b73bc9c0-eec1-a645-80f7-39eb98778d2c Ancestors: Morphic-ct.1814
Allow enclosing a selection with multiple levels of brackets with EncloseTextSelections preference on. Both opening and closing brackets on a selection enclose the selection with the first level of brackets; on higher levels opening brackets add and closing brackets remove one level...
Currently, enclosing a selection with only one level of brackets is supported; pressing an opening bracket for the second time removes the enclosing brackets; pressing a closing bracket replaces the selection altogether.
=============== Diff against Morphic-ct.1814 ===============
Item was changed: ----- Method: TextEditor>>enclose: (in category 'editing keys') ----- enclose: aKeyboardEvent + "Insert or remove bracket characters around the current selection. + Pressing a right bracket removes one level of brackets of the same kind if there are any." - "Insert or remove bracket characters around the current selection."
+ | character left right startIndex stopIndex oldSelection which closingBracket t | - | character left right startIndex stopIndex oldSelection which t | character := aKeyboardEvent keyCharacter. self closeTypeIn. startIndex := self startIndex. stopIndex := self stopIndex. oldSelection := self selection. + closingBracket := false. + which := '([ + closingBracket := true. + ')]>}|"''' indexOf: character ifAbsent: [^ false ]]. - which := '([ left := '([ right := ')]>}|"''' at: which. t := self text. ((startIndex > 1 and: [stopIndex + and: [ (t at: startIndex-1) = left and: [(t at: stopIndex) = right]] + and: [closingBracket]) - and: [ (t at: startIndex-1) = left and: [(t at: stopIndex) = right]]) ifTrue: + ["already enclosed and the pressed character is a closing bracket; strip off brackets" - ["already enclosed; strip off brackets" self selectFrom: startIndex-1 to: stopIndex. self replaceSelectionWith: oldSelection] ifFalse: + ["not enclosed or the pressed character is an opening bracket; enclose by matching brackets" - ["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!
squeak-dev@lists.squeakfoundation.org