From c28e4f9d222f4d6981ab8f099cda3d570febe97c Mon Sep 17 00:00:00 2001 From: Micah Date: Mon, 2 Apr 2018 21:28:22 -0500 Subject: [PATCH 1/3] Avoid deleting elements with defined attributes An element shouldn't be considered "empty" if it has attributes. Example: in bootstrap, you might to do something like this: ```html ``` This is an empty element if you're only counting how many children it has, but its attributes are very "full" :) --- src/scripts/text.coffee | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/scripts/text.coffee b/src/scripts/text.coffee index dd02c97..8712d2b 100644 --- a/src/scripts/text.coffee +++ b/src/scripts/text.coffee @@ -40,8 +40,10 @@ class ContentEdit.Text extends ContentEdit.Element if @isMounted() @_syncContent() - if @content.isWhitespace() and @can('remove') - # Detatch element from parent if empty + if @content.isWhitespace() and @can('remove') and + (k for own k in @_attributes).length == 0 + # Detatch element from parent if empty and has no attributes. + if @parent() @parent().detach(this) From 51ece1b8bc8ae0c9c21cb576624e37a1eb31ee9c Mon Sep 17 00:00:00 2001 From: Micah Date: Mon, 2 Apr 2018 21:30:54 -0500 Subject: [PATCH 2/3] comment grammar --- src/scripts/text.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/text.coffee b/src/scripts/text.coffee index 8712d2b..7ca3147 100644 --- a/src/scripts/text.coffee +++ b/src/scripts/text.coffee @@ -42,7 +42,7 @@ class ContentEdit.Text extends ContentEdit.Element if @content.isWhitespace() and @can('remove') and (k for own k in @_attributes).length == 0 - # Detatch element from parent if empty and has no attributes. + # Detatch element from parent if it has neither children nor attributes. if @parent() @parent().detach(this) From 70c247f5a83858b0f5e6b4a04bdb025d16347611 Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 11 Apr 2018 10:31:27 -0500 Subject: [PATCH 3/3] compiles to cleaner javascript --- src/scripts/text.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/text.coffee b/src/scripts/text.coffee index 7ca3147..69b25a6 100644 --- a/src/scripts/text.coffee +++ b/src/scripts/text.coffee @@ -41,7 +41,7 @@ class ContentEdit.Text extends ContentEdit.Element @_syncContent() if @content.isWhitespace() and @can('remove') and - (k for own k in @_attributes).length == 0 + Object.keys(@_attributes).length == 0 # Detatch element from parent if it has neither children nor attributes. if @parent()