Skip to content

Commit 9b5d55e

Browse files
committed
attach 実行時に事前にテキストが入力されている場合は、それに対して処理を行うように変更
1 parent 6b7a0ba commit 9b5d55e

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/text-input-guard.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class InputGuard {
482482
this.applySeparateValue();
483483
this.bindEvents();
484484
// 初期値を評価
485-
this.evaluateInput();
485+
this.evaluateCommit();
486486
}
487487

488488
/**
@@ -776,10 +776,10 @@ class InputGuard {
776776
if (inputType === "deleteContentBackward") {
777777
// Backspace: キャレットの左側1文字を削除
778778
replaceStart = Math.max(0, replaceStart - 1);
779-
replaceEnd = snapSel.start ?? replaceEnd;
779+
replaceEnd = snapSel?.start ?? replaceEnd;
780780
} else if (inputType === "deleteContentForward") {
781781
// Delete: キャレットの右側1文字を削除
782-
replaceStart = snapSel.start ?? replaceStart;
782+
replaceStart = snapSel?.start ?? replaceStart;
783783
replaceEnd = Math.min(beforeText.length, replaceEnd + 1);
784784
}
785785
// 追加で拾うならここ:
@@ -1145,6 +1145,19 @@ class InputGuard {
11451145
const ctx = this.createCtx();
11461146
ctx.afterText = current;
11471147

1148+
// beforeinput が取得できない経路(初回評価)では
1149+
// 差分再構成を行うと lastAcceptedValue 基準で値を落とす可能性があるため、
1150+
// 現在の全文を正規化して扱うフォールバックへ切り替える。
1151+
if (!this.beforeInputSnapshot) {
1152+
let newText = current;
1153+
ctx.beforeText = "";
1154+
newText = this.runNormalizeChar(newText, ctx);
1155+
newText = this.runNormalizeStructure(newText, ctx);
1156+
this.setDisplayValuePreserveCaret(display, newText, ctx);
1157+
ctx.afterText = newText;
1158+
return ctx;
1159+
}
1160+
11481161
// 元のテキスト
11491162
const beforeText = ctx.beforeText;
11501163

0 commit comments

Comments
 (0)