MOBILE-4470 rte: Fix selection being lost on bold and italics

main
Pau Ferrer Ocaña 2024-05-10 11:05:59 +02:00
parent cdcb2f77a6
commit f4697a298a
2 changed files with 13 additions and 18 deletions

View File

@ -23,16 +23,16 @@
<swiper-container #swiperRef [slidesPerView]="swiperOpts.slidesPerView" (slidechangetransitionend)="updateToolbarArrows()">
<!-- https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand -->
<swiper-slide>
<button [disabled]="!rteEnabled" [attr.aria-pressed]="toolbarStyles.strong" [title]="'core.editor.bold' | translate"
(click)="buttonAction($event, 'bold', 'strong')" (keyup)="buttonAction($event, 'bold', 'strong')"
(mousedown)="downAction($event)" (keydown)="downAction($event)" tabindex="0">
<button [disabled]="!rteEnabled" [attr.aria-pressed]="toolbarStyles.strong || toolbarStyles.b"
[title]="'core.editor.bold' | translate" (click)="buttonAction($event, 'bold', 'b')"
(keyup)="buttonAction($event, 'bold', 'b')" (mousedown)="downAction($event)" (keydown)="downAction($event)" tabindex="0">
<ion-icon name="fas-bold" aria-hidden="true" />
</button>
</swiper-slide>
<swiper-slide>
<button [disabled]="!rteEnabled" [attr.aria-pressed]="toolbarStyles.em" [title]="'core.editor.italic' | translate"
(click)="buttonAction($event, 'italic', 'em')" (keyup)="buttonAction($event, 'italic', 'em')"
(mousedown)="downAction($event)" (keydown)="downAction($event)" tabindex="0">
<button [disabled]="!rteEnabled" [attr.aria-pressed]="toolbarStyles.em || toolbarStyles.i"
[title]="'core.editor.italic' | translate" (click)="buttonAction($event, 'italic', 'i')"
(keyup)="buttonAction($event, 'italic', 'i')" (mousedown)="downAction($event)" (keydown)="downAction($event)" tabindex="0">
<ion-icon name="fas-italic" aria-hidden="true" />
</button>
</swiper-slide>
@ -94,13 +94,13 @@
</swiper-slide>
<swiper-slide>
<button [disabled]="!rteEnabled" (click)="buttonAction($event, 'removeFormat')" (keyup)="buttonAction($event, 'removeFormat')"
(mousedown)="downAction($event)" (keydown)="downAction($event)" [title]="'core.editor.clear' | translate">
(mousedown)="downAction($event)" (keydown)="downAction($event)" [title]="'core.editor.clear' | translate" tabindex="0">
<ion-icon name="fas-eraser" aria-hidden="true" />
</button>
</swiper-slide>
<swiper-slide *ngIf="canScanQR">
<button [disabled]="!rteEnabled" (click)="scanQR($event)" (keyup)="scanQR($event)" (mousedown)="stopBubble($event)"
(keydown)="stopBubble($event)" [title]="'core.scanqr' | translate">
(keydown)="stopBubble($event)" [title]="'core.scanqr' | translate" tabindex="0">
<ion-icon name="fas-qrcode" aria-hidden="true" />
</button>
</swiper-slide>

View File

@ -139,7 +139,9 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
infoMessage?: string;
toolbarStyles = {
strong: 'false',
b: 'false',
em: 'false',
i: 'false',
u: 'false',
strike: 'false',
p: 'false',
@ -491,6 +493,9 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
this.stopBubble(event);
// Update tags for a11y.
this.replaceTags(['b', 'i'], ['strong', 'em']);
this.setContent(this.control?.value || '');
this.rteEnabled = !this.rteEnabled;
@ -498,9 +503,6 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
// Set focus and cursor at the end.
// Modify the DOM directly so the keyboard stays open.
if (this.rteEnabled) {
// Update tags for a11y.
this.replaceTags(['b', 'i'], ['strong', 'em']);
this.editorElement?.removeAttribute('hidden');
const textareaInputElement = await this.textarea?.getInputElement();
textareaInputElement?.setAttribute('hidden', '');
@ -679,13 +681,6 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
// eslint-disable-next-line deprecation/deprecation
document.execCommand(command, false);
// Modern browsers are using non a11y tags, so replace them.
if (command === 'bold') {
this.replaceTags(['b'], ['strong']);
} else if (command === 'italic') {
this.replaceTags(['i'], ['em']);
}
}
/**