Skip to content

Commit de6b323

Browse files
Hide rich text controls on interaction (#5008)
* suppress widget controls for rt in some scenarios * cleanup * more cleanup * lint * remove unneeded method * clear suppresswidgetcontrol flag on breadcrumb click, changelog * whitespace --------- Co-authored-by: Miro Yovchev <2827783+myovchev@users.noreply.github.com>
1 parent d2022f1 commit de6b323

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
### Changes
1111

12-
- Changes handling of `order` and `groups` in the `admin-bar` module to respect, rather that reverse, the order of items
12+
* Changes handling of `order` and `groups` in the `admin-bar` module to respect, rather that reverse, the order of items
13+
* Interacting with the text inside a rich text widget will hide the widget controls to prevent awkawrd text selection.
1314

1415
### Fixes
1516

modules/@apostrophecms/area/ui/apos/components/AposAreaWidget.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
class="apos-area-widget-controls apos-area-widget__label"
2626
:class="labelsClasses"
2727
>
28-
<ol class="apos-area-widget__breadcrumbs">
28+
<ol
29+
@click="isSuppressingWidgetControls = false"
30+
class="apos-area-widget__breadcrumbs"
31+
>
2932
<li
3033
class="
3134
apos-area-widget__breadcrumb
@@ -135,6 +138,7 @@
135138
:doc-id="docId"
136139
:focused="isFocused"
137140
@update="$emit('update', $event)"
141+
@suppress-widget-controls="isSuppressingWidgetControls = true"
138142
/>
139143
<component
140144
:is="widgetComponent(widget.type)"
@@ -285,12 +289,14 @@ export default {
285289
mounted: false, // hack around needing DOM to be rendered for computed classes
286290
isSuppressed: false,
287291
menuOpen: null,
292+
isSuppressingWidgetControls: false,
288293
classes: {
289294
show: 'apos-is-visible',
290295
open: 'apos-is-open',
291296
focus: 'apos-is-focused',
292297
highlight: 'apos-is-highlighted',
293-
adjust: 'apos-is-ui-adjusted'
298+
adjust: 'apos-is-ui-adjusted',
299+
suppressWidgetControls: 'apos-is-suppressing-widget-controls'
294300
},
295301
breadcrumbs: {
296302
$lastEl: null,
@@ -362,7 +368,8 @@ export default {
362368
},
363369
controlsClasses() {
364370
return {
365-
[this.classes.show]: this.isFocused
371+
[this.classes.show]: this.isFocused,
372+
[this.classes.suppressWidgetControls]: this.isSuppressingWidgetControls
366373
};
367374
},
368375
containerClasses() {
@@ -398,6 +405,7 @@ export default {
398405
} else {
399406
this.menuOpen = null;
400407
this.$refs.wrapper.removeEventListener('keydown', this.handleKeyboardUnfocus);
408+
this.isSuppressingWidgetControls = false;
401409
}
402410
}
403411
},
@@ -881,7 +889,7 @@ export default {
881889
}
882890
}
883891
884-
.apos-is-visible,
892+
.apos-is-visible:not(.apos-is-suppressing-widget-controls),
885893
.apos-is-focused {
886894
opacity: 1;
887895
pointer-events: auto;

modules/@apostrophecms/rich-text-widget/ui/apos/components/AposRichTextWidgetEditor.vue

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export default {
193193
default: false
194194
}
195195
},
196-
emits: [ 'update' ],
196+
emits: [ 'update', 'suppressWidgetControls' ],
197197
data() {
198198
return {
199199
editor: null,
@@ -209,6 +209,8 @@ export default {
209209
showPlaceholder: null,
210210
activeInsertMenuComponent: false,
211211
suppressInsertMenu: false,
212+
suppressWidgetControls: false,
213+
hasSelection: false,
212214
insertMenuKey: null,
213215
openedPopover: false
214216
};
@@ -377,8 +379,14 @@ export default {
377379
}
378380
},
379381
watch: {
382+
suppressWidgetControls(newVal) {
383+
if (newVal) {
384+
this.$emit('suppressWidgetControls');
385+
}
386+
},
380387
isFocused(newVal) {
381388
if (!newVal) {
389+
this.suppressWidgetControls = false;
382390
if (this.pending) {
383391
this.emitWidgetUpdate();
384392
}
@@ -463,6 +471,13 @@ export default {
463471
this.$nextTick(() => {
464472
this.showPlaceholder = true;
465473
});
474+
},
475+
onSelectionUpdate: ({ editor }) => {
476+
this.$nextTick(() => {
477+
if (!editor.view.state.selection.empty) {
478+
this.suppressWidgetControls = true;
479+
}
480+
});
466481
}
467482
});
468483
apos.bus.$on('apos-refreshing', this.onAposRefreshing);
@@ -501,6 +516,7 @@ export default {
501516
} else {
502517
this.suppressInsertMenu = false;
503518
}
519+
this.suppressWidgetControls = true;
504520
},
505521
doSuppressInsertMenu() {
506522
this.suppressInsertMenu = true;

0 commit comments

Comments
 (0)