]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve word selection behavior
authorPo Lu <luangruo@yahoo.com>
Mon, 17 Jul 2023 04:58:29 +0000 (12:58 +0800)
committerPo Lu <luangruo@yahoo.com>
Mon, 17 Jul 2023 04:58:29 +0000 (12:58 +0800)
* lisp/tab-bar.el (tab-bar-map): Don't bind touch-screen-drag.
* lisp/touch-screen.el (touch-screen-drag): Extend the region
based on the position of the mark, not the position of point
relative to EVENT.
(touch-screen-translate-touch): Don't generate virtual function
keys for non-mouse events.
(function-key-map): Remove redundant definitions.
* src/keyboard.c (read_key_sequence): Don't generate *-bar
prefix keys for mock input (such as input from function key
translation.)

lisp/tab-bar.el
lisp/touch-screen.el
src/keyboard.c

index a81f42fc7519a5addf7392f49d3faf983807fc55..044337260ce56ef9dd122b5987bd2179f6f1b721 100644 (file)
@@ -493,9 +493,7 @@ appropriate."
   "S-<wheel-down>"  #'tab-bar-move-tab
   "S-<wheel-left>"  #'tab-bar-move-tab-backward
   "S-<wheel-right>" #'tab-bar-move-tab
-  "<touchscreen-begin>" #'tab-bar-touchscreen-begin
-  ;; Trying to set this in `touch-screen.el' runs afoul of the filter.
-  "<touchscreen-drag>"  'touchscreen-drag)
+  "<touchscreen-begin>" #'tab-bar-touchscreen-begin)
 
 (global-set-key [tab-bar]
                 `(menu-item ,(purecopy "tab bar") ,(make-sparse-keymap)
index 4543dc5e8ce22e79de27a45928994d4cadb2b729..f500076c78acb09aa54913912b72b90eac2a830a 100644 (file)
@@ -405,22 +405,28 @@ area."
                     ;; BEGV if this word is there.
                     (backward-word-strictly)
                     (setq word-start (point)))
-                  ;; If point is greater than the current point, set
-                  ;; it to word-end.
-                  (if (> point (point))
-                      (goto-char word-end)
-                    ;; Else, go to the start of the word.
-                    (goto-char word-start))
-                  ;; If point is less than mark, which is is less than
-                  ;; the end of the word that was originally selected,
-                  ;; try to keep it selected by moving mark there.
-                  (when (and initial (<= (point) (mark))
-                             (< (mark) (cdr initial)))
-                    (set-mark (cdr initial)))
-                  ;; Do the opposite when the converse is true.
-                  (when (and initial (>= (point) (mark))
-                             (> (mark) (car initial)))
-                    (set-mark (car initial)))
+                  (let ((mark (mark)))
+                    ;; Extend the region to cover either word-end or
+                    ;; word-start; whether to goto word-end or
+                    ;; word-start is subject to the position of the
+                    ;; mark relative to point.
+                    (if (< word-start mark)
+                        ;; The start of the word is behind mark.
+                        ;; Extend the region towards the start.
+                        (goto-char word-start)
+                      ;; Else, go to the end of the word.
+                      (goto-char word-end))
+                    ;; If point is less than mark, which is is less
+                    ;; than the end of the word that was originally
+                    ;; selected, try to keep it selected by moving
+                    ;; mark there.
+                    (when (and initial (<= (point) mark)
+                               (< mark (cdr initial)))
+                      (set-mark (cdr initial)))
+                    ;; Do the opposite when the converse is true.
+                    (when (and initial (>= (point) mark)
+                               (> mark (car initial)))
+                      (set-mark (car initial))))
                   (if bounds
                       (progn (setcar bounds word-start)
                              (setcdr bounds word-end))
@@ -439,33 +445,28 @@ area."
                   (when (and (>= (point) (mark))
                              (> (mark) (car initial)))
                     (set-mark (car initial))))
