feat: 添加输入框编辑索引管理,优化输入文本分发逻辑
This commit is contained in:
@@ -40,7 +40,7 @@ Git 历史采用 Conventional Commits,且摘要多为中文,例如 `feat:
|
|||||||
<claude-mem-context>
|
<claude-mem-context>
|
||||||
# Memory Context
|
# Memory Context
|
||||||
|
|
||||||
# $CMEM mp-xieyingeng 2026-05-13 8:06am GMT+8
|
# $CMEM mp-xieyingeng 2026-05-13 8:12am GMT+8
|
||||||
|
|
||||||
Legend: 🎯session 🔴bugfix 🟣feature 🔄refactor ✅change 🔵discovery ⚖️decision
|
Legend: 🎯session 🔴bugfix 🟣feature 🔄refactor ✅change 🔵discovery ⚖️decision
|
||||||
Format: ID TIME TYPE TITLE
|
Format: ID TIME TYPE TITLE
|
||||||
|
|||||||
@@ -234,6 +234,9 @@ export class PageLevel extends BaseView {
|
|||||||
/** 最近一次自动提交的答案,避免填满后重复提交同一内容 */
|
/** 最近一次自动提交的答案,避免填满后重复提交同一内容 */
|
||||||
private _lastAutoSubmittedAnswer: string = '';
|
private _lastAutoSubmittedAnswer: string = '';
|
||||||
|
|
||||||
|
/** 当前正在编辑的输入格索引 */
|
||||||
|
private _editingInputIndex: number = -1;
|
||||||
|
|
||||||
/** 倒计时剩余秒数 */
|
/** 倒计时剩余秒数 */
|
||||||
private _countdown: number = 60;
|
private _countdown: number = 60;
|
||||||
|
|
||||||
@@ -659,28 +662,13 @@ export class PageLevel extends BaseView {
|
|||||||
|
|
||||||
// ========== EditBox 事件回调 ==========
|
// ========== EditBox 事件回调 ==========
|
||||||
|
|
||||||
/**
|
|
||||||
* 输入框开始编辑时,把当前所有格子的内容合并到当前输入框里
|
|
||||||
*/
|
|
||||||
private onInputEditingBegan(editBox: EditBox): void {
|
private onInputEditingBegan(editBox: EditBox): void {
|
||||||
if (this._isSyncingInputText) return;
|
if (this._isSyncingInputText) return;
|
||||||
|
|
||||||
const inputIndex = this._inputNodes.findIndex(node => node === editBox.node);
|
const inputIndex = this._inputNodes.findIndex(node => node === editBox.node);
|
||||||
if (inputIndex < 0) return;
|
if (inputIndex < 0) return;
|
||||||
|
|
||||||
const answer = this.getAnswer();
|
this._editingInputIndex = inputIndex;
|
||||||
this._isSyncingInputText = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
for (let i = 0; i < this._inputNodes.length; i++) {
|
|
||||||
const itemEditBox = this._inputNodes[i].getComponent(EditBox);
|
|
||||||
if (itemEditBox) {
|
|
||||||
itemEditBox.string = i === inputIndex ? answer : '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
this._isSyncingInputText = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -696,22 +684,48 @@ export class PageLevel extends BaseView {
|
|||||||
private onInputEditingEnded(editBox: EditBox): void {
|
private onInputEditingEnded(editBox: EditBox): void {
|
||||||
if (this._isSyncingInputText) return;
|
if (this._isSyncingInputText) return;
|
||||||
|
|
||||||
const inputIndex = this._inputNodes.findIndex(node => node === editBox.node);
|
const inputIndex = this._editingInputIndex >= 0
|
||||||
|
? this._editingInputIndex
|
||||||
|
: this._inputNodes.findIndex(node => node === editBox.node);
|
||||||
if (inputIndex < 0) return;
|
if (inputIndex < 0) return;
|
||||||
|
|
||||||
this.distributeInputText(editBox.string);
|
this.applyInputTextToBlocks(editBox.string, inputIndex);
|
||||||
|
this._editingInputIndex = -1;
|
||||||
this.tryAutoSubmitAnswer();
|
this.tryAutoSubmitAnswer();
|
||||||
}
|
}
|
||||||
|
|
||||||
private distributeInputText(text: string): void {
|
private applyInputTextToBlocks(text: string, inputIndex: number): void {
|
||||||
const chars = Array.from(text);
|
const chars = Array.from(text.trim());
|
||||||
|
if (chars.length <= 1) {
|
||||||
|
this.setInputBlockText(inputIndex, chars[0] ?? '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.distributeInputText(text, inputIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private setInputBlockText(index: number, text: string): void {
|
||||||
|
const editBox = this._inputNodes[index]?.getComponent(EditBox);
|
||||||
|
if (!editBox) return;
|
||||||
|
|
||||||
|
this._isSyncingInputText = true;
|
||||||
|
try {
|
||||||
|
editBox.string = Array.from(text.trim())[0] ?? '';
|
||||||
|
} finally {
|
||||||
|
this._isSyncingInputText = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private distributeInputText(text: string, startIndex: number = 0): void {
|
||||||
|
const chars = Array.from(text.trim());
|
||||||
|
const safeStartIndex = Math.max(0, Math.min(startIndex, this._inputNodes.length - 1));
|
||||||
this._isSyncingInputText = true;
|
this._isSyncingInputText = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (let i = 0; i < this._inputNodes.length; i++) {
|
for (let i = safeStartIndex; i < this._inputNodes.length; i++) {
|
||||||
const editBox = this._inputNodes[i].getComponent(EditBox);
|
const editBox = this._inputNodes[i].getComponent(EditBox);
|
||||||
if (editBox) {
|
if (editBox) {
|
||||||
editBox.string = chars[i] ?? '';
|
editBox.string = chars[i - safeStartIndex] ?? '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -752,6 +766,10 @@ export class PageLevel extends BaseView {
|
|||||||
this.onSubmitAnswer();
|
this.onSubmitAnswer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private normalizeAnswerForCompare(answer: string): string {
|
||||||
|
return answer.trim().toLocaleLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
// ========== IconSetting 按钮相关 ==========
|
// ========== IconSetting 按钮相关 ==========
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1741,7 +1759,7 @@ export class PageLevel extends BaseView {
|
|||||||
const userAnswer = this.getAnswer();
|
const userAnswer = this.getAnswer();
|
||||||
console.log(`[PageLevel] 提交答案: ${userAnswer}, 正确答案: ${this._currentConfig.answer}`);
|
console.log(`[PageLevel] 提交答案: ${userAnswer}, 正确答案: ${this._currentConfig.answer}`);
|
||||||
|
|
||||||
if (userAnswer === this._currentConfig.answer) {
|
if (this.normalizeAnswerForCompare(userAnswer) === this.normalizeAnswerForCompare(this._currentConfig.answer)) {
|
||||||
if (this._isShareMode) {
|
if (this._isShareMode) {
|
||||||
this._recordCurrentShareSubmission(userAnswer);
|
this._recordCurrentShareSubmission(userAnswer);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user