瀏覽代碼

Add modification hook for inline images

This patch adds a modification hook to remove inline-image overlays if
the underlying text is modified.  This prevents blind editing of text
behind images.
Martin Pohlack 15 年之前
父節點
當前提交
d18653505d
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      lisp/org.el

+ 9 - 0
lisp/org.el

@@ -15943,8 +15943,17 @@ BEG and END default to the buffer boundaries."
 		(overlay-put ov 'display img)
 		(overlay-put ov 'face 'default)
 		(overlay-put ov 'org-image-overlay t)
+		(overlay-put ov 'modification-hooks
+			     (list 'org-display-inline-modification-hook))
 		(push ov org-inline-image-overlays)))))))))
 
+(defun org-display-inline-modification-hook (ov after beg end &optional len)
+  "Remove inline-display overlay if a corresponding region is modified."
+  (let ((inhibit-modification-hooks t))
+    (when (and ov after)
+      (delete ov org-inline-image-overlays)
+      (delete-overlay ov))))
+
 (defun org-remove-inline-images ()
   "Remove inline display of images."
   (interactive)