Skip to content

Commit 77e56f8

Browse files
committed
https://github.com/elmsln/issues/issues/1970
1 parent fefcae9 commit 77e56f8

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

elements/hax-body/hax-body.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
16521652
var content = "";
16531653
for (var i = 0; i < children.length; i++) {
16541654
// some mild front-end sanitization
1655-
if (this._validElementTest(children[i])) {
1655+
if (this._validElementTest(children[i], true)) {
16561656
this.__applyDragDropState(children[i], false);
16571657
// remove some of the protected classes though they shouldn't leak through
16581658
children[i].classList.remove("hax-hovered");
@@ -2959,7 +2959,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
29592959
this.shadowRoot
29602960
) {
29612961
mutations.forEach((mutation) => {
2962-
//move toolbar when active Node is deleted
2962+
// move toolbar when active Node is deleted
29632963
if (mutation.removedNodes.length > 0)
29642964
for (var node of mutation.removedNodes) {
29652965
if (mutation.previousSibling && this.activeNode == node) {
@@ -3098,7 +3098,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
30983098
let grandKids = node.querySelectorAll("*");
30993099
for (var j = 0; j < grandKids.length; j++) {
31003100
// sanity check for being a valid element / not a "hax" element
3101-
if (this._validElementTest(grandKids[j])) {
3101+
if (this._validElementTest(grandKids[j], true)) {
31023102
// correctly add or remove listeners
31033103
this.__applyNodeEditableState(
31043104
grandKids[j],
@@ -3211,7 +3211,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
32113211
if (mutation.addedNodes.length > 0) {
32123212
mutation.addedNodes.forEach((node) => {
32133213
// valid element to apply state to
3214-
if (this._validElementTest(node)) {
3214+
if (this._validElementTest(node, true)) {
32153215
// make it editable / drag/drop capable
32163216
setTimeout(() => {
32173217
this.__applyNodeEditableState(node, this.editMode);
@@ -3256,7 +3256,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
32563256
* true means its a valid element for selection
32573257
* We have special support for the hax-logo because it's hax.
32583258
*/
3259-
_validElementTest(node) {
3259+
_validElementTest(node, allowInline = false) {
32603260
// ignore hax internal tags
32613261
// search results can be drag'ed from their panel for exact placement
32623262
// special place holder in drag and drop
@@ -3269,6 +3269,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
32693269
// being the thing that should grad actual block level focus
32703270
// this would be like a B or I tag grabbing focus as well
32713271
if (
3272+
!allowInline &&
32723273
this._HTMLInlineTextDecorationTest(node) &&
32733274
node.parentNode != "HAX-BODY"
32743275
) {
@@ -3317,7 +3318,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
33173318
}
33183319
for (var i = 0; i < children.length; i++) {
33193320
// sanity check for being a valid element / not a "hax" element
3320-
if (this._validElementTest(children[i])) {
3321+
if (this._validElementTest(children[i], true)) {
33213322
// correctly add or remove listeners
33223323
if (
33233324
!status ||
@@ -3335,7 +3336,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
33353336
let grandKids = children[i].querySelectorAll("*");
33363337
for (var j = 0; j < grandKids.length; j++) {
33373338
// sanity check for being a valid element / not a "hax" element
3338-
if (this._validElementTest(grandKids[j])) {
3339+
if (this._validElementTest(grandKids[j], true)) {
33393340
// correctly add or remove listeners
33403341
this.__applyNodeEditableState(grandKids[j], status);
33413342
}

elements/hax-body/lib/hax-store.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,13 @@ class HaxStore extends I18NMixin(winEventsElement(HAXElement(LitElement))) {
12701270
}
12711271
}
12721272
}
1273+
1274+
// normalize this functionality with what we preovide in the View Source based method
1275+
_onCommand(e) {
1276+
if (e.detail.command && e.detail.command === "removeFormat") {
1277+
this.activeNode.innerHTML = stripMSWord(this.activeNode.innerHTML);
1278+
}
1279+
}
12731280
/**
12741281
* Intercept paste event and clean it up before inserting the contents
12751282
*/
@@ -2000,6 +2007,7 @@ class HaxStore extends I18NMixin(winEventsElement(HAXElement(LitElement))) {
20002007
"hax-consent-tap": "_haxConsentTap",
20012008
onbeforeunload: "_onBeforeUnload",
20022009
paste: "_onPaste",
2010+
command: "_onCommand",
20032011
"hax-register-app": "_haxStoreRegisterApp",
20042012
"hax-register-stax": "_haxStoreRegisterStax",
20052013
"hax-register-core-piece": "_haxStorePieceRegistrationManager",

elements/hax-body/src/hax-body.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,7 +1652,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
16521652
var content = "";
16531653
for (var i = 0; i < children.length; i++) {
16541654
// some mild front-end sanitization
1655-
if (this._validElementTest(children[i])) {
1655+
if (this._validElementTest(children[i], true)) {
16561656
this.__applyDragDropState(children[i], false);
16571657
// remove some of the protected classes though they shouldn't leak through
16581658
children[i].classList.remove("hax-hovered");
@@ -2959,7 +2959,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
29592959
this.shadowRoot
29602960
) {
29612961
mutations.forEach((mutation) => {
2962-
//move toolbar when active Node is deleted
2962+
// move toolbar when active Node is deleted
29632963
if (mutation.removedNodes.length > 0)
29642964
for (var node of mutation.removedNodes) {
29652965
if (mutation.previousSibling && this.activeNode == node) {
@@ -3098,7 +3098,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
30983098
let grandKids = node.querySelectorAll("*");
30993099
for (var j = 0; j < grandKids.length; j++) {
31003100
// sanity check for being a valid element / not a "hax" element
3101-
if (this._validElementTest(grandKids[j])) {
3101+
if (this._validElementTest(grandKids[j], true)) {
31023102
// correctly add or remove listeners
31033103
this.__applyNodeEditableState(
31043104
grandKids[j],
@@ -3211,7 +3211,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
32113211
if (mutation.addedNodes.length > 0) {
32123212
mutation.addedNodes.forEach((node) => {
32133213
// valid element to apply state to
3214-
if (this._validElementTest(node)) {
3214+
if (this._validElementTest(node, true)) {
32153215
// make it editable / drag/drop capable
32163216
setTimeout(() => {
32173217
this.__applyNodeEditableState(node, this.editMode);
@@ -3256,7 +3256,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
32563256
* true means its a valid element for selection
32573257
* We have special support for the hax-logo because it's hax.
32583258
*/
3259-
_validElementTest(node) {
3259+
_validElementTest(node, allowInline = false) {
32603260
// ignore hax internal tags
32613261
// search results can be drag'ed from their panel for exact placement
32623262
// special place holder in drag and drop
@@ -3269,6 +3269,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
32693269
// being the thing that should grad actual block level focus
32703270
// this would be like a B or I tag grabbing focus as well
32713271
if (
3272+
!allowInline &&
32723273
this._HTMLInlineTextDecorationTest(node) &&
32733274
node.parentNode != "HAX-BODY"
32743275
) {
@@ -3317,7 +3318,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
33173318
}
33183319
for (var i = 0; i < children.length; i++) {
33193320
// sanity check for being a valid element / not a "hax" element
3320-
if (this._validElementTest(children[i])) {
3321+
if (this._validElementTest(children[i], true)) {
33213322
// correctly add or remove listeners
33223323
if (
33233324
!status ||
@@ -3335,7 +3336,7 @@ class HaxBody extends I18NMixin(UndoManagerBehaviors(SimpleColors)) {
33353336
let grandKids = children[i].querySelectorAll("*");
33363337
for (var j = 0; j < grandKids.length; j++) {
33373338
// sanity check for being a valid element / not a "hax" element
3338-
if (this._validElementTest(grandKids[j])) {
3339+
if (this._validElementTest(grandKids[j], true)) {
33393340
// correctly add or remove listeners
33403341
this.__applyNodeEditableState(grandKids[j], status);
33413342
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
<page-section>
2-
<h2>Cool stuff!</h2>
3-
</page-section>
4-
<page-section>
5-
<h2>Cool stuff!</h2>
6-
</page-section>
7-
<page-section anchor="Some place">
8-
<h2>Cool stuff!</h2>
9-
</page-section>
10-
<page-section>
11-
<h2>Cool stuff!</h2>
12-
</page-section>
13-
<page-section>
14-
<h2>Cool stuff!</h2>
15-
</page-section>
1+
<p><span>I CANNOT BE EDITED I AM IN CHARGE</span></p>
2+
<p>2<span>I CANNOT BE EDITED I AM IN CHARGE</span></p>
3+
<p>I am a friendly p tag</p>

0 commit comments

Comments
 (0)