         guard UserDefaults.standard[.enableSyntaxHighlight] else { return nil }
         guard !self.textStorage.string.isEmpty else { return nil }
         
-        let wholeRange = self.textStorage.range
-        let editedRange = editedRange ?? wholeRange
-        
         // in case that wholeRange length is changed from editedRange
-        guard editedRange.upperBound <= wholeRange.upperBound else {
+        guard editedRange.flatMap({ $0.upperBound > self.textStorage.length }) != true else {
             assertionFailure("Invalid range is passed in to \(#function)")
             return nil
         }
         
-        guard !self.style.isNone else {
-            self.textStorage.apply(highlights: [:], range: editedRange)
-            completionHandler()
-            return nil
-        }
-        
-        let bufferLength = UserDefaults.standard[.coloringRangeBufferLength]
-        var highlightRange = editedRange
-        
-        // highlight whole if string is enough short
-        if wholeRange.length <= bufferLength {
-            highlightRange = wholeRange
-            
-        } else if highlightRange != wholeRange {
+        let wholeRange = self.textStorage.range
+        let highlightRange: NSRange = {
+            guard let editedRange = editedRange, editedRange != wholeRange else { return wholeRange }
+            
+            // highlight whole if string is enough short
+            let bufferLength = UserDefaults.standard[.coloringRangeBufferLength]
+            if wholeRange.length <= bufferLength {
+                return wholeRange
+            }
+            
             // highlight whole visible area if edited point is visible
-            highlightRange = self.textStorage.layoutManagers
+            var highlightRange = self.textStorage.layoutManagers
                 .compactMap(\.textViewForBeginningOfSelection?.visibleRange)
-                .filter { $0.intersects(highlightRange) }
-                .reduce(into: highlightRange) { $0.formUnion($1) }
+                .filter { $0.intersects(editedRange) }
+                .reduce(into: editedRange) { $0.formUnion($1) }
             
             highlightRange = (self.textStorage.string as NSString).lineRange(for: highlightRange)
             

                    highlightRange.length = effectiveRange.upperBound - highlightRange.location
                }
            }
        }
        
        // use cache if the content of the whole document is the same as the last

                }
                
                // cache result if whole text was parsed
                if highlightRange == string.nsRange {
                    self?.highlightCache = Cache(styleName: styleName, string: string, highlights: highlights)
                }
                
                self?.textStorage.apply(highlights: highlights, range: highlightRange)
                
                progress.completedUnitCount += 1
                
                completionHandler()
            }
        }
        
