# HG changeset patch # User Claus Gittinger # Date 1563208829 -7200 # Node ID 476a7030cebb0916b32cb0079feb2de92b257a09 # Parent 5cf6c9bdb07c0bd9b9feff53910194e071bc90a6 #BUGFIX by cg class: WorkspaceCompletionSupport refactoring and fixes class definition added: #computeAndShowCompletions comment/format in: #computeCompletions changed: #suggestionsArrived:implementations:actions:autoSelect: class: WorkspaceCompletionSupport class added: #numberOfCompletionSuggestionsShown diff -r 5cf6c9bdb07c -r 476a7030cebb WorkspaceCompletionSupport.st --- a/WorkspaceCompletionSupport.st Mon Jul 15 16:40:05 2019 +0200 +++ b/WorkspaceCompletionSupport.st Mon Jul 15 18:40:29 2019 +0200 @@ -1,3 +1,5 @@ +"{ Encoding: utf8 }" + " COPYRIGHT (c) 2013 by eXept Software AG All Rights Reserved @@ -15,7 +17,7 @@ EditTextViewCompletionSupport subclass:#WorkspaceCompletionSupport instanceVariableNames:'' - classVariableNames:'' + classVariableNames:'NumberOfCompletionSuggestionsShown' poolDictionaries:'' category:'Interface-Smalltalk' ! @@ -53,9 +55,35 @@ " ! ! +!WorkspaceCompletionSupport class methodsFor:'defaults'! + +numberOfCompletionSuggestionsShown + "/ used to be 25, but that makes a long list, which seems disturbung + ^ NumberOfCompletionSuggestionsShown ? 15. + + "Created: / 15-07-2019 / 17:24:03 / Claus Gittinger" +! ! + !WorkspaceCompletionSupport methodsFor:'private'! +computeAndShowCompletions + "compute completions, then push an event to show them" + + |completions| + + completions := self computeCompletions. + completions notEmptyOrNil ifTrue:[ + editView sensor + pushUserEvent:#'suggestionsArrived:implementations:actions:autoSelect:' + for:self + withArguments:completions + ]. + + "Created: / 15-07-2019 / 17:29:54 / Claus Gittinger" +! + computeCompletions + "compute completions (but do not show them)" |topView suggestions implementations actions contextOrNil| @@ -84,23 +112,21 @@ ]. "/ Transcript show:'suggestions: '; showCR:suggestions. "/ Transcript show:'actions: '; showCR:actions. - editView sensor - pushUserEvent:#'suggestionsArrived:implementations:actions:autoSelect:' - for:self - withArguments:{suggestions . implementations . actions . autoSelect } + ^ {suggestions . implementations . actions . autoSelect } "Created: / 26-09-2013 / 17:44:31 / Jan Vrany " "Modified: / 09-03-2017 / 10:48:44 / cg" + "Modified (comment): / 15-07-2019 / 17:34:27 / Claus Gittinger" ! suggestionsArrived:suggestionsArg implementations:implementationsArg actions:actionsArg autoSelect:autoSelectArg "the background process has generated some suggestions" |v numShown numFirst numLast numSkipped - suggestions implementations actions suggestionOffset keyAndSnippet indexOfSnippet| + suggestions implementations actions suggestionOffsetDueToSnippets keyAndSnippet indexOfSnippet| (editView sensor hasKeyPressEventFor:nil) ifTrue:[ - self closeCompletionView. + "/ self closeCompletionView. ^ self ]. @@ -110,24 +136,45 @@ suggestions := suggestionsArg ? #(). suggestions := suggestions reject:[:el | el isNil]. - numShown := 25. + numShown := self class numberOfCompletionSuggestionsShown. suggestions size > numShown ifTrue:[ - numFirst := numShown-5. - numLast := 5. - numSkipped := suggestions size-numShown. - suggestions := (suggestions copyTo:numShown-5) + numFirst := numShown-3. + numLast := 3. + numSkipped := suggestions size-numShown. + + suggestions := (suggestions copyTo:numShown-numLast) , { ('<< %1 more skipped >>' bindWith:numSkipped) withColor:Color grey } - , (suggestions copyLast:5). - implementations isArray ifTrue:[ - implementations := (implementations copyTo:numShown-5),#(nil),(implementations copyLast:5). - ]. - actions isArray ifTrue:[ - actions := (actions copyTo:numShown-5),#(nil),(actions copyLast:5). - ]. + , (suggestions copyLast:numLast). + implementations isSequenceable ifTrue:[ + implementations := (implementations copyTo:numShown-numLast),#(nil),(implementations copyLast:numLast). + ] ifFalse:[ + self halt + ]. + actions isSequenceable ifTrue:[ + actions := (actions copyTo:numShown-numLast),#(nil),(actions copyLast:numLast). + ] ifFalse:[ + actions isBlock ifTrue:[ + "/ the block will be called with the index of the selected completion; + "/ this is now wrong, as we have changed the list!!. + "/ wrap the block by an index-adjusting action +"/ actions := [:selectedIndex | +"/ |adjustedIndex| +"/ +"/ selectedIndex <= numShown ifTrue:[ +"/ adjustedIndex := selectedIndex +"/ ] ifFalse:[ +"/ adjustedIndex := selectedIndex + numSkipped. +"/ ]. +"/ actionsArg value:adjustedIndex. +"/ ]. + ] ifFalse:[ + self halt + ]. + ]. ]. "/ append snipplet, if any (can be easily reached via CRSR-up) - suggestionOffset := 0. + suggestionOffsetDueToSnippets := 0. indexOfSnippet := nil. UserPreferences current appendAbbreviationsToCompletionSuggestions ifTrue:[ (keyAndSnippet := editView findAbbreviationKeyBeforeCursor) notNil ifTrue:[ @@ -150,8 +197,8 @@ with: ( ('("',abbrev,'" snippet)') withColor:Color gray)). indexOfSnippet := suggestions size. - "/ change below, when reversing the order in above code - "/ suggestionOffset := 2. + "/ change below, when reversing the order in above code (i.e. when snippets come first) + "/ suggestionOffsetDueToSnippets := 2. ] ] ]. @@ -202,14 +249,14 @@ performCompletion := [:selectedListIndex | - |indexInSuggestions| - self closeCompletionView. - indexInSuggestions := selectedListIndex - suggestionOffset. (selectedListIndex == indexOfSnippet) ifTrue:[ - "/ replace the sniplet + "/ replace by the sniplet editView sensor pushUserEvent:#expandAbbreviation for:editView ] ifFalse:[ + |indexInSuggestions| + + indexInSuggestions := selectedListIndex - suggestionOffsetDueToSnippets. LastCompletions isNil ifTrue:[ LastCompletions := OrderedCollection new. ]. @@ -279,6 +326,7 @@ ] "Modified: / 05-11-2017 / 11:10:47 / cg" + "Modified: / 15-07-2019 / 17:57:56 / Claus Gittinger" ! ! !WorkspaceCompletionSupport class methodsFor:'documentation'!