summaryrefslogtreecommitdiff
path: root/lisp/composite.el
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2022-06-27 15:32:53 +0300
committerEli Zaretskii <eliz@gnu.org>2022-06-27 15:32:53 +0300
commit0190dff96ac15e48ad57f33d69f5900b3851b9e0 (patch)
treefb4299d32c151b207caf1f0fbbd828125f843134 /lisp/composite.el
parentf9f41c586a31ad5ba326834c9f4dddfcf78f69e9 (diff)
downloademacs-0190dff96ac15e48ad57f33d69f5900b3851b9e0.tar.gz
Fix deletion of composed text
* lisp/composite.el (lgstring-glyph-boundary): New function. * lisp/simple.el (delete-forward-char): Call 'lgstring-glyph-boundary' to find where to end the deletion inside an automatic composition. (Bug#56237)
Diffstat (limited to 'lisp/composite.el')
-rw-r--r--lisp/composite.el19
1 files changed, 19 insertions, 0 deletions
diff --git a/lisp/composite.el b/lisp/composite.el
index d7ac75708c9..6fcf637584e 100644
--- a/lisp/composite.el
+++ b/lisp/composite.el
@@ -474,6 +474,25 @@ after a sequence of character events."
(aset gstring (1- len) nil))
gstring)
+(defun lgstring-glyph-boundary (gstring startpos endpos)
+ "Return buffer position at or after ENDPOS where grapheme from GSTRING ends.
+STARTPOS is the position where the grapheme cluster starts; it is returned
+by `find-composition'."
+ (let ((nglyphs (lgstring-glyph-len gstring))
+ (idx 0)
+ glyph found)
+ (while (and (not found) (< idx nglyphs))
+ (setq glyph (lgstring-glyph gstring idx))
+ (cond
+ ((or (null glyph)
+ (= (+ startpos (lglyph-from glyph)) endpos))
+ (setq found endpos))
+ ((>= (+ startpos (lglyph-to glyph)) endpos)
+ (setq found (+ startpos (lglyph-to glyph) 1)))
+ (t
+ (setq idx (1+ idx)))))
+ (or found endpos)))
+
(defun compose-glyph-string (gstring from to)
(let ((glyph (lgstring-glyph gstring from))
from-pos to-pos)