From 0a4653f2dff1c84f1f1b266c9a9839395b337851 Mon Sep 17 00:00:00 2001
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
Date: Thu, 25 Nov 2021 02:41:26 +0900
Subject: [PATCH 2/2] =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0?=
 =?UTF-8?q?=E7=B5=B5=E6=96=87=E5=AD=97=E4=BB=A5=E9=99=8D=E3=81=AEURL?=
 =?UTF-8?q?=E6=96=87=E5=AD=97=E5=88=97=E9=81=B8=E6=8A=9E=E7=AF=84=E5=9B=B2?=
 =?UTF-8?q?=E3=81=8C=E3=82=BA=E3=83=AC=E3=82=8B=E3=81=AE=E3=82=92=E4=BF=AE?=
 =?UTF-8?q?=E6=AD=A3=20refs=20#1546?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 plugin/gtk3/widget/miraclepainter.rb | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/plugin/gtk3/widget/miraclepainter.rb b/plugin/gtk3/widget/miraclepainter.rb
index 3206a39d..35844a2b 100644
--- a/plugin/gtk3/widget/miraclepainter.rb
+++ b/plugin/gtk3/widget/miraclepainter.rb
@@ -233,7 +233,12 @@ class Plugin::Gtk3::MiraclePainter < Gtk::ListBoxRow
         index = main_pos_to_index(x, y)
         if index
           clicked_note = score.find{|note|
-            index -= note.description.size
+            if UserConfig[:miraclepainter_expand_custom_emoji] && note.respond_to?(:inline_photo)
+              # 1 -> 置換された絵文字の文字長
+              index -= 1
+            else
+              index -= note.description.size
+            end
             index < 0
           }
           Plugin.call(:open, clicked_note) if clickable?(clicked_note)
@@ -674,7 +679,12 @@ private
     index = main_pos_to_index(x, y)
     if index # the cursor is placed on text
       pointed_note = score.find{|note|
-        index -= note.description.size
+        if UserConfig[:miraclepainter_expand_custom_emoji] && note.respond_to?(:inline_photo)
+          # 1 -> 置換された絵文字の文字長
+          index -= 1
+        else
+          index -= note.description.size
+        end
         index < 0
       }
       if clickable?(pointed_note)
-- 
2.33.0

