From 1e1d3fd7c1d6034e66655c6d53f13ebd60139737 Mon Sep 17 00:00:00 2001 From: Vincent Ritter Date: Fri, 4 Sep 2026 16:28:46 +0200 Subject: [PATCH 1/3] Fix Android post editor losing focus on return. --- .../components/highlighting_text.test.js | 34 +++++++++ src/components/text/editor_html.js | 70 +++++++++++++++++-- src/components/text/highlighting_text.js | 43 +++++++++++- 3 files changed, 141 insertions(+), 6 deletions(-) diff --git a/__tests__/components/highlighting_text.test.js b/__tests__/components/highlighting_text.test.js index 15280356..c2067a3b 100644 --- a/__tests__/components/highlighting_text.test.js +++ b/__tests__/components/highlighting_text.test.js @@ -1,4 +1,6 @@ +import { Platform } from 'react-native' import HighlightingText from '../../src/components/text/highlighting_text' +import editorHtml from '../../src/components/text/editor_html' import App from '../../src/stores/App' jest.mock('../../src/stores/App', () => ({ @@ -24,6 +26,38 @@ jest.mock('../../src/components/keyboard/editor_keyboard_avoiding_view', () => { }) describe('HighlightingText font scaling', () => { + test('requests native WebView focus when focusing the editor', () => { + const requestFocus = jest.fn() + const editor = new HighlightingText({}) + editor.webview = { current: { requestFocus } } + editor.editorConfig = () => ({ editable: true }) + editor.injectJavaScript = jest.fn() + + editor.syncEditor({ focus: true }) + + expect(requestFocus).toHaveBeenCalled() + }) + + test('keeps Android newlines in place instead of rewriting the document', () => { + expect(editorHtml).toContain('insertLineBreakInPlace') + expect(editorHtml).toContain('execCommand("insertLineBreak")') + expect(editorHtml).toMatch(/if \(!insertedNewline\) \{\s*insertLineBreakInPlace\(\)/) + }) + + test('enables the Android keyboard proxy only when autoFocus is set', () => { + const original = Platform.OS + Platform.OS = 'android' + try { + const with_focus = new HighlightingText({ autoFocus: true }) + const without_focus = new HighlightingText({ autoFocus: false }) + expect(with_focus.state.android_focus_proxy).toBe(true) + expect(without_focus.state.android_focus_proxy).toBe(false) + } + finally { + Platform.OS = original + } + }) + test('uses the full system font scale by default', () => { App.font_scale = 3.5 const editor = new HighlightingText({}) diff --git a/src/components/text/editor_html.js b/src/components/text/editor_html.js index 6b29c4dc..69199c28 100644 --- a/src/components/text/editor_html.js +++ b/src/components/text/editor_html.js @@ -194,7 +194,7 @@ const editorHtml = String.raw` -
+