diff options
author | Federico Tedin <federicotedin@gmail.com> | 2018-10-26 13:16:50 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2018-10-26 13:16:50 -0400 |
commit | 8fffac14b19d375f774b835ea33ef8989300125d (patch) | |
tree | a70868fb5928796e8f2522bf9dc13a0072a8c88c /lisp/mouse.el | |
parent | f172ceda8aa5011c1ab79d812f2374a1dbe7a3ef (diff) | |
download | emacs-8fffac14b19d375f774b835ea33ef8989300125d.tar.gz emacs-8fffac14b19d375f774b835ea33ef8989300125d.tar.bz2 emacs-8fffac14b19d375f774b835ea33ef8989300125d.zip |
Subject: (mouse-drag-and-drop-region): Simplify and remove assumptions
* lisp/mouse.el (mouse-drag-and-drop-region): Use insert-for-yank for
insertion, remove rectangular-region-specific variables.
Use text-property-not-all.
* lisp/rect.el (rectangle-dimensions): New function.
(rectangle-position-as-coordinates): Use the usual 1-origin for lines.
Diffstat (limited to 'lisp/mouse.el')
-rw-r--r-- | lisp/mouse.el | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el index 44cca4c868a..7efe751ab6b 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -2413,16 +2413,13 @@ is copied instead of being cut." (buffer (current-buffer)) (window (selected-window)) (text-from-read-only buffer-read-only) - ;; Use multiple overlays to cover cases where the region is - ;; rectangular. + ;; Use multiple overlays to cover cases where the region has more + ;; than one boundary. (mouse-drag-and-drop-overlays (mapcar (lambda (bounds) (make-overlay (car bounds) (cdr bounds))) (region-bounds))) (region-noncontiguous (region-noncontiguous-p)) - (region-width (- (overlay-end (car mouse-drag-and-drop-overlays)) - (overlay-start (car mouse-drag-and-drop-overlays)))) - (region-height (length mouse-drag-and-drop-overlays)) point-to-paste point-to-paste-read-only window-to-paste @@ -2467,10 +2464,6 @@ is copied instead of being cut." ;; skipped, value-selection remains nil. (unless value-selection (setq value-selection (funcall region-extract-function nil)) - ;; Remove yank-handler property in order to re-insert text using - ;; the `insert-rectangle' function later on. - (remove-text-properties 0 (length value-selection) - '(yank-handler) value-selection) (when mouse-drag-and-drop-region-show-tooltip (let ((text-size mouse-drag-and-drop-region-show-tooltip)) (setq text-tooltip @@ -2485,15 +2478,11 @@ is copied instead of being cut." ;; Check if selected text is read-only. (setq text-from-read-only (or text-from-read-only - (get-text-property start 'read-only) - (get-text-property end 'read-only) (catch 'loop - (dolist (bound (region-bounds)) - (unless (equal - (next-single-char-property-change - (car bound) 'read-only nil (cdr bound)) - (cdr bound)) - (throw 'loop t))))))) + (dolist (bound (region-bounds)) + (when (text-property-not-all + (car bound) (cdr bound) 'read-only nil) + (throw 'loop t))))))) (setq window-to-paste (posn-window (event-end event))) (setq point-to-paste (posn-point (event-end event))) @@ -2531,16 +2520,16 @@ is copied instead of being cut." (and (eq (overlay-buffer (car mouse-drag-and-drop-overlays)) buffer-to-paste) (if region-noncontiguous - (let ((size (cons region-width region-height)) + (let ((dimensions (rectangle-dimensions start end)) (start-coordinates (rectangle-position-as-coordinates start)) (point-to-paste-coordinates (rectangle-position-as-coordinates point-to-paste))) (and (rectangle-intersect-p - start-coordinates size - point-to-paste-coordinates size) - (not (<= (car point-to-paste-coordinates) + start-coordinates dimensions + point-to-paste-coordinates dimensions) + (not (< (car point-to-paste-coordinates) (car start-coordinates))))) (and (<= (overlay-start (car mouse-drag-and-drop-overlays)) @@ -2635,10 +2624,7 @@ is copied instead of being cut." (setq window-exempt window-to-paste) (goto-char point-to-paste) (push-mark) - - (if region-noncontiguous - (insert-rectangle (split-string value-selection "\n")) - (insert value-selection)) + (insert-for-yank value-selection) ;; On success, set the text as region on destination buffer. (when (not (equal (mark) (point))) |