Christoph Thiede uploaded a new version of HelpSystem-Core to project The Trunk: http://source.squeak.org/trunk/HelpSystem-Core-ct.145.mcz
==================== Summary ====================
Name: HelpSystem-Core-ct.145 Author: ct Time: 19 August 2023, 4:04:35.502781 pm UUID: a4636ce2-ee17-554b-b226-571f3ec822ab Ancestors: HelpSystem-Core-ct.144
Fixes and documentation for SearchTopic: * Fixes off-by-one error for titleHitInterval (that led to a DNU when canceling/jumping to the end of the result text). * Documents structure of resultEntry tuple and harmonizes names. * Documents existing bugs/limitations of search.
=============== Diff against HelpSystem-Core-ct.144 ===============
Item was changed: ----- Method: SearchTopic>>find:in:results: (in category 'searching') ----- find: term in: path results: results
+ | resultEntry topic contents index | - | resultTemplate topic contents index | topic := path last. + resultEntry := Array new: 6. "{topicPath. titleHitInterval?. contentExcerptInterval?. contentExcerpt?. leadingContext? (not in use). contentHitInterval?}" + resultEntry at: 1 put: path. - resultTemplate := Array new: 6. - resultTemplate at: 1 put: path. contents := topic title asString. (index := contents findString: term startingAt: 1 caseSensitive: false) > 0 ifTrue: [ + resultEntry at: 2 put: (index to: index + term size - 1) ]. - resultTemplate at: 2 put: (index to: index + term size) ]. + contents := topic contents asString withSqueakLineEndings. - contents := topic contents asString withSqueakLineEndings. (index := contents findString: term startingAt: 1 caseSensitive: false) > 0 ifTrue: [ | leadingContext trailingContext i | leadingContext := 0. trailingContext := 0. i := index. [i notNil] whileTrue: [ (leadingContext = 2 or: [i = 1]) ifTrue: [ leadingContext := i = 1 ifTrue: [i] ifFalse: [i+1]. i := nil] ifFalse: [ ((contents at: i) = Character cr) ifTrue: [ leadingContext := leadingContext + 1]. i := i - 1] ]. i := index + term size. [i notNil] whileTrue: [ (trailingContext = 2 or: [i >= contents size]) ifTrue: [ trailingContext := i = contents size ifTrue: [i] ifFalse: [i-1]. i := nil] ifFalse: [ ((contents at: i) = Character cr) ifTrue: [ trailingContext := trailingContext + 1]. i := i + 1] ]. + resultEntry - resultTemplate at: 3 put: (index - leadingContext + 1 to: index - leadingContext + term size); at: 4 put: (contents copyFrom: leadingContext to: trailingContext); at: 5 put: leadingContext; at: 6 put: (index to: index + term size - 1) ]. + (resultEntry second notNil "match in title" or: [resultEntry third notNil "match in contents"]) ifTrue: [ + self mutex critical: [ results add: resultEntry ]. - (resultTemplate second notNil "match in title" or: [resultTemplate third notNil "match in contents"]) ifTrue: [ - self mutex critical: [ results add: resultTemplate ]. self triggerUpdateContents]. topic isSearchable ifTrue: [ + self flag: #todo. "Selecting nested results (#searchResultSelected) currently does not work because the model usually has a different instance of the topic than retrieved here." + self flag: #bug. "For cyclic #subtopics, search never stops." topic subtopics do: [:t | self find: term in: path, {t} results: results]].!
Item was changed: ----- Method: SearchTopic>>printResultEntry: (in category 'searching') ----- printResultEntry: entry
+ | resultEntry topicPath topic | - | resultEntry topic | resultEntry := '' asText. + topicPath := entry first. + topic := topicPath last. - topic := entry first last. + resultEntry append: + (topic title asText + addAttribute: TextEmphasis bold; + yourself). + entry second ifNotNil: [:titleHitInterval | + resultEntry + addAttribute: (TextColor color: Color green muchDarker) + from: titleHitInterval first + to: titleHitInterval last]. - entry second notNil - ifFalse: [resultEntry append: ( - (topic title) asText - addAttribute: TextEmphasis bold)] - ifTrue: [resultEntry append: ( - (topic title) asText - addAttribute: TextEmphasis bold; - addAttribute: (TextColor color: Color green muchDarker) - from: entry second first - to: entry second last)].
+ resultEntry append: ' ' asText , ('({1})' asText - resultEntry append: (' ' asText , ('({1})' asText addAttribute: (PluggableTextAttribute evalBlock: [ + | contentHitInterval | + self changed: #searchResultSelected with: topicPath. + contentHitInterval := entry sixth. + self changed: #searchResultContentsSelected with: contentHitInterval]); + format: {'open topic' translated}). - self changed: #searchResultSelected with: entry first. - self changed: #searchResultContentsSelected with: entry sixth]); - format: {'open topic' translated})). resultEntry append: String cr. resultEntry append: ( + ('> ', ((topicPath allButLast collect: [:t | t title]) joinSeparatedBy: ' > ')) asText - ('> ', ((entry first allButLast collect: [:t | t title]) joinSeparatedBy: ' > ')) asText addAttribute: (TextColor color: (Color gray: 0.7))).
resultEntry append: String cr. + entry fourth ifNil: [resultEntry append: '\' withCRs] ifNotNil: [:contentHitText | + | text contentHitInterval | + text := contentHitText asText. + contentHitInterval := entry third. - entry fourth ifNil: [resultEntry append: '\' withCRs] ifNotNil: [:contents | - | text | - text := contents asText. text addAttribute: (TextColor color: Color green muchDarker) + from: contentHitInterval first + to: contentHitInterval last; - from: entry third first - to: entry third last; addAttribute: TextEmphasis bold + from: contentHitInterval first + to: contentHitInterval last. - from: entry third first - to: entry third last. resultEntry append: text withBlanksTrimmed; + append: '\' withCRs]. - append: '\' withCRs. - - ]. ^ resultEntry!
packages@lists.squeakfoundation.org