MOBILE-4470 rte: Fix rte auto focused on enter

main
Pau Ferrer Ocaña 2024-05-16 14:00:31 +02:00
parent ba72120574
commit 211231a0a8
4 changed files with 8 additions and 5 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -22,7 +22,7 @@ import { CoreDom } from '@singletons/dom';
* Directive to auto focus an element when a view is loaded. * Directive to auto focus an element when a view is loaded.
* *
* The value of the input will decide if show keyboard when focusing the element (only on Android). * The value of the input will decide if show keyboard when focusing the element (only on Android).
* In case value is nofocus, the directive is disabled. * In case value is false, the directive is disabled.
* *
* <ion-input [core-auto-focus]="showKeyboard"> * <ion-input [core-auto-focus]="showKeyboard">
*/ */

View File

@ -435,6 +435,10 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
* @param parent Parent where to set the position. * @param parent Parent where to set the position.
*/ */
protected setCurrentCursorPosition(parent: Node): void { protected setCurrentCursorPosition(parent: Node): void {
if (!this.rteEnabled || !this.element.classList.contains('has-focus')) {
return;
}
const range = document.createRange(); const range = document.createRange();
// Select all so it will go to the end. // Select all so it will go to the end.
@ -600,7 +604,7 @@ export class CoreEditorRichTextEditorComponent implements OnInit, AfterViewInit,
this.control?.setValue(null, { emitEvent: false }); this.control?.setValue(null, { emitEvent: false });
setTimeout(() => { setTimeout(() => {
if (this.rteEnabled && this.editorElement) { if (this.editorElement) {
this.setCurrentCursorPosition(this.editorElement); this.setCurrentCursorPosition(this.editorElement);
} }
}, 1); }, 1);

View File

@ -299,9 +299,6 @@ export class CoreDomUtilsProvider {
async focusElement( async focusElement(
element: HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSearchbarElement | HTMLIonButtonElement | HTMLElement, element: HTMLIonInputElement | HTMLIonTextareaElement | HTMLIonSearchbarElement | HTMLIonButtonElement | HTMLElement,
): Promise<void> { ): Promise<void> {
let retries = 10;
const isIonButton = element.tagName === 'ION-BUTTON';
let elementToFocus = element; let elementToFocus = element;
/** /**
@ -318,6 +315,7 @@ export class CoreDomUtilsProvider {
} }
} }
const isIonButton = element.tagName === 'ION-BUTTON';
if ('getInputElement' in elementToFocus) { if ('getInputElement' in elementToFocus) {
// If it's an Ionic element get the right input to use. // If it's an Ionic element get the right input to use.
elementToFocus.componentOnReady && await elementToFocus.componentOnReady(); elementToFocus.componentOnReady && await elementToFocus.componentOnReady();
@ -332,6 +330,7 @@ export class CoreDomUtilsProvider {
throw new CoreError('Element to focus cannot be focused'); throw new CoreError('Element to focus cannot be focused');
} }
let retries = 10;
while (retries > 0 && elementToFocus !== document.activeElement) { while (retries > 0 && elementToFocus !== document.activeElement) {
elementToFocus.focus(); elementToFocus.focus();