Skip to content

Commit cec5007

Browse files
committed
Remove from configuration and add focus to JS
1 parent 460fb3c commit cec5007

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

ios/Sources/GutenbergKit/Sources/EditorConfiguration.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public struct EditorConfiguration: Sendable {
1616
public let shouldUsePlugins: Bool
1717
/// Toggles visibility of the title field
1818
public let shouldHideTitle: Bool
19-
/// If enabled, the editor automatically becomes focused when initialized
20-
/// with an empty content.
21-
public let shouldAutoFocus: Bool
2219
/// Root URL for the site
2320
public let siteURL: String
2421
/// Root URL for the site API
@@ -45,7 +42,6 @@ public struct EditorConfiguration: Sendable {
4542
shouldUseThemeStyles: Bool,
4643
shouldUsePlugins: Bool,
4744
shouldHideTitle: Bool,
48-
shouldAutoFocus: Bool,
4945
siteURL: String,
5046
siteApiRoot: String,
5147
siteApiNamespace: [String],
@@ -62,7 +58,6 @@ public struct EditorConfiguration: Sendable {
6258
self.shouldUseThemeStyles = shouldUseThemeStyles
6359
self.shouldUsePlugins = shouldUsePlugins
6460
self.shouldHideTitle = shouldHideTitle
65-
self.shouldAutoFocus = shouldAutoFocus
6661
self.siteURL = siteURL
6762
self.siteApiRoot = siteApiRoot
6863
self.siteApiNamespace = siteApiNamespace
@@ -82,7 +77,6 @@ public struct EditorConfiguration: Sendable {
8277
shouldUseThemeStyles: shouldUseThemeStyles,
8378
shouldUsePlugins: shouldUsePlugins,
8479
shouldHideTitle: shouldHideTitle,
85-
shouldAutoFocus: shouldAutoFocus,
8680
siteURL: siteURL,
8781
siteApiRoot: siteApiRoot,
8882
siteApiNamespace: siteApiNamespace,
@@ -113,7 +107,6 @@ public struct EditorConfigurationBuilder {
113107
private var shouldUseThemeStyles: Bool
114108
private var shouldUsePlugins: Bool
115109
private var shouldHideTitle: Bool
116-
private var shouldAutoFocus: Bool
117110
private var siteURL: String
118111
private var siteApiRoot: String
119112
private var siteApiNamespace: [String]
@@ -131,7 +124,6 @@ public struct EditorConfigurationBuilder {
131124
shouldUseThemeStyles: Bool = false,
132125
shouldUsePlugins: Bool = false,
133126
shouldHideTitle: Bool = false,
134-
shouldAutoFocus: Bool = true,
135127
siteURL: String = "",
136128
siteApiRoot: String = "",
137129
siteApiNamespace: [String] = [],
@@ -148,7 +140,6 @@ public struct EditorConfigurationBuilder {
148140
self.shouldUseThemeStyles = shouldUseThemeStyles
149141
self.shouldUsePlugins = shouldUsePlugins
150142
self.shouldHideTitle = shouldHideTitle
151-
self.shouldAutoFocus = shouldAutoFocus
152143
self.siteURL = siteURL
153144
self.siteApiRoot = siteApiRoot
154145
self.siteApiNamespace = siteApiNamespace
@@ -201,12 +192,6 @@ public struct EditorConfigurationBuilder {
201192
return copy
202193
}
203194

204-
public func setShouldAutoFocus(_ shouldAutoFocus: Bool) -> EditorConfigurationBuilder {
205-
var copy = self
206-
copy.shouldAutoFocus = shouldAutoFocus
207-
return copy
208-
}
209-
210195
public func setSiteUrl(_ siteUrl: String) -> EditorConfigurationBuilder {
211196
var copy = self
212197
copy.siteURL = siteUrl
@@ -286,7 +271,6 @@ public struct EditorConfigurationBuilder {
286271
shouldUseThemeStyles: shouldUseThemeStyles,
287272
shouldUsePlugins: shouldUsePlugins,
288273
shouldHideTitle: shouldHideTitle,
289-
shouldAutoFocus: shouldAutoFocus,
290274
siteURL: siteURL,
291275
siteApiRoot: siteApiRoot,
292276
siteApiNamespace: siteApiNamespace,

ios/Sources/GutenbergKit/Sources/EditorViewController.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,11 @@ public final class EditorViewController: UIViewController, GutenbergEditorContro
321321
print("gutenbergkit-measure_editor-first-render:", duration)
322322
delegate?.editorDidLoad(self)
323323

324-
if configuration.shouldAutoFocus, configuration.content.isEmpty {
325-
autoFocusEditor()
324+
if configuration.content.isEmpty {
325+
evaluate("editor.focus();")
326326
}
327327
}
328328

329-
// MARK: - Helpers
330-
331-
private func autoFocusEditor() {
332-
evaluate("""
333-
(function() {
334-
const editable = document.querySelector('[contenteditable="true"]');
335-
if (editable) {
336-
editable.focus();
337-
editable.click();
338-
}
339-
})();
340-
""")
341-
}
342-
343329
// MARK: - Warmup
344330

345331
/// Calls this at any moment before showing the actual editor. The warmup

src/components/editor/use-host-bridge.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ export function useHostBridge( post, editorRef ) {
108108
);
109109
};
110110

111+
window.editor.focus = () => {
112+
const editable = document.querySelector('[contenteditable="true"]');
113+
if (editable) {
114+
editable.focus();
115+
editable.click();
116+
}
117+
};
118+
111119
window.editor.appendTextAtCursor = ( text ) => {
112120
const selectedBlockClientId = getSelectedBlockClientId();
113121

0 commit comments

Comments
 (0)