Changeset 11611


Ignore:
Timestamp:
Jan 13, 2009, 2:21:27 AM (11 years ago)
Author:
gb
Message:

Don't implement drawRect: (and therefore don't set temporary attributes
inside drawRect:) Setting temporary attributes seems to invalidate
the bounding rectangle and forces drawing of the affected rectangles
the next time that drawRect: is called (as when the cursor blinks.)
That drawRect: call was drawing temporary attributes and thus causing
excessive redisplay on the next drawing cycle ... amazingly bad.)

Instead, COMPUTE-TEMPORARY-ATTRIBUTES after deciding whether or not
to highlight matching parens (whether parens match or not.) and
when the containing window reaquires keyboard focus. That's still
overkill - we could certainly be more clever about not recomputing
things that haven't changed - but doesn't do nearly as much unnecessary
redisplay.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/cocoa-editor.lisp

    r11424 r11611  
    10211021(defmethod disable-paren-highlight ((self hemlock-textstorage-text-view))
    10221022  (when (eql (text-view-paren-highlight-enabled self) #$YES)
    1023     (setf (text-view-paren-highlight-enabled self) #$NO)
    1024     (remove-paren-highlight self)))
    1025 
    1026 
    1027 
    1028 
    1029 (defmethod force-paren-redisplay ((self hemlock-textstorage-text-view))
    1030   (when (eql (text-view-paren-highlight-enabled self) #$YES)
    1031     (ns:with-ns-range (left-char-range (text-view-paren-highlight-left-pos self) 1)
    1032       (ns:with-ns-range (right-char-range (text-view-paren-highlight-right-pos self) 1)
    1033         (let* ((layout (#/layoutManager self))
    1034                (container (#/textContainer self))
    1035                (left-glyph-range (#/glyphRangeForCharacterRange:actualCharacterRange:
    1036                                   layout
    1037                                   left-char-range
    1038                                   +null-ptr+))
    1039                (right-glyph-range (#/glyphRangeForCharacterRange:actualCharacterRange:
    1040                                    layout
    1041                                    right-char-range
    1042                                    +null-ptr+))
    1043                (left-rect (#/boundingRectForGlyphRange:inTextContainer:
    1044                            layout
    1045                            left-glyph-range
    1046                            container))
    1047                (right-rect (#/boundingRectForGlyphRange:inTextContainer:
    1048                             layout
    1049                             right-glyph-range
    1050                             container)))
    1051           (#/setNeedsDisplayInRect: self left-rect)
    1052           (#/setNeedsDisplayInRect: self right-rect))))))
     1023    (setf (text-view-paren-highlight-enabled self) #$NO)))
     1024
     1025
     1026
     1027
     1028(defmethod compute-temporary-attributes ((self hemlock-textstorage-text-view))
     1029  (let* ((container (#/textContainer self))
     1030         ;; If there's a containing scroll view, use its contentview         
     1031         ;; Otherwise, just use the current view.
     1032         (scrollview (#/enclosingScrollView self))
     1033         (contentview (if (%null-ptr-p scrollview) self (#/contentView scrollview)))
     1034         (rect (#/frame contentview))
     1035         (layout (#/layoutManager container))
     1036         (glyph-range (#/glyphRangeForBoundingRect:inTextContainer:
     1037                       layout rect container))
     1038         (char-range (#/characterRangeForGlyphRange:actualGlyphRange:
     1039                      layout glyph-range +null-ptr+))
     1040         (start (ns:ns-range-location char-range))
     1041         (length (ns:ns-range-length char-range)))
     1042    (when (> length 0)
     1043      ;; Remove all temporary attributes from the character range
     1044      (#/removeTemporaryAttribute:forCharacterRange:
     1045       layout #&NSForegroundColorAttributeName char-range)
     1046      (#/removeTemporaryAttribute:forCharacterRange:
     1047       layout #&NSBackgroundColorAttributeName char-range)
     1048      (let* ((ts (#/textStorage self))
     1049             (cache (hemlock-buffer-string-cache (slot-value ts 'hemlock-string)))
     1050             (hi::*current-buffer* (buffer-cache-buffer cache)))
     1051        (multiple-value-bind (start-line start-offset)
     1052                             (update-line-cache-for-index cache start)
     1053          (let* ((end-line (update-line-cache-for-index cache (+ start length))))
     1054            (set-temporary-character-attributes
     1055             layout
     1056             (- start start-offset)
     1057             start-line
     1058             (hi::line-next end-line))))))
     1059    (when (eql #$YES (text-view-paren-highlight-enabled self))
     1060      (let* ((background #&NSBackgroundColorAttributeName)
     1061             (paren-highlight-left (text-view-paren-highlight-left-pos self))
     1062             (paren-highlight-right (text-view-paren-highlight-right-pos self))
     1063             (paren-highlight-color (text-view-paren-highlight-color self))
     1064             (attrs (#/dictionaryWithObject:forKey: ns:ns-dictionary
     1065                                                    paren-highlight-color
     1066                                                    background)))
     1067        (#/addTemporaryAttributes:forCharacterRange:
     1068         layout attrs (ns:make-ns-range paren-highlight-left 1))
     1069        (#/addTemporaryAttributes:forCharacterRange:
     1070         layout attrs (ns:make-ns-range paren-highlight-right 1))))))
    10531071
    10541072(defmethod update-paren-highlight ((self hemlock-textstorage-text-view))
     
    10821100                           (1- (hi:mark-absolute-position point))
    10831101                           (text-view-paren-highlight-enabled self) #$YES))))))
    1084         (force-paren-redisplay self)))))
     1102        (compute-temporary-attributes self)))))
    10851103
    10861104
     
    11761194                     layout attrs range)))))))))))
    11771195
     1196#+no
    11781197(objc:defmethod (#/drawRect: :void) ((self hemlock-text-view) (rect :<NSR>ect))
    1179   (let* ((container (#/textContainer self))
    1180          (layout (#/layoutManager container))
    1181          (glyph-range (#/glyphRangeForBoundingRect:inTextContainer:
    1182                        layout rect container))
    1183          (char-range (#/characterRangeForGlyphRange:actualGlyphRange:
    1184                       layout glyph-range +null-ptr+))
    1185          (start (ns:ns-range-location char-range))
    1186          (length (ns:ns-range-length char-range)))
    1187     (when (> length 0)
    1188       ;; Remove all temporary attributes from the character range
    1189       (#/removeTemporaryAttribute:forCharacterRange:
    1190        layout #&NSForegroundColorAttributeName char-range)
    1191       (#/removeTemporaryAttribute:forCharacterRange:
    1192        layout #&NSBackgroundColorAttributeName char-range)
    1193       (let* ((ts (#/textStorage self))
    1194              (cache (hemlock-buffer-string-cache (slot-value ts 'hemlock-string)))
    1195              (hi::*current-buffer* (buffer-cache-buffer cache)))
    1196         #+debug (#_NSLog #@"paren-highlight-phase = %d" :int (text-view-paren-highlight-phase self))
    1197         (multiple-value-bind (start-line start-offset)
    1198             (update-line-cache-for-index cache start)
    1199           (let* ((end-line (update-line-cache-for-index cache (+ start length))))
    1200             (set-temporary-character-attributes
    1201              layout
    1202              (- start start-offset)
    1203              start-line
    1204              (hi::line-next end-line))))))
    1205     (when (and (eql #$YES (text-view-paren-highlight-enabled self))
    1206                (#/isKeyWindow (#/window self))
    1207                (#/isSelectable self))
    1208       (let* ((background #&NSBackgroundColorAttributeName)
    1209              (paren-highlight-left (text-view-paren-highlight-left-pos self))
    1210              (paren-highlight-right (text-view-paren-highlight-right-pos self))
    1211              (paren-highlight-color (text-view-paren-highlight-color self))
    1212              (attrs (#/dictionaryWithObject:forKey: ns:ns-dictionary
    1213                                                     paren-highlight-color
    1214                                                     background)))
    1215         (#/addTemporaryAttributes:forCharacterRange:
    1216          layout attrs (ns:make-ns-range paren-highlight-left 1))
    1217         (#/addTemporaryAttributes:forCharacterRange:
    1218          layout attrs (ns:make-ns-range paren-highlight-right 1))))
    1219     ;; Um, don't forget to actually draw the view..
    1220     (call-next-method  rect)))
     1198  ;; Um, don't forget to actually draw the view..
     1199  (call-next-method  rect))
    12211200
    12221201
     
    16741653  ;; highlighting (like matching-paren highlighting).  Maybe make this
    16751654  ;; more general ...
     1655  ;; Currently, this only removes temporary attributes from matching
     1656  ;; parens; other kinds of syntax highlighting stays visible when
     1657  ;; the containing window loses keyboard focus
    16761658  (let* ((tv (text-pane-text-view self)))
    16771659    (remove-paren-highlight tv)
     
    16841666  (declare (ignorable notification))
    16851667  (let* ((tv (text-pane-text-view self)))
    1686     (force-paren-redisplay tv)
    1687     (force-paren-redisplay (slot-value tv 'peer))))
     1668    (compute-temporary-attributes tv)
     1669    (compute-temporary-attributes (slot-value tv 'peer))))
    16881670 
    16891671
Note: See TracChangeset for help on using the changeset viewer.