Changeset 11037


Ignore:
Timestamp:
Oct 10, 2008, 9:54:25 AM (11 years ago)
Author:
gb
Message:

Try to keep track of the state of the insertion point in the blink-phase
slot of a text-view.

Implement a "before" method on #/drawRect: for hemlock-textstorage-textview;
in it, do way to much parsing to support primitive syntax highlighting via
temporary attributes.

Handle drawing/erasing the matching paren by invalidating its glyph
rectangle; decide whether to erase it in the drawRect: method (and
use a temporary attribute when erasing it.) Disable blinking when
the view's deactivated. (This seems to remove the delay before the
matching paren starts blinking; I think that I've seen a delay when
reactivating the window when blinking should take place. Sometimes.)

File:
1 edited

Legend:

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

    r10614 r11037  
    542542
    543543
     544
    544545;;; This runs on the main thread; it synchronizes the "real" NSMutableAttributedString
    545546;;; with the hemlock string and informs the textstorage of the insertion.
     
    857858     (blink-color-attribute :foreign-type :id :accessor text-view-blink-color)
    858859     (blink-enabled :foreign-type :<BOOL> :accessor text-view-blink-enabled)
     860     (blink-phase :foreign-type :<BOOL> :accessor text-view-blink-phase)
    859861     (peer :foreign-type :id))
    860862  (:metaclass ns:+ns-object))
     
    879881  #+debug (log-debug "deactivating ~s" self)
    880882  (assume-not-editing self)
     883  (setf (text-view-blink-phase self) #$NO)
     884  (disable-blink self)
    881885  (#/setSelectable: self nil))
    882886
     
    10061010              (#/editingInProgress (#/textStorage self)))
    10071011    (unless (eql #$NO (text-view-blink-enabled self))
     1012      #+debug (#_NSLog #@"Flag = %@" :id (if flag #@"T" #@"NIL"))
     1013      (setf (text-view-blink-phase self) (if flag 1 0))
    10081014      (let* ((layout (#/layoutManager self))
    1009              (container (#/textContainer self))
    1010              (blink-color (text-view-blink-color self)))
     1015             (container (#/textContainer self)))
    10111016        ;; We toggle the blinked character "off" by setting its
    10121017        ;; foreground color to the textview's background color.
     
    10261031                          glyph-range
    10271032                          container)))
    1028               (#/set blink-color)
    1029               (#_NSRectFill rect))
    1030           (unless flag
    1031             (#/drawGlyphsForGlyphRange:atPoint: layout glyph-range (#/textContainerOrigin self))))))))
     1033              (#/setNeedsDisplayInRect: self rect)))))))
    10321034  (call-next-method r color flag))
    10331035
     
    10721074                     (setf (text-view-blink-location self)
    10731075                           (hi:mark-absolute-position temp)
    1074                            (text-view-blink-enabled self) #$YES))))))))))
     1076                           (text-view-blink-enabled self) #$YES))))))
     1077        (when (eql (text-view-blink-enabled self) #$YES)
     1078          (ns:with-ns-range (char-range (text-view-blink-location self) 1)
     1079            (let* ((layout (#/layoutManager self))
     1080                   (container (#/textContainer self))
     1081                   (glyph-range (#/glyphRangeForCharacterRange:actualCharacterRange:
     1082                                 layout
     1083                                 char-range
     1084                                 +null-ptr+))
     1085                   (rect (#/boundingRectForGlyphRange:inTextContainer:
     1086                          layout
     1087                          glyph-range
     1088                          container)))
     1089              (setf (text-view-blink-phase self) #$YES)
     1090              (#/setNeedsDisplayInRect: self rect))))))))
     1091
     1092(objc:defmethod (#/updateInsertionPointStateAndRestartTimer: :void)
     1093    ((self hemlock-textstorage-text-view)
     1094     (restart #>BOOL))
     1095  (setf (text-view-blink-phase self) #$YES)
     1096  (call-next-method restart))
    10751097
    10761098;;; Set and display the selection at pos, whose length is len and whose
     
    10801102
    10811103(objc:defmethod (#/updateSelection:length:affinity: :void)
    1082                 ((self hemlock-textstorage-text-view)
    1083                 (pos :int)
    1084                 (length :int)
    1085                 (affinity :<NSS>election<A>ffinity))
     1104    ((self hemlock-textstorage-text-view)
     1105    (pos :int)
     1106    (length :int)
     1107    (affinity :<NSS>election<A>ffinity))
    10861108  (assume-cocoa-thread)
    10871109  (when (eql length 0)
     
    11221144  (:metaclass ns:+ns-object))
    11231145(declaim (special hemlock-text-view))
     1146
     1147
     1148
     1149;;; LAYOUT is an NSLayoutManager in which we'll set temporary character
     1150;;; attrubutes before redisplay.
     1151;;; POS is the absolute character position of the start of START-LINE.
     1152;;; END-LINE is either EQ to START-LNE (in the degenerate case) or
     1153;;; follows it in the buffer; it may be NIL and is the exclusive
     1154;;; end of a range of lines
     1155;;; HI::*CURRENT-BUFFER* is bound to the buffer containing START-LINE
     1156;;; and END-LINE
     1157(defun set-temporary-character-attributes (layout pos start-line end-line blink-location  blink-color)
     1158  (ns:with-ns-range (range)
     1159    (let* ((color-attribute #&NSForegroundColorAttributeName)
     1160           (string-color  (#/blueColor ns:ns-color) )
     1161           (comment-color (#/grayColor ns:ns-color)))
     1162      (hi::with-mark ((m (hi::buffer-start-mark hi::*current-buffer*)))
     1163        (hi::line-start m start-line)
     1164        (hi::pre-command-parse-check m t))
     1165      (do ((p pos (+ p (1+ (hi::line-length line))))
     1166           (line start-line (hi::line-next line)))
     1167          ((eq line end-line))
     1168        (let* ((parse-info (getf (hi::line-plist line) 'hemlock::lisp-info)))
     1169          (when parse-info
     1170            (dolist (r (hemlock::lisp-info-ranges-to-ignore parse-info))
     1171              (destructuring-bind (istart . iend) r
     1172                (let* ((is-string (if (= istart 0)
     1173                                    (hemlock::lisp-info-begins-quoted parse-info)
     1174                                    (eql (hi::line-character line (1- istart))
     1175                                         #\")))
     1176                       (color (if is-string
     1177                                string-color
     1178                                comment-color)))
     1179                  (if (and is-string (not (= istart 0)))
     1180                    (decf istart))
     1181                  (setf (ns:ns-range-location range) (+ p istart)
     1182                        (ns:ns-range-length range) (1+ (- iend istart)))
     1183                  (#/addTemporaryAttribute:value:forCharacterRange:
     1184                   layout color-attribute color range)))))))
     1185      (when blink-location
     1186        (#/addTemporaryAttribute:value:forCharacterRange:
     1187             layout color-attribute blink-color (ns:make-ns-range blink-location 1))))))
     1188
     1189(objc:defmethod (#/drawRect: :void) ((self hemlock-text-view) (rect :<NSR>ect))
     1190  (let* ((container (#/textContainer self))
     1191         (layout (#/layoutManager container))
     1192         (glyph-range (#/glyphRangeForBoundingRect:inTextContainer:
     1193                       layout rect container))
     1194         (char-range (#/characterRangeForGlyphRange:actualGlyphRange:
     1195                      layout glyph-range +null-ptr+))
     1196         (start (ns:ns-range-location char-range))
     1197         (length (ns:ns-range-length char-range)))
     1198    (when (> length 0)
     1199      ;; Remove all temporary attributes from the character range
     1200      (#/removeTemporaryAttribute:forCharacterRange:
     1201       layout #&NSForegroundColorAttributeName char-range)
     1202      (let* ((ts (#/textStorage self))
     1203             (cache (hemlock-buffer-string-cache (slot-value ts 'hemlock-string)))
     1204             (hi::*current-buffer* (buffer-cache-buffer cache)))
     1205        #+debug (#_NSLog #@"blink-phase = %d" :int (text-view-blink-phase self))
     1206        (multiple-value-bind (start-line start-offset)
     1207            (update-line-cache-for-index cache start)
     1208          (let* ((end-line (update-line-cache-for-index cache (+ start length))))
     1209            (set-temporary-character-attributes
     1210             layout
     1211             (- start start-offset)
     1212             start-line
     1213             (hi::line-next end-line)
     1214             (and (eql #$YES (text-view-blink-enabled self))
     1215                  (eql #$YES (text-view-blink-phase self))
     1216                  (#/shouldDrawInsertionPoint self)
     1217                  (text-view-blink-location self))
     1218             (text-view-blink-color self))))))
     1219    ;; Um, don't forget to actually draw the view..
     1220    (call-next-method  rect)))
     1221
    11241222
    11251223(defmethod hemlock-view ((self hemlock-text-view))
     
    18061904(declaim (special hemlock-frame))
    18071905
    1808 (defmethod hemlock-view ((self hemlock-frame))
    1809   (let ((pane (slot-value self 'pane)))
    1810     (unless (%null-ptr-p pane)
     1906
     1907(defmethod hemlock-view ((frame hemlock-frame))
     1908  (let ((pane (slot-value frame 'pane)))
     1909    (when (and pane (not (%null-ptr-p pane)))
    18111910      (hemlock-view pane))))
    18121911
     
    20142113       t))))
    20152114
    2016 (defun textstorage-note-insertion-at-position (textstorage pos n)
    2017   #+debug
    2018   (#_NSLog #@"insertion at position %d, len %d" :int pos :int n)
    2019   (#/edited:range:changeInLength:
    2020    textstorage #$NSTextStorageEditedAttributes (ns:make-ns-range pos 0) n)
    2021   (#/edited:range:changeInLength:
    2022    textstorage  #$NSTextStorageEditedCharacters (ns:make-ns-range pos n) 0))
     2115
    20232116
    20242117
     
    24302523             
    24312524
    2432 (defmethod hemlock-view ((frame hemlock-frame))
    2433   (let ((pane (slot-value frame 'pane)))
    2434     (when (and pane (not (%null-ptr-p pane)))
    2435       (hemlock-view pane))))
     2525
    24362526
    24372527(defun hemlock-ext:all-hemlock-views ()
Note: See TracChangeset for help on using the changeset viewer.