@@ -986,7 +986,13 @@ class InputGuard {
986986 // console.log("[text-input-guard] input");
987987 // compositionend後に input が来た場合、フォールバックを無効化
988988 this . pendingCompositionCommit = false ;
989- this . evaluateInput ( ) ;
989+ try {
990+ this . evaluateInput ( ) ;
991+ } finally {
992+ // beforeinput が来ない入力経路(autocomplete等)で
993+ // 古い snapshot を使い回さないよう、1イベントごとに破棄する
994+ this . beforeInputSnapshot = null ;
995+ }
990996 }
991997
992998 /**
@@ -1145,17 +1151,43 @@ class InputGuard {
11451151 const ctx = this . createCtx ( ) ;
11461152 ctx . afterText = current ;
11471153
1148- // beforeinput が取得できない経路(初回評価)では
1149- // 差分再構成を行うと lastAcceptedValue 基準で値を落とす可能性があるため、
1150- // 現在の全文を正規化して扱うフォールバックへ切り替える。
1151- if ( ! this . beforeInputSnapshot ) {
1154+ /**
1155+ * 入力値情報のみを使用するフォールバック
1156+ * @returns {GuardContext }
1157+ */
1158+ const applyFullNormalizeFromCurrent = ( ) => {
11521159 let newText = current ;
11531160 ctx . beforeText = "" ;
11541161 newText = this . runNormalizeChar ( newText , ctx ) ;
11551162 newText = this . runNormalizeStructure ( newText , ctx ) ;
11561163 this . setDisplayValuePreserveCaret ( display , newText , ctx ) ;
11571164 ctx . afterText = newText ;
11581165 return ctx ;
1166+ } ;
1167+
1168+ // beforeinput が取得できない経路(初回評価)では
1169+ // 差分再構成を行うと lastAcceptedValue 基準で値を落とす可能性があるため、
1170+ // 現在の全文を正規化して扱うフォールバックへ切り替える。
1171+ if ( ! this . beforeInputSnapshot ) {
1172+ return applyFullNormalizeFromCurrent ( ) ;
1173+ }
1174+
1175+ // オートコンプリート等では beforeinput は来ても data が空のことがあり、
1176+ // 差分情報だけでは再構成不能になる。表示値がすでに変わっている場合は
1177+ // 再構成を諦めて current 全体の正規化に切り替える。
1178+ const isDeleteInput =
1179+ ctx . inputType === "deleteContentBackward" ||
1180+ ctx . inputType === "deleteContentForward" ;
1181+ const isInsertLikeInput =
1182+ ctx . inputType === "" ||
1183+ ctx . inputType ?. startsWith ( "insert" ) ;
1184+ const lacksDelta =
1185+ ctx . insertedText === "" &&
1186+ ctx . beforeText !== current &&
1187+ isInsertLikeInput &&
1188+ ! isDeleteInput ;
1189+ if ( lacksDelta ) {
1190+ return applyFullNormalizeFromCurrent ( ) ;
11591191 }
11601192
11611193 // 元のテキスト
0 commit comments