-                (setq touch-screen-word-select-bounds nil)))
-            (let ((relative-xy
-                   (touch-screen-relative-xy posn window)))
-              (let ((scroll-conservatively 101))
-                (cond
-                 ((< (cdr relative-xy) 0)
-                  (ignore-errors
-                    (goto-char (1- (window-start)))
-                    (setq touch-screen-word-select-bounds nil))
-                  (redisplay))
-                 ((> (cdr relative-xy)
-                     (let ((edges (window-inside-pixel-edges)))
-                       (- (nth 3 edges) (cadr edges))))
-                  (ignore-errors
-                    (goto-char (1+ (window-end nil t)))
-                    (setq touch-screen-word-select-bounds nil))
-                  (redisplay))))))))))
+                (setq touch-screen-word-select-bounds nil))))
+        ;; POSN is outside the window.  Scroll accordingly.
+        (let ((relative-xy
+               (touch-screen-relative-xy posn window)))
+          (let ((scroll-conservatively 101))
+            (cond
+             ((< (cdr relative-xy) 0)
+              (ignore-errors
+                (goto-char (1- (window-start)))
+                (setq touch-screen-word-select-bounds nil))
+              (redisplay))
+             ((> (cdr relative-xy)
+                 (let ((edges (window-inside-pixel-edges)))
+                   (- (nth 3 edges) (cadr edges))))
+              (ignore-errors
+                (goto-char (1+ (window-end nil t)))
+                (setq touch-screen-word-select-bounds nil))
+              (redisplay)))))))))
 
 (global-set-key [touchscreen-hold] #'touch-screen-hold)
 (global-set-key [touchscreen-drag] #'touch-screen-drag)
 
-;; Bind this to most of the virtual prefix keys as well.
-(global-set-key [tool-bar touchscreen-drag] #'touch-screen-drag)
-(global-set-key [header-line touchscreen-drag] #'touch-screen-drag)
-(global-set-key [mode-line touchscreen-drag] #'touch-screen-drag)
-(global-set-key [tab-line touchscreen-drag] #'touch-screen-drag)
-
 \f
 
 ;; Touch screen event translation.  The code here translates raw touch
@@ -911,6 +912,11 @@ if POSN is on a link or a button, or `mouse-1' otherwise."
         ;; or an empty vector if it is nil, meaning that
         ;; no key events have been translated.
         (if event (or (and prefix (consp event)
+                           ;; Only generate virtual function keys for
+                           ;; mouse events.
+                           (memq (car event)
+                                 '(down-mouse-1 mouse-1
+                                   mouse-2 mouse-movement))
                            ;; If this is a mode line event, then
                            ;; generate the appropriate function key.
                            (vector prefix event))
@@ -932,8 +938,6 @@ if POSN is on a link or a button, or `mouse-1' otherwise."
 
 (define-key function-key-map [mode-line touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [mode-line touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [mode-line touchscreen-end]
             #'touch-screen-translate-touch)
 
@@ -942,67 +946,54 @@ if POSN is on a link or a button, or `mouse-1' otherwise."
 
 (define-key function-key-map [nil touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [nil touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [nil touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [header-line touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [header-line touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [header-line touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [bottom-divider touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [bottom-divider touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [bottom-divider touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [right-divider touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [right-divider touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [right-divider touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [right-divider touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [right-divider touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [right-divider touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [left-fringe touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [left-fringe touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [left-fringe touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [right-fringe touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [right-fringe touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [right-fringe touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [left-margin touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [left-margin touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [left-margin touchscreen-end]
             #'touch-screen-translate-touch)
 
 (define-key function-key-map [right-margin touchscreen-begin]
             #'touch-screen-translate-touch)
-(define-key function-key-map [right-margin touchscreen-update]
-            #'touch-screen-translate-touch)
 (define-key function-key-map [right-margin touchscreen-end]
             #'touch-screen-translate-touch)
 
+(define-key function-key-map [tool-bar touchscreen-begin]
+            #'touch-screen-translate-touch)
+(define-key function-key-map [tool-bar touchscreen-end]
+            #'touch-screen-translate-touch)
+
 \f
 ;; Exports.  These functions are intended for use externally.
 
index fa5eea31c3b2e02cb02e9e673a15f518ba8f1431..78105fa9e05787dc4976cbaab5c33f298d745078 100644 (file)
@@ -10762,7 +10762,15 @@ read_key_sequence (Lisp_Object *keybuf, Lisp_Object prompt,
              posn = POSN_POSN (xevent_start (key));
              /* Handle menu-bar events:
                 insert the dummy prefix event `menu-bar'.  */
-             if (EQ (posn, Qmenu_bar) || EQ (posn, Qtab_bar) || EQ (posn, Qtool_bar))
+             if ((EQ (posn, Qmenu_bar) || EQ (posn, Qtab_bar)
+                  || EQ (posn, Qtool_bar))
+                 /* Only insert the prefix key if the event comes
+                    directly from the keyboard buffer.  Key
+                    translation functions might return events with a
+                    `posn-area' of tool-bar or tab-bar without
+                    intending for these prefix events to be
+                    generated.  */
+                 && (mock_input <= t))
                {
                  if (READ_KEY_ELTS - t <= 1)
                    error ("Key sequence too long");