'From Squeak3.7gamma of ''17 July 2004'' [latest update: #5985] on 28 August 2004 at 2:36:27 pm'! "Change Set: ChangeEmphasisFixes2 Date: 28 August 2004 Author: tween fixes 2 bugs. The cmd-6 'be a web URL' links aren't working in plain TextMorphs. To see this drag a Text from the Supplies tab, select its contents and hit cmd-6. Then select 'be a web URL link' on the menu. It actually performs a different menu item (edit hidden info). This bug was originally fixed in changeset 5363TextMorphURLFix-nk, but the fix has been lost. using cmd-7 to toggle bold on/off doesn't always work. The text can get stuck on bold or not bold. For example, double click on the first 'Squeak' in the welcome window, and hit cmd-7 a few times. It will change to bold, but won't change back to normal. The same applies to italic etc. " ! !ParagraphEditor methodsFor: 'editing keys' stamp: 'tween 8/28/2004 14:02'! changeEmphasis: characterStream "Change the emphasis of the current selection or prepare to accept characters with the change in emphasis. Emphasis change amounts to a font change. Keeps typeahead." | keyCode attribute oldAttributes index thisSel colors extras indexOfOldAttributes | "control 0..9 -> 0..9" keyCode := ('0123456789-=' indexOf: sensor keyboard ifAbsent: [1]) - 1. "grab the old set of attributes" indexOfOldAttributes := startBlock stringIndex = stopBlock stringIndex ifTrue:[ "selection is empty, look on character to the left" (startBlock stringIndex - 1) max: 1] ifFalse:[ "selection is not empty, look on leftmost character in the selection" startBlock stringIndex min: stopBlock stringIndex]. oldAttributes := paragraph text attributesAt: indexOfOldAttributes forStyle: paragraph textStyle. thisSel := self selection. "Decipher keyCodes for Command 0-9..." (keyCode between: 1 and: 5) ifTrue: [attribute := TextFontChange fontNumber: keyCode]. keyCode = 6 ifTrue: [colors := #(black magenta red yellow green blue cyan white). extras := ((self class name = #TextMorphEditor) and: [(self morph isKindOf: TextMorphForEditView) not]) "not a system window" ifTrue: [#()] ifFalse: [#('Link to comment of class' 'Link to definition of class' 'Link to hierarchy of class' 'Link to method')]. index := (PopUpMenu labelArray: colors , #('choose color...' 'Do it' 'Print it'), extras, #('be a web URL link' 'Edit hidden info' 'Copy hidden info') lines: (Array with: colors size +1)) startUp. index = 0 ifTrue: [^ true]. index <= colors size ifTrue: [attribute := TextColor color: (Color perform: (colors at: index))] ifFalse: [index := index - colors size - 1. "Re-number!!!!!!" index = 0 ifTrue: [attribute := self chooseColor]. index = 1 ifTrue: [attribute := TextDoIt new. thisSel := attribute analyze: self selection asString]. index = 2 ifTrue: [attribute := TextPrintIt new. thisSel := attribute analyze: self selection asString]. (extras size = 0) & (index > 2) ifTrue: [index := index + 4]. "skip those" index = 3 ifTrue: [attribute := TextLink new. thisSel := attribute analyze: self selection asString with: 'Comment']. index = 4 ifTrue: [attribute := TextLink new. thisSel := attribute analyze: self selection asString with: 'Definition']. index = 5 ifTrue: [attribute := TextLink new. thisSel := attribute analyze: self selection asString with: 'Hierarchy']. index = 6 ifTrue: [attribute := TextLink new. thisSel := attribute analyze: self selection asString]. index = 7 ifTrue: [attribute := TextURL new. thisSel := attribute analyze: self selection asString]. index = 8 ifTrue: ["Edit hidden info" thisSel := self hiddenInfo. "includes selection" attribute := TextEmphasis normal]. index = 9 ifTrue: ["Copy hidden info" self copyHiddenInfo. ^ true]. "no other action" thisSel ifNil: [^ true]]. "Could not figure out what to link to" ]. (keyCode between: 7 and: 11) ifTrue: [sensor leftShiftDown ifTrue: [keyCode = 10 ifTrue: [attribute := TextKern kern: -1]. keyCode = 11 ifTrue: [attribute := TextKern kern: 1]] ifFalse: [attribute := TextEmphasis perform: (#(bold italic narrow underlined struckOut) at: keyCode - 6). oldAttributes do: [:att | ((att dominates: attribute) and: [att ~= TextEmphasis normal]) ifTrue: [attribute turnOff]]]]. (keyCode = 0) ifTrue: [attribute := TextEmphasis normal]. beginTypeInBlock ~~ nil ifTrue: [self insertTypeAhead: characterStream] ifFalse: [self replaceSelectionWith: (thisSel asText addAttribute: attribute)]. emphasisHere := Text addAttribute: attribute toArray: oldAttributes. ^ true! !