Zero Width Space 처리 수정
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
|
// const ZERO_WIDTH_SPACE = '​';
|
||||||
|
const ZERO_WIDTH_SPACE = '​';
|
||||||
class EditableInputModel {
|
class EditableInputModel {
|
||||||
|
|
||||||
constructor(value = '') {
|
constructor(value = '') {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@@ -26,7 +29,7 @@ class EditableInputView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
generateInputHtml() {
|
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 `
|
return `
|
||||||
<div contenteditable="true" class="editableInputContent form-control" data-value="${this.model.getValue()}">
|
<div contenteditable="true" class="editableInputContent form-control" data-value="${this.model.getValue()}">
|
||||||
${contentHtml}
|
${contentHtml}
|
||||||
@@ -48,7 +51,7 @@ class EditableInputView {
|
|||||||
if (content) {
|
if (content) {
|
||||||
this.editableDiv.innerHTML = this.renderContent(this.parseContent(content));
|
this.editableDiv.innerHTML = this.renderContent(this.parseContent(content));
|
||||||
} else {
|
} 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);
|
this.editableDiv.setAttribute('data-value', content);
|
||||||
@@ -57,6 +60,7 @@ class EditableInputView {
|
|||||||
renderContent(contentArray) {
|
renderContent(contentArray) {
|
||||||
let content = '';
|
let content = '';
|
||||||
contentArray.forEach((item) => {
|
contentArray.forEach((item) => {
|
||||||
|
|
||||||
if (item.startsWith('{{') && item.endsWith('}}')) {
|
if (item.startsWith('{{') && item.endsWith('}}')) {
|
||||||
content += `<span class="variable">${item}</span>`;
|
content += `<span class="variable">${item}</span>`;
|
||||||
} else {
|
} else {
|
||||||
@@ -118,6 +122,10 @@ class EditableInputController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleInput(editableDiv) {
|
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 cursor = this.getCurrentCursor(editableDiv);
|
||||||
let mergedString = Array.from(editableDiv.childNodes)
|
let mergedString = Array.from(editableDiv.childNodes)
|
||||||
@@ -130,7 +138,10 @@ class EditableInputController {
|
|||||||
})
|
})
|
||||||
.join('');
|
.join('');
|
||||||
|
|
||||||
let content = this.parseContent(mergedString);
|
var result = mergedString.replace(/[\u200B-\u200D\uFEFF]/g, '');
|
||||||
|
|
||||||
|
let content = this.parseContent(result);
|
||||||
|
|
||||||
this.model.setValue(content.join(''));
|
this.model.setValue(content.join(''));
|
||||||
// Optionally, update the view if needed
|
// Optionally, update the view if needed
|
||||||
this.view.updateUI();
|
this.view.updateUI();
|
||||||
|
|||||||
Reference in New Issue
Block a user