1
0

TextEditors.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. extension BackendFeatures {
  2. /// Backend methods for text editors.
  3. ///
  4. /// These are used by ``TextEditor``.
  5. @MainActor
  6. public protocol TextEditors: TextViews {
  7. /// Creates an editable multi-line text editor.
  8. ///
  9. /// Predominantly used by ``TextEditor``.
  10. ///
  11. /// - Returns: A text editor.
  12. func createTextEditor() -> Widget
  13. /// Sets the placeholder label and change handler of an editable multi-line
  14. /// text editor.
  15. ///
  16. /// The backend shouldn't wait until the user finishes typing to call the
  17. /// change handler; it should allow live access to the value.
  18. ///
  19. /// - Parameters:
  20. /// - textEditor: The text editor to update.
  21. /// - environment: The current environment.
  22. /// - onChange: The action to perform when the text editor's content
  23. /// changes. This replaces any existing change handlers, and is called
  24. /// whenever the displayed value changes.
  25. func updateTextEditor(
  26. _ textEditor: Widget,
  27. environment: EnvironmentValues,
  28. onChange: @escaping (String) -> Void
  29. )
  30. /// Sets the value of an editable multi-line text editor.
  31. ///
  32. /// - Parameters:
  33. /// - textEditor: The text editor to set the content of.
  34. /// - content: The new content.
  35. func setContent(ofTextEditor textEditor: Widget, to content: String)
  36. /// Gets the value of an editable multi-line text editor.
  37. ///
  38. /// - Parameter textEditor: The text editor to get the content of.
  39. /// - Returns: `textEditor`'s content.
  40. func getContent(ofTextEditor textEditor: Widget) -> String
  41. }
  42. }