Skip to content

Commit

Permalink
Refactor FragmentAlt.vue to handle empty and whitespace text inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
dontry committed Feb 18, 2024
1 parent ef4766e commit d21b0b1
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,20 @@ export default {
event.preventDefault();
event.stopPropagation();
// Remove all whitespaces and check if the text is empty
const newText = event.target.innerText.replace(/\s/g, "").trim();
let newText = event.target.innerText.trim();
// if text is empty, we need to replace it with the original condition text
if (newText === "") {
event.target.innerText = conditionTextFromIfElseBlock(this);
return;
}
// if text has empty spaces, we need to wrap it with double quotes
if (newText.includes(" ")) {
newText = newText.replace(/"/g, "");
newText = `"${newText}"`;
}
const condition = conditionFromIfElseBlock(block);
const [start, end] = [condition?.start?.start, condition?.stop?.stop];
updateCode(
Expand Down

0 comments on commit d21b0b1

Please sign in to comment.