Changeset 12278


Ignore:
Timestamp:
Jun 23, 2009, 4:42:04 PM (10 years ago)
Author:
mikel
Message:

Ticket #471: hitting a right arrow or C-f ("Forward Character") now collapses the selection if one is active, leaving the insertion point at the right end of the selection. Formerly, "Forward Character" always moved the insertion point, even if a selection was active, violating the expectations of many users.

"Backward Character" is also altered to provide the analogous behavior.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/cocoa-ide/hemlock/src/command.lisp

    r12121 r12278  
    6262  (setf (hi::hemlock-view-quote-next-p hi::*current-view*) :native))
    6363
     64#| the old way
    6465(defcommand "Forward Character" (p)
    6566  "Move the point forward one character, collapsing the selection.
     
    7980               (buffer-start point))
    8081           (editor-error "Not enough characters.")))))
    81 
    82 (defcommand "Select Forward Character" (p)
    83   "Move the point forward one character, extending the selection.
     82|#
     83
     84;;; experimental: if there is an active region, we want to collapse the selection to the end,
     85;;; rather than collapse it AND move forward one character
     86(defcommand "Forward Character" (p)
     87    "Move the point forward one character, collapsing the selection.
    8488   With prefix argument move that many characters, with negative argument
    8589   go backwards."
    86   "Move the point of the current buffer forward p characters, extending the selection."
    87   (let* ((p (or p 1))
    88          (point (current-point-extending-selection)))
     90    "Move the point of the current buffer forward p characters, collapsing the selection."
     91  (let* ((p (cond
     92              (p p)
     93              ((hi::%buffer-current-region-p hi::*current-buffer*) 0)
     94              (t 1)))
     95         (point (current-point-collapsing-selection)))
    8996    (cond ((character-offset point p))
    90           ((= p 1)
    91            (editor-error "No next character."))
    92           ((= p -1)
    93            (editor-error "No previous character."))
    94           (t
    95            (if (plusp p)
    96                (buffer-end point)
    97                (buffer-start point))
    98            (editor-error "Not enough characters.")))))
    99 
     97          ((= p 1)
     98           (editor-error "No next character."))
     99          ((= p -1)
     100           (editor-error "No previous character."))
     101          (t
     102           (if (plusp p)
     103               (buffer-end point)
     104               (buffer-start point))
     105           (editor-error "Not enough characters.")))))
     106
     107(defcommand "Select Forward Character" (p)
     108    "Move the point forward one character, extending the selection.
     109   With prefix argument move that many characters, with negative argument
     110   go backwards."
     111    "Move the point of the current buffer forward p characters, extending the selection."
     112  (if (hi::%buffer-current-region-p hi::*current-buffer*)
     113      (multiple-value-bind (start end)(region-bounds (current-region nil nil))
     114        (setf (buffer-point hi::*current-buffer*) end)
     115        (setf (hi::buffer-region-active hi::*current-buffer*) nil))
     116      (let* ((p (cond
     117                  (p p)
     118                  ((hi::%buffer-current-region-p hi::*current-buffer*) 0)
     119                  (t 1)))
     120             (point (current-point-collapsing-selection)))
     121        (cond ((character-offset point p))
     122              ((= p 1)
     123               (editor-error "No next character."))
     124              ((= p -1)
     125               (editor-error "No previous character."))
     126              (t
     127               (if (plusp p)
     128                   (buffer-end point)
     129                   (buffer-start point))
     130               (editor-error "Not enough characters."))))))
     131
     132#| the old way
    100133(defcommand "Backward Character" (p)
    101134  "Move the point backward one character, collapsing the selection.
     
    103136  "Move the point p characters backward, collapsing the selection."
    104137  (forward-character-command (if p (- p) -1)))
     138|#
     139
     140;;; experimental: if there is an active region, we want to collapse the selection to the start,
     141;;; rather than collapse it AND move backward one character
     142(defcommand "Backward Character" (p)
     143    "Move the point backward one character, collapsing the selection.
     144  With prefix argument move that many characters backward."
     145    "Move the point p characters backward, collapsing the selection."
     146  (if (hi::%buffer-current-region-p hi::*current-buffer*)
     147      (multiple-value-bind (start end)(region-bounds (current-region nil nil))
     148        (setf (buffer-point hi::*current-buffer*) start)
     149        (setf (hi::buffer-region-active hi::*current-buffer*) nil))
     150      (forward-character-command (if p (- p) -1))))
    105151
    106152(defcommand "Select Backward Character" (p)
Note: See TracChangeset for help on using the changeset viewer.