diff --git a/ApiTestManager/src/components/EditableInput.js b/ApiTestManager/src/components/EditableInput.js index 54548d1..dda21df 100644 --- a/ApiTestManager/src/components/EditableInput.js +++ b/ApiTestManager/src/components/EditableInput.js @@ -1,4 +1,7 @@ +// const ZERO_WIDTH_SPACE = '​'; +const ZERO_WIDTH_SPACE = '​'; class EditableInputModel { + constructor(value = '') { this.value = value; } @@ -26,7 +29,7 @@ class EditableInputView { } generateInputHtml() { - let contentHtml = this.model.getValue() ? this.renderContent(this.parseContent(this.model.getValue())) : '​'; + let contentHtml = this.model.getValue() ? this.renderContent(this.parseContent(this.model.getValue())) : ZERO_WIDTH_SPACE; return `
${contentHtml} @@ -48,7 +51,7 @@ class EditableInputView { if (content) { this.editableDiv.innerHTML = this.renderContent(this.parseContent(content)); } else { - this.editableDiv.innerHTML = '​'; // Insert a zero-width space + this.editableDiv.innerHTML = ZERO_WIDTH_SPACE; // Insert a zero-width space } this.editableDiv.setAttribute('data-value', content); @@ -57,6 +60,7 @@ class EditableInputView { renderContent(contentArray) { let content = ''; contentArray.forEach((item) => { + if (item.startsWith('{{') && item.endsWith('}}')) { content += `${item}`; } else { @@ -118,6 +122,10 @@ class EditableInputController { } handleInput(editableDiv) { + // Check and remove zero-width space if it's the only content + if (editableDiv.innerHTML === '​') { + editableDiv.innerHTML = ''; + } let cursor = this.getCurrentCursor(editableDiv); let mergedString = Array.from(editableDiv.childNodes) @@ -130,7 +138,10 @@ class EditableInputController { }) .join(''); - let content = this.parseContent(mergedString); + var result = mergedString.replace(/[\u200B-\u200D\uFEFF]/g, ''); + + let content = this.parseContent(result); + this.model.setValue(content.join('')); // Optionally, update the view if needed this.view.updateUI();