Changeset 15325
- Timestamp:
- Apr 13, 2012, 2:04:38 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/source/cocoa-ide/cocoa-editor.lisp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/cocoa-ide/cocoa-editor.lisp
r15291 r15325 1527 1527 (hemlock-buffer-string-cache (#/hemlockString (#/textStorage self)))) 1528 1528 1529 1529 1530 (objc:defmethod (#/selectionRangeForProposedRange:granularity: :ns-range) 1530 1531 ((self hemlock-textstorage-text-view) … … 1534 1535 (#_NSLog #@"Granularity = %d" :int g) 1535 1536 (objc:returning-foreign-struct (r) 1536 (block HANDLED 1537 (let* ((index (ns:ns-range-location proposed)) 1538 (length (ns:ns-range-length proposed)) 1539 (textstorage (#/textStorage self)) 1540 (event (#/currentEvent (#/window self))) 1541 (event-type (#/type event))) 1542 ;; Workaround for bug #150 1543 (when (and (eql g #$NSSelectByCharacter) 1544 (eql index (#/length textstorage)) 1545 (or (eql event-type #$NSLeftMouseDown) (eql event-type #$NSLeftMouseUp))) 1546 (setq g (case (#/clickCount event) 1547 ((0 1) #$NSSelectByCharacter) 1548 (2 #$NSSelectByWord) 1549 (t #$NSSelectByParagraph)))) 1550 (unless (eql g #$NSSelectByCharacter) 1551 (let* ((cache (hemlock-buffer-string-cache (#/hemlockString textstorage))) 1552 (buffer (buffer-cache-buffer cache)) 1553 (hi::*current-buffer* buffer) 1554 (point (hi:buffer-point buffer)) 1555 (atom-mode (eql g #$NSSelectByParagraph))) 1556 (hi:with-mark ((mark point)) 1557 (when (or (= length 0) (hi:move-to-absolute-position mark index)) 1558 (let* ((region (selection-for-click mark atom-mode)) 1559 (other-region (and (< 0 length) 1560 (hi:character-offset mark length) 1561 (selection-for-click mark atom-mode)))) 1562 (when (null region) (setq region other-region other-region nil)) 1563 (when region 1564 (let ((start-pos (min (hi:mark-absolute-position (hi:region-start region)) 1565 (if other-region 1566 (hi:mark-absolute-position (hi:region-start other-region)) 1567 index))) 1568 (end-pos (max (hi:mark-absolute-position (hi:region-end region)) 1569 (if other-region 1570 (hi:mark-absolute-position (hi:region-end other-region)) 1571 (+ index length))))) 1572 (assert (<= start-pos end-pos)) 1573 ;; Act as if we started the selection at the other end, so the heuristic 1574 ;; in #/setSelectedRange does the right thing. ref bug #565. 1575 ;; However, only do so at the end, so don't keep toggling during selection, ref bug #851. 1576 (when (and (eql event-type #$NSLeftMouseUp) (< start-pos end-pos)) 1577 (let ((point-pos (hi:mark-absolute-position point))) 1578 (cond ((eql point-pos start-pos) 1579 (hi:move-to-absolute-position point end-pos)) 1580 ((eql point-pos end-pos) 1581 (hi:move-to-absolute-position point start-pos))))) 1582 (ns:init-ns-range r start-pos (- end-pos start-pos)) 1583 #+debug 1584 (#_NSLog #@"range = %@, proposed = %@, granularity = %d" 1585 :address (#_NSStringFromRange r) 1586 :address (#_NSStringFromRange proposed) 1587 :<NSS>election<G>ranularity g) 1588 (return-from HANDLED r)))))))) 1589 (prog1 1590 (call-next-method proposed g) 1591 #+debug 1592 (#_NSLog #@"range = %@, proposed = %@, granularity = %d" 1593 :address (#_NSStringFromRange r) 1594 :address (#_NSStringFromRange proposed) 1595 :<NSS>election<G>ranularity g)))))) 1537 (block HANDLED 1538 (let* ((index (ns:ns-range-location proposed)) 1539 (length (ns:ns-range-length proposed)) 1540 (textstorage (#/textStorage self)) 1541 (event (#/currentEvent (#/window self))) 1542 (event-type (#/type event))) 1543 ;; Workaround for bug #150 1544 (when (and (eql g #$NSSelectByCharacter) 1545 (eql index (#/length textstorage)) 1546 (or (eql event-type #$NSLeftMouseDown) (eql event-type #$NSLeftMouseUp))) 1547 (setq g (case (#/clickCount event) 1548 ((0 1) #$NSSelectByCharacter) 1549 (2 #$NSSelectByWord) 1550 (t #$NSSelectByParagraph)))) 1551 (unless (eql g #$NSSelectByCharacter) 1552 (let* ((cache (hemlock-buffer-string-cache (#/hemlockString textstorage))) 1553 (buffer (buffer-cache-buffer cache))) 1554 (with-view-selection-info (self buffer) 1555 (let* ((hi::*current-buffer* buffer) 1556 (point (hi:buffer-point buffer)) 1557 (atom-mode (eql g #$NSSelectByParagraph))) 1558 (hi:with-mark ((mark point)) 1559 (when (or (= length 0) (hi:move-to-absolute-position mark index)) 1560 (let* ((region (selection-for-click mark atom-mode)) 1561 (other-region (and (< 0 length) 1562 (hi:character-offset mark length) 1563 (selection-for-click mark atom-mode)))) 1564 (when (null region) (setq region other-region other-region nil)) 1565 (when region 1566 (let ((start-pos (min (hi:mark-absolute-position (hi:region-start region)) 1567 (if other-region 1568 (hi:mark-absolute-position (hi:region-start other-region)) 1569 index))) 1570 (end-pos (max (hi:mark-absolute-position (hi:region-end region)) 1571 (if other-region 1572 (hi:mark-absolute-position (hi:region-end other-region)) 1573 (+ index length))))) 1574 (assert (<= start-pos end-pos)) 1575 ;; Act as if we started the selection at the other end, so the heuristic 1576 ;; in #/setSelectedRange does the right thing. ref bug #565. 1577 ;; However, only do so at the end, so don't keep toggling during selection, ref bug #851. 1578 (when (and (eql event-type #$NSLeftMouseUp) (< start-pos end-pos)) 1579 (let ((point-pos (hi:mark-absolute-position point))) 1580 (cond ((eql point-pos start-pos) 1581 (hi:move-to-absolute-position point end-pos)) 1582 ((eql point-pos end-pos) 1583 (hi:move-to-absolute-position point start-pos))))) 1584 (ns:init-ns-range r start-pos (- end-pos start-pos)) 1585 #+debug 1586 (#_NSLog #@"range = %@, proposed = %@, granularity = %d" 1587 :address (#_NSStringFromRange r) 1588 :address (#_NSStringFromRange proposed) 1589 :<NSS>election<G>ranularity g) 1590 (return-from HANDLED r)))))))))) 1591 (prog1 1592 (call-next-method proposed g) 1593 #+debug 1594 (#_NSLog #@"range = %@, proposed = %@, granularity = %d" 1595 :address (#_NSStringFromRange r) 1596 :address (#_NSStringFromRange proposed) 1597 :<NSS>election<G>ranularity g)))))) 1596 1598 1597 1599 ;; Return nil to use the default Cocoa selection, which will be word for double-click, line for triple.
Note:
See TracChangeset
for help on using the changeset viewer.
