Changeset 14490


Ignore:
Timestamp:
Dec 16, 2010, 11:50:56 PM (9 years ago)
Author:
gb
Message:

Do paren highlighting by modifying the textstorage's attributes,
not by using NSLayoutManager temporary attributes. (This doesn't
seem to make the buffer dirty and in need of saving, as I'd once
thought it did.)

Needs testing on Cocotron.

File:
1 edited

Legend:

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

    r14481 r14490  
    11311131                                                       
    11321132
    1133 
     1133;;; This assumes that NSBackgroundColorAttributeName can only be
     1134;;; present id it's (possibly stale) paren highlighting info.
     1135;;; We can't be sure of the locations (because of insertions/deletions),
     1136;;; so remove the attribute from the entire textstorage.
    11341137(defmethod remove-paren-highlight ((self hemlock-textstorage-text-view))
    1135   #-cocotron
    1136   (let* ((left (text-view-paren-highlight-left-pos self))
    1137          (right (text-view-paren-highlight-right-pos self)))
    1138     (ns:with-ns-range  (char-range left 1)
    1139       (let* ((layout (#/layoutManager self)))
    1140         (#/removeTemporaryAttribute:forCharacterRange:
    1141          layout #&NSBackgroundColorAttributeName
    1142          char-range)
    1143         (setf (pref char-range #>NSRange.location) right)
    1144         (#/removeTemporaryAttribute:forCharacterRange:
    1145          layout #&NSBackgroundColorAttributeName
    1146          char-range)))))
     1138  (let* ((textstorage (#/textStorage self))
     1139         (len (#/length textstorage)))
     1140    (#/beginEditing textstorage)
     1141    (ns:with-ns-range  (char-range 0 len)
     1142      (#/removeAttribute:range: textstorage #&NSBackgroundColorAttributeName
     1143                                char-range))
     1144    (#/endEditing textstorage)))
    11471145
    11481146(defmethod disable-paren-highlight ((self hemlock-textstorage-text-view))
     
    11531151
    11541152(defmethod compute-temporary-attributes ((self hemlock-textstorage-text-view))
    1155   #-cocotron
    11561153  (let* ((container (#/textContainer self))
    11571154         ;; If there's a containing scroll view, use its contentview         
     
    11911188             (attrs (#/dictionaryWithObject:forKey: ns:ns-dictionary
    11921189                                                    paren-highlight-color
    1193                                                     background)))
    1194         (#/addTemporaryAttributes:forCharacterRange:
    1195          layout attrs (ns:make-ns-range paren-highlight-left 1))
    1196         (#/addTemporaryAttributes:forCharacterRange:
    1197          layout attrs (ns:make-ns-range paren-highlight-right 1))))))
     1190                                                    background))
     1191             (ts (#/textStorage self)))
     1192        (ns:with-ns-range (left-range paren-highlight-left 1)
     1193          (ns:with-ns-range (right-range paren-highlight-right 1)
     1194            (#/beginEditing ts)
     1195            (#/addAttributes:range: ts attrs left-range)
     1196            ;(#/edited:range:changeInLength: ts #$NSTextStorageEditedAttributes left-range 0)
     1197            (#/addAttributes:range: ts attrs right-range)
     1198            ;(#/edited:range:changeInLength: ts #$NSTextStorageEditedAttributes right-range 0)
     1199            (#/endEditing ts)))))))
    11981200
    11991201(defmethod update-paren-highlight ((self hemlock-textstorage-text-view))
     
    13281330                    (setf (ns:ns-range-location range) start
    13291331                          (ns:ns-range-length range) len)
    1330                     (let ((attrs (#/dictionaryWithObject:forKey:
    1331                                   ns:ns-dictionary
    1332                                   (if (eq type :string) string-color comment-color)
    1333                                   color-attribute)))
    1334                       (#/addTemporaryAttributes:forCharacterRange:
    1335                        layout attrs range)))
     1332                    (let ((attrs (if (eq type :string) string-color comment-color)))
     1333                      (#/addTemporaryAttribute:value:forCharacterRange:
     1334                       layout color-attribute attrs range)))
    13361335                  (setq last-end iend))))))))))
    13371336
Note: See TracChangeset for help on using the changeset viewer.