#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Tue, 17 Apr 2018 08:17:41 +0200
changeset 18040 8f6de437a2df
parent 18039 1b9aabb9f18a
child 18041 13926da725fa
#REFACTORING by cg class: Tools::CodeHighlightingService comment/format in: #setHighlightedCode:elements: changed: #process:
Tools__CodeHighlightingService.st
--- a/Tools__CodeHighlightingService.st	Tue Apr 17 08:16:58 2018 +0200
+++ b/Tools__CodeHighlightingService.st	Tue Apr 17 08:17:41 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
               All Rights Reserved
@@ -64,7 +66,6 @@
 "
 ! !
 
-
 !CodeHighlightingService class methodsFor:'accessing'!
 
 label
@@ -211,7 +212,7 @@
 !
 
 process: delayed
-    |oldCode oldCodeList newCode elements cls mthd highlighterClasses|
+    |oldCode oldCodeList oldCodeWithoutEmphasis newCode elements cls mthd highlighterClasses|
 
     "/ codeView topView class == DebugView ifTrue:[^ self].
 
@@ -232,6 +233,12 @@
         ].
     ].
     mthd := codeView method.
+    mthd isNil ifTrue:[
+        cls isNil ifTrue:[
+            self halt.
+            ^ self.
+        ]
+    ].
 
     "textView" modified ifFalse:[
         "/ bad bad bad: textView's list may change, while we copy!!!!!!!!!!
@@ -241,7 +248,8 @@
 
         "textView" modified ifFalse:[
             oldCodeList isNil ifFalse:[
-                oldCode := oldCodeList asStringCollection asStringWithoutEmphasis.
+                oldCode := oldCodeList asStringCollection.
+                oldCodeWithoutEmphasis := oldCode asStringWithoutEmphasis.
                 "textView" modified ifFalse:[
                     Screen currentScreenQuerySignal answer:codeView device
                     do:[
@@ -261,7 +269,7 @@
                             | codeAspect |
                             
                             elements := ParseTreeIndex new.
-                            newCode := oldCode asText.
+                            newCode := oldCodeWithoutEmphasis asText.
                             codeAspect := codeView codeAspect.
                             codeAspect == SyntaxHighlighter codeAspectMethod ifTrue:[
                                 highlighterClasses do:[:e|newCode := e formatMethod:mthd source:newCode in:cls using:syntaxPreferences elementsInto: elements].
@@ -278,7 +286,7 @@
                     ].
                     newCode notNil ifTrue:[
                         "textView" modified ifFalse:[
-                            newCode ~= oldCodeList ifTrue:[
+                            newCode ~= oldCode ifTrue:[
                                 newCode := newCode asStringCollection.
                                 "textView" modified ifFalse:[
                                     done := true.
@@ -341,7 +349,7 @@
     lastShown := textView lastLineShown.
 
     replaceAction := [:lNr :line |
-            |oldLine|
+            |oldLine nonSepIndex charEmphasis|
 
             oldLine :=  list at:lNr ifAbsent:nil.
             oldLine notNil ifTrue:[
@@ -352,16 +360,12 @@
                     "/ Certainly a kludge.
 
                     oldLine string = line string ifTrue:[
-                        | i |
-
                         "JV@2012-02-01: Remove any emphasis on leading whitespace"
                         "(presumably created by LintHighlighter)"
-                        i := line string indexOfNonSeparator.
-                        i > 1 ifTrue:[
-                            | e |
-
-                            (e := (line emphasisAt: i - 1)) notNil ifTrue:[
-                                line emphasisFrom: 1 to: i - 1 remove: e.
+                        nonSepIndex := line string indexOfNonSeparator.
+                        nonSepIndex > 1 ifTrue:[
+                            (charEmphasis := (line emphasisAt:nonSepIndex - 1)) notNil ifTrue:[
+                                line emphasisFrom:1 to:(nonSepIndex - 1) remove:charEmphasis.
                             ]
                         ].