Changeset 12877


Ignore:
Timestamp:
Sep 22, 2009, 8:48:09 PM (10 years ago)
Author:
gz
Message:

In #/selectionRangeForProposedRange, always start at the proposed location (not at current point) and move point to the other end, so it looks like the selection started there. This fixes bug #565. Also refactor a little for future extensibility...

Location:
trunk/source/cocoa-ide
Files:
2 edited

Legend:

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

    r12859 r12877  
    14911491                                    (> (#/clickCount event) 1))))))
    14921492           (let* ((cache (hemlock-buffer-string-cache (#/hemlockString textstorage)))
    1493                   (buffer (if cache (buffer-cache-buffer cache))))
    1494              (when (and buffer (string= (hi::buffer-major-mode buffer) "Lisp"))
    1495                (let* ((hi::*current-buffer* buffer))
    1496                  (hi::with-mark ((m1 (hi::buffer-point buffer)))
    1497                    (setq index (hi:mark-absolute-position m1))
    1498                    (hemlock::pre-command-parse-check m1)
    1499                    (when (hemlock::valid-spot m1 nil)
    1500                      (cond ((eql (hi::next-character m1) #\()
    1501                             (hi::with-mark ((m2 m1))
    1502                               (when (hemlock::list-offset m2 1)
    1503                                 (ns:init-ns-range r index (- (hi:mark-absolute-position m2) index))
    1504                                 (return-from HANDLED r))))
    1505                            ((eql (hi::previous-character m1) #\))
    1506                             (hi::with-mark ((m2 m1))
    1507                               (when (hemlock::list-offset m2 -1)
    1508                                 (ns:init-ns-range r (hi:mark-absolute-position m2) (- index (hi:mark-absolute-position m2)))
    1509                                 (return-from HANDLED r))))))))))))       
    1510        (call-next-method proposed g)
    1511        #+debug
    1512        (#_NSLog #@"range = %@, proposed = %@, granularity = %d"
    1513                 :address (#_NSStringFromRange r)
    1514                 :address (#_NSStringFromRange proposed)
    1515                 :<NSS>election<G>ranularity g))))
    1516 
    1517 
     1493                  (buffer (buffer-cache-buffer cache))
     1494                  (hi::*current-buffer* buffer)
     1495                  (point (hi::buffer-point buffer)))
     1496             (hi::with-mark ((mark point))
     1497               (move-hemlock-mark-to-absolute-position mark cache index)
     1498               (when (selection-offset-for-double-click buffer mark)
     1499                 ;; Act as if we started the selection at the other end, so the heuristic
     1500                 ;; in #/selectionRangeForProposedRange does the right thing.  ref bug #565.
     1501                 (hi::move-mark point mark)
     1502                 (let ((start index)
     1503                       (end (hi::mark-absolute-position mark)))
     1504                   (when (< end start) (rotatef start end))
     1505                   (ns:init-ns-range r start (- end start)))
     1506                 #+debug
     1507                 (#_NSLog #@"range = %@, proposed = %@, granularity = %d"
     1508                          :address (#_NSStringFromRange r)
     1509                          :address (#_NSStringFromRange proposed)
     1510                          :<NSS>election<G>ranularity g)
     1511                 (return-from HANDLED r))))))
     1512       (prog1
     1513           (call-next-method proposed g)
     1514         #+debug
     1515         (#_NSLog #@"range = %@, proposed = %@, granularity = %d"
     1516                  :address (#_NSStringFromRange r)
     1517                  :address (#_NSStringFromRange proposed)
     1518                  :<NSS>election<G>ranularity g)))))
     1519
     1520;; Return nil to use the default Cocoa selection, which will be word for double-click, line for triple.
     1521;; TODO: make this consistent with "current sexp".
     1522(defun selection-offset-for-double-click (buffer mark)
     1523  (when (string= (hi::buffer-major-mode buffer) "Lisp") ;; gag
     1524    (hemlock::pre-command-parse-check mark)
     1525    (when (hemlock::valid-spot mark nil)
     1526      (cond ((eql (hi::next-character mark) #\()
     1527             (hemlock::list-offset mark 1))
     1528            ((eql (hi::previous-character mark) #\))
     1529             (hemlock::list-offset mark -1))))))
    15181530
    15191531(defun append-output (view string)
     
    15341546     (affinity :<NSS>election<A>ffinity)
    15351547     (still-selecting :<BOOL>))
    1536   #+debug
    1537   (#_NSLog #@"Set selected range called: location = %d, length = %d, affinity = %d, still-selecting = %d"
    1538            :int (pref r :<NSR>ange.location)
    1539            :int (pref r :<NSR>ange.length)
     1548  #+debug
     1549  (#_NSLog #@"Set selected range called: range = %@, affinity = %d, still-selecting = %d"
     1550           :address (#_NSStringFromRange r)
    15401551           :<NSS>election<A>ffinity affinity
    15411552           :<BOOL> (if still-selecting #$YES #$NO))
  • trunk/source/cocoa-ide/hemlock/src/listener.lisp

    r12859 r12877  
    601601
    602602(defcommand "Editor Evaluate Defun" (p)
    603   "Evaluates the current or next top-level form in the editor Lisp.
     603  "Evaluates the current or next top-level form.
    604604   If the current region is active, this evaluates the region."
    605   "Evaluates the current or next top-level form in the editor Lisp."
    606605  (declare (ignore p))
    607606  (if (region-active-p)
     
    610609
    611610(defcommand "Editor Evaluate Region" (p)
    612   "Evaluates lisp forms between the point and the mark in the editor Lisp."
    613   "Evaluates lisp forms between the point and the mark in the editor Lisp."
     611  "Evaluates lisp forms between the point and the mark"
    614612  (declare (ignore p))
    615613  (if (region-active-p)
     
    634632(defcommand "Editor Re-evaluate Defvar" (p)
    635633  "Evaluate the current or next top-level form if it is a DEFVAR.  Treat the
    636    form as if the variable is not bound.  This occurs in the editor Lisp."
    637   "Evaluate the current or next top-level form if it is a DEFVAR.  Treat the
    638    form as if the variable is not bound.  This occurs in the editor Lisp."
     634   form as if the variable is not bound."
    639635  (declare (ignore p))
    640636  (with-input-from-region (stream (defun-region (current-point)))
Note: See TracChangeset for help on using the changeset viewer.