### Installation Directory Setup Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_chat/windows/CMakeLists.txt Sets up installation directories, ensuring support files are placed next to the executable for in-place running. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Installation Bundle Directory Setup Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_perf/linux/CMakeLists.txt Configures the installation prefix to create a relocatable bundle in the build directory and sets up data and library directories within the bundle. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Configure Visual Studio Installation Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example/windows/CMakeLists.txt Sets up installation directories and makes the 'install' step default for Visual Studio builds, allowing in-place execution. ```cmake set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Run Super Editor Example App Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/README.md Navigate to the example directory and run the Flutter app to see Super Editor in action. This command is used to build and run the example implementation on macOS. ```bash cd example flutter run -d macos ``` -------------------------------- ### Install Executable and Data Files Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_perf/linux/CMakeLists.txt Installs the application executable, ICU data file, and the Flutter library to their respective destinations within the installation bundle. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Define Installation Directories Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_perf/windows/CMakeLists.txt Sets variables for the installation directories of data and libraries within the bundle. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Installation Target for Executable Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/CMakeLists.txt Installs the main application executable to the runtime destination directory. This is part of setting up the deployable artifact. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Defining Installation Directories Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Sets variables for the installation directories within the bundle for data and libraries. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Installs Flutter assets to the application bundle data directory. Ensures any previous installation is removed first. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install( CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installing Bundled Plugin Libraries Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Iterates through a list of bundled libraries (likely from plugins) and installs each to the library directory within the bundle. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Install Native Assets Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_chat/windows/CMakeLists.txt Installs native assets provided by build.dart to the library directory. ```cmake # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installation of AOT Library Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library for Profile and Release builds. This is used for performance optimization. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Minimal Super Editor Setup Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/getting-started/quickstart.md This Dart code demonstrates the minimal setup for a Super Editor experience by creating an Editor and wrapping it in a SuperEditor widget. ```dart class MyApp extends StatefulWidget { State createState() => _MyApp(); } class _MyApp extends State { late final Editor _editor; void initState() { super.initState(); _editor = createDefaultDocumentEditor( document: MutableDocument.empty(), composer: MutableDocumentComposer(), ); } void dispose() { _editor.dispose(); super.dispose(); } Widget build(BuildContext context) { return SuperEditor( editor: _editor, ); } } ``` -------------------------------- ### Setting Installation Prefix and Bundle Directory Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Configures the installation prefix to a build bundle directory and ensures it's initialized to default if not already set. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Installation of Bundled Plugin Libraries Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/CMakeLists.txt Installs any bundled native libraries required by plugins. This ensures that plugins have their necessary dependencies available at runtime. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Project and Executable Setup Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_chat/windows/CMakeLists.txt Sets the minimum CMake version and defines the project name and the executable's on-disk name. ```cmake cmake_minimum_required(VERSION 3.14) project(example_chat LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "example_chat") ``` -------------------------------- ### Installing Native Assets Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Installs native assets provided by build.dart from all packages into the library directory of the bundle. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Cleaning Build Bundle Directory on Install Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Installs a code that removes the build bundle directory before installation to ensure a clean state. ```cmake install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) ``` -------------------------------- ### Installation of Flutter Assets Directory Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/CMakeLists.txt Configures the installation of the Flutter assets directory. It first removes any existing directory to ensure a clean copy, then copies the new assets. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_chat/windows/CMakeLists.txt Installs the Flutter assets directory, ensuring it's re-copied on each build to avoid stale files. ```cmake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Set Installation Prefix for Bundled App Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_perf/windows/CMakeLists.txt Configures the installation prefix to be next to the executable for in-place running, especially for Visual Studio builds. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Installation of Flutter Library Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/CMakeLists.txt Installs the main Flutter library file to the library directory within the application bundle. This is a core component for the Flutter engine. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installation of Native Assets Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/CMakeLists.txt Installs native assets provided by the build process into the application's library directory. These assets are typically platform-specific resources. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Code Block Example Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/dev/style-guide.md Demonstrates a basic code block. Use this for displaying code snippets. ```markdown A code block ``` -------------------------------- ### Install AOT Library Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_chat/windows/CMakeLists.txt Installs the AOT (Ahead-Of-Time compilation) library on non-Debug builds (Profile and Release). ```cmake # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Initialize Quill Editor with Toolbar Options Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/quill/quill_js/index.html Configure the Quill editor with a custom toolbar. This example sets up a snow theme and enables syntax highlighting. ```javascript const toolbarOptions = [ ['bold', 'italic', 'underline', 'strike'], // toggled buttons ['blockquote', 'code-block'], ['link', 'image', 'video', 'formula'], [{ 'header': 1 }, { 'header': 2 }], // custom button values [{ 'list': 'ordered'}, { 'list': 'bullet' }, { 'list': 'check' }], [{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript [{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent [{ 'direction': 'rtl' }], // text direction [{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown [{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme [{ 'font': [] }], [{ 'align': [] }], ['clean'] // remove formatting button ]; const quill = new Quill('#editor', { theme: 'snow', modules: { syntax: true, toolbar: toolbarOptions } }); ``` -------------------------------- ### Install AOT Library (Non-Debug) Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the application bundle library directory. This is only performed for non-Debug build types. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Basic SuperEditor Setup Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/viewport/auto-scrolling.md This code demonstrates the fundamental integration of SuperEditor within a Flutter widget tree. Ensure you provide a stylesheet for proper editor styling. ```dart class _MyAppState extends State { Stylesheet _stylesheet = _lightStylesheet; Widget build(BuildContext context) { return SuperEditor( stylesheet: _stylesheet, // ...other properties ); } } ``` -------------------------------- ### Functional Command in v0.2.x Source: https://github.com/flutter-bounty-hunters/super_editor/wiki/Migration-Guide:-Super-Editor--=-0.2.x-to-Super-Editor-0.3.0 An example of a functional command in v0.2.x, using a lambda to execute command behavior. ```dart editor.executeCommand( EditorCommandFunction( (doc, transaction) { // command behavior here }, ), ); ``` -------------------------------- ### Display Standard Editor Source: https://github.com/flutter-bounty-hunters/super_editor/wiki/How-to:-display-an-editor Use `Editor.standard` to display an editor with default behavior and rendering. Ensure a `DocumentEditor` is created once, for example, in `initState()`. ```dart // Create a DocumentEditor in initState() or some other location // that only runs once. final documentEditor = DocumentEditor(document: doc); // In a build() method, create the Editor widget. return Editor.standard( editor: documentEditor, showDebugPaint: showDebugPaint, // Optional: true to paint debug style UI, false otherwise ); ``` -------------------------------- ### Installation of ICU Data File Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/CMakeLists.txt Installs the ICU data file to the data directory within the application bundle. This file is necessary for internationalization support. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Setting Installation RPATH Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Configures the RPATH to load bundled libraries from the lib/ directory relative to the binary. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Configure FollowerAligner Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/editing-ui/add-a-popover-toolbar.md Create a FollowerAligner, such as CupertinoPopoverToolbarAligner, to define how the toolbar should align with the selected content. This example places the toolbar above the content by default. ```dart class MyAppState extends State { // ... late final FollowerAligner _toolbarAligner; // ... @override void initState() { super.initState(); // Place the toolbar above the content by default. _toolbarAligner = CupertinoPopoverToolbarAligner(_viewportKey); }; // ... } ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example/windows/CMakeLists.txt Specifies the minimum required CMake version and the project name. This is a standard CMake setup. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) ``` -------------------------------- ### Configure SuperEditor in v0.2.x Source: https://github.com/flutter-bounty-hunters/super_editor/wiki/Migration-Guide:-Super-Editor--=-0.2.x-to-Super-Editor-0.3.0 In v0.2.x, SuperEditor only required a DocumentEditor. This snippet shows the basic setup. ```dart void initState() { super.initState(); _myDocument = createDocument(); _myEditor = DocumentEditor(document: _myDocument); } Widget build(BuildContext context) { return SuperEditor( editor: _myEditor, ); } ``` -------------------------------- ### Access SuperKeyboard Singleton Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_keyboard/doc/website/source/guides/unified-api.md Get the singleton instance of SuperKeyboard to access its unified API from anywhere in your application. ```dart final superKeyboard = SuperKeyboard.instance; ``` -------------------------------- ### Display Plain Text Editor Source: https://github.com/flutter-bounty-hunters/super_editor/wiki/How-to:-display-an-editor Use `Editor.custom` to display an editor with custom styling and component builders. This example forces all text to have the same style and displays placeholder boxes for non-paragraph nodes. ```dart final documentEditor = DocumentEditor(document: doc); return Editor.custom( editor: documentEditor, textStyleBuilder: (attributions) { // Force all text to look the same, regardless of attributions. return TextStyle( color: Colors.black, fontSize: 13, fontWeight: FontWeight.normal, ); }, componentBuilders: [ (ComponentContext componentContext) { if (componentContext.currentNode is ParagraphNode) { return paragraphBuilder(componentContext); } else { // Display a placeholder box for all nodes other than // ParagraphNodes return UnknownComponent(); } } ], showDebugPaint: showDebugPaint, ); ``` -------------------------------- ### Configure Windows Runner Executable Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example/windows/runner/CMakeLists.txt Defines the main executable for the Windows runner, including all necessary source files and resources. This setup is specific to Windows builds. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Implement Custom Block Delta Format Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/quill/import.md Implement `BlockDeltaFormat` to define how custom block Delta formats are parsed into Super Editor requests. This example shows parsing a hypothetical video block. ```dart class VideoBlockFormat implements BlockDeltaFormat { const VideoBlockFormat(); @override List? applyTo(Operation operation, Editor editor) { // Pull out the data based on your custom video Delta format... if (!operation.hasAttribute('video')) { return null; } final videoUrl = operation['video']; if (videoUrl is! String) { return null; } // This example assumes that your editor supports a `InsertVideoRequest`. editor.executeRequests([ InsertVideoRequest(videoUrl), ]); } } ``` -------------------------------- ### Detect Keyboard Visibility with Window Insets Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_keyboard/doc/website/source/guides/android.md Use `onApplyWindowInsets` to detect when the keyboard starts opening or closing by checking `insets.isVisible(WindowInsetsCompat.Type.ime())`. This method is called when window insets change. ```kotlin override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat { val imeVisible = insets.isVisible(WindowInsetsCompat.Type.ime()) // Note: We only identify opening/closing here. The opened/closed completion // is identified by the window insets animation callback. if (imeVisible && keyboardState != KeyboardState.Opening && keyboardState != KeyboardState.Open) { channel.invokeMethod("keyboardOpening", null) keyboardState = KeyboardState.Opening } else if (!imeVisible && keyboardState != KeyboardState.Closing && keyboardState != KeyboardState.Closed) { channel.invokeMethod("keyboardClosing", null) keyboardState = KeyboardState.Closing } return insets } ``` -------------------------------- ### Create Custom Stylesheet with Green Headers Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/styling/style-a-document.md Define a custom stylesheet by copying the default and adding rules. This example makes all level one headers green. Provide this stylesheet to the `SuperEditor` widget. ```dart const myStyleSheet = defaultStylesheet.copyWith( addRulesAfter: [ StyleRule( // Matches all level one headers. const BlockSelector("header1"), (document, node) { return { Styles.textStyle: const TextStyle(color: Colors.green), }; }, ), ], ); ``` ```dart class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return SuperEditor( // ... stylesheet: myStyleSheet, ); } } ``` -------------------------------- ### Configure Flutter library and headers Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/flutter/CMakeLists.txt Defines the Flutter library path and headers, and sets them to be available in the parent scope for installation steps. It also defines project build directory and AOT library path. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` -------------------------------- ### Merge Multiple Styles for Header Font Size Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/styling/style-a-document.md Demonstrates how multiple `StyleRule`s can match a single node and how their styles are merged. This example applies green color to level one headers and sets a default font size of 14px to all nodes. ```dart const myStyleSheet = defaultStylesheet.copyWith( addRulesAfter: [ StyleRule( // Matches all level one headers. const BlockSelector("header1"), (document, node) { return { Styles.textStyle: const TextStyle(color: Colors.green), }; }, ), StyleRule( // Matches all nodes. BlockSelector.all, (document, node) { return { Styles.textStyle: const TextStyle(fontSize: 14), }; }, ) ], ); ``` -------------------------------- ### Initialize Super Editor Components Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/README.md Set up the `MutableDocument`, `MutableComposer`, and `Editor` required by `SuperEditor`. The `MutableDocument` holds the content, `MutableComposer` manages the user's selection, and `Editor` applies changes to the document. ```dart class _MyAppState extends State { late final MutableDocument _document; late final MutableComposer _composer; late final Editor _editor; @override void initState() { super.initState(); // A MutableDocument is an in-memory Document. Create the starting // content that you want your editor to display. // // To start with an empty document, create a MutableDocument with a // single ParagraphNode that holds an empty string. _document = MutableDocument( nodes: [ ParagraphNode( id: DocumentEditor.createNodeId(), text: AttributedText('This is a header'), metadata: { 'blockType': header1Attribution, }, ), ParagraphNode( id: DocumentEditor.createNodeId(), text: AttributedText('This is the first paragraph'), ), ], ); // A DocumentComposer holds the user's selection. Your editor will likely want // to observe, and possibly change the user's selection. Therefore, you should // hold onto your own DocumentComposer and pass it to your Editor. _composer = MutableDocumentComposer(); // With a MutableDocument, create an Editor, which knows how to apply changes // to the MutableDocument. _editor = createDefaultDocumentEditor(document: _document, composer: _composer); } void build(context) { return SuperEditor( document: _document, composer: _composer, editor: _editor, ); } } ``` -------------------------------- ### Export Flutter Library Path Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example/windows/flutter/CMakeLists.txt Exports the FLUTTER_LIBRARY variable to the parent scope, making it available for installation targets. This ensures the correct library path is used during installation. ```cmake set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) ``` -------------------------------- ### Add Dependency Libraries and Include Directories Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and adds include directories for the target. Application-specific dependencies should also be added here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) ``` ```cmake target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") ``` ```cmake target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Find and check PkgConfig modules for GTK, GLIB, and GIO Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/flutter/CMakeLists.txt This snippet uses PkgConfig to find and check for the required GTK, GLIB, and GIO libraries. These are system-level dependencies for Flutter's Linux backend. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Add Super Editor Dependency (Dev Preview) Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/getting-started/quickstart.md Add this YAML configuration to use the latest dev preview build of Super Editor from Pub. Check pub.dev for the latest version. ```yaml dependencies: super_editor: 0.3.0-dev.23 ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/windows/runner/CMakeLists.txt Applies a standard set of build settings to the specified target. This can be removed if custom build settings are required. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example/windows/flutter/CMakeLists.txt Specifies the minimum version of CMake required for this project. Ensure your CMake installation meets this requirement. ```cmake cmake_minimum_required(VERSION 3.14) ``` -------------------------------- ### Cross-building Sysroot Configuration Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Configures sysroot and find root path settings for cross-compilation environments. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Configure Flutter Tool Backend Custom Command Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_chat/windows/flutter/CMakeLists.txt Sets up a custom command to run the Flutter tool backend, generating necessary build artifacts like the Flutter library and headers. A phony output file is used to ensure execution. ```cmake # === Flutter tool backend === # _phony_ is a non-existent file to force this command to run every time, # since currently there's no way to get a full input/output list from the # flutter tool. set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) ``` -------------------------------- ### Serialize Document to Markdown Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/markdown/export.md Call the `serializeDocumentToMarkdown` function with your Super Editor document to get its Markdown representation. This uses the default `MarkdownSyntax.superEditor`. ```dart final markdown = serializeDocumentToMarkdown(superEditorDocument); ``` -------------------------------- ### Serialize Document with Custom Node Converters Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/markdown/export.md Provide a list of `customNodeSerializers` to control how specific `DocumentNode` types are converted to Markdown. This example includes a `TableNodeToMarkdownConverter`. ```dart final markdown = serializeDocumentToMarkdown( superEditorDocument, syntax: [ const TableNodeToMarkdownConverter(), ], ); ``` -------------------------------- ### Implement Custom Inline Embed Delta Format Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/quill/import.md Implement `InlineEmbedFormat` to handle custom inline embeds. This example shows parsing an inline bitmap image. ```dart class InlineImageFormat implements InlineEmbedFormat { @override bool insert(Editor editor, DocumentComposer composer, Map embed) { // Pull out the data based on your custom Delta inline image format... final url = embed['image']; if (url is! String) { return false; } // TODO: take whatever action you'd like with the inline image URL. return true; } } ``` -------------------------------- ### Finding PkgConfig and GTK Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Finds the PkgConfig module and checks for the gtk+-3.0 package, making its imported target available. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) ``` -------------------------------- ### Run All Golden Tests with Script Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/README_GOLDEN_TESTS.md Execute a verification script to run all golden tests. This script automates the process of testing goldens within the project's environment. ```bash ./test_goldens_verify.sh ``` -------------------------------- ### Add follow_the_leader dependency Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/editing-ui/add-a-popover-toolbar.md Include the `follow_the_leader` package in your `pubspec.yaml` to enable advanced toolbar alignment and positioning. ```yaml dependencies: follow_the_leader: latest_version ``` -------------------------------- ### Implement Custom Inline Attribute Delta Format Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/quill/import.md Implement `InlineDeltaFormat` to define how custom inline attributes are parsed. This example shows parsing a hypothetical user tag. ```dart class UserTagFormat implements InlineDeltaFormat { @override Attribution? from(Operation operation) { // Pull out the data based on your custom user tag Delta attribute format... if (!operation.hasAttribute('tag')) { return null; } final tag = operation['tag']; if (tag is! Map) { return null; } final userId = tag['userId']; final userName = tag['userName']; if (userId is! String || userName is! String) { return null; } // This hypothetical example assumes that your editor supports a // `InsertUserTagRequest`. editor.executeRequests([ InsertUserTagRequest( id: userId, name: userName, ), ]); return attribution; } } ``` -------------------------------- ### Defining the Application Executable Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_clones/google_docs/linux/CMakeLists.txt Defines the main executable target, listing its source files. Any new source files should be added here. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) ``` -------------------------------- ### Implement Custom Block Serializer Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/quill/export.md Implement `DeltaSerializer` to serialize a Super Editor `DocumentNode` into a Quill Delta block. This example shows a hypothetical video block serializer. ```dart class VideoBlockSerializer implements DeltaSerializer { const VideoBlockSerializer(); @override bool serialize(DocumentNode node, Delta deltas) { if (node is! VideoNode) { return false; } deltas.operations.add( Operation.insert({ "video": node.url, }), ); return true; } } ``` -------------------------------- ### Extend Text Block Serializer for Custom Inline Attributes Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/quill/export.md Extend `TextBlockDeltaSerializer` to add support for custom inline attributes, such as a user tag. This example assumes a `UserTagAttribution` exists. ```dart class MyAppParagraphSerializer extends TextBlockDeltaSerializer { @override @protected Map getInlineAttributesFor(Set superEditorAttributions) { // Collect any standard Quill Delta attributes that exist in the current // span of text. final inlineAttributes = super.getInlineAttributesFor(superEditorAttribions); // This hypothetical example assumes that your editor has the concept // of a `UserTagAttribution`. final userTag = superEditorAttributions.whereType().firstOrNull; if (userTag != null) { // This inline span includes a user tag. Configure the Quill Delta attributes // based on our custom specifications. inlineAttributes['tag'] = { 'userId': userTag.id, 'userName': userTag.name, }; } return inlineAttributes; } } ``` -------------------------------- ### Animate Keyboard State and Height Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_keyboard/doc/website/source/guides/android.md Implement `WindowInsetsAnimationCompat.Callback` to listen for keyboard animation progress and completion. This allows reporting keyboard height during animation and detecting when the keyboard is fully opened or closed. ```kotlin ViewCompat.setWindowInsetsAnimationCallback( mainView!!, object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_STOP) { override fun onPrepare(animation: WindowInsetsAnimationCompat) {} override fun onStart( animation: WindowInsetsAnimationCompat, bounds: WindowInsetsAnimationCompat.BoundsCompat ): WindowInsetsAnimationCompat.BoundsCompat { return bounds; } override fun onProgress( insets: WindowInsetsCompat, runningAnimations: MutableList ): WindowInsetsCompat { val imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom channel.invokeMethod("onProgress", mapOf( "keyboardHeight" to imeHeight, )) return insets } override fun onEnd( animation: WindowInsetsAnimationCompat ) { // Report whether the keyboard has fully opened or fully closed. if (keyboardState == KeyboardState.Opening) { channel.invokeMethod("keyboardOpened", null) } else if (keyboardState == KeyboardState.Closing) { channel.invokeMethod("keyboardClosed", null) } } } ) ``` -------------------------------- ### Style Custom Underlines in Stylesheet Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/styling/text-underlines.md Add a style rule to your `Stylesheet` to define how custom underlines are painted. This example configures a green squiggly underline for the `standard` underline type. ```dart final myStylesheet = defaultStylesheet.copyWith( addRulesBefore: [ StyleRule( BlockSelector.all, (doc, docNode) { return { // The `underlineStyles` key is used to identify a collection of // underline styles. // // Within the `CustomUnderlineStyles`, you should add an entry // for every underline type name that your app uses, and then // specify the `UnderlineStyle` to paint that underline. UnderlineStyler.underlineStyles: CustomUnderlineStyles({ // In this example, we specify only one underline style. This // style is for the `standard` underline type, and it paints // a green squiggly underline. CustomUnderlineAttribution.standard: SquiggleUnderlineStyle( color: Colors.green, ), // You can add more types and styles here... }), }; }, ), ], ); ``` -------------------------------- ### Activate Keyboard Logging Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_keyboard/README.md Enable logging for keyboard-related events by calling SuperKeyboard.startLogging(). This can be useful for debugging. ```dart SuperKeyboard.startLogging(); ``` -------------------------------- ### Attribute Text with Custom Underline Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/styling/text-underlines.md Attribute text with a `CustomUnderlineAttribution` to specify the visual type of underline. This example shows how to apply the standard underline type to a specific text range. ```dart final underlineAttribution = CustomUnderlineAttribution( CustomUnderlineAttribution.standard, ); AttributedText( "This text includes an underline.", AttributedSpans( attributions: [ SpanMarker(attribution: underlineAttribution, offset: 22, markerType: SpanMarkerType.start), SpanMarker(attribution: underlineAttribution, offset: 30, markerType: SpanMarkerType.end), ], ), ) ``` -------------------------------- ### Simulate Software Keyboard in Widget Tests Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_keyboard/doc/website/source/guides/testing.md Wrap your test widget tree with `SoftwareKeyboardHeightSimulator` to simulate a software keyboard in widget tests. This widget intercepts platform channel messages and adjusts MediaQuery bottom insets to mimic keyboard appearance and disappearance. ```dart testWidgets("my widget test", (tester) async { await tester.pumpWidget( SoftwareKeyboardHeightSimulator( tester: tester, child: MaterialApp(...), ), ); }); ``` -------------------------------- ### Create Flutter Wrapper Application Library Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper intended for the main application runner. It includes core and application-specific sources and links against the Flutter library. ```cmake add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Create Flutter Wrapper Plugin Library Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example/windows/flutter/CMakeLists.txt Builds a static library for the Flutter wrapper intended for use in plugins. It includes core and plugin-specific sources and links against the Flutter library. ```cmake add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Initialize SuperReader with FadeInStyler Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/ai/fade-in-content.md Set up a SuperReader widget with a MutableDocument and a FadeInStyler to manage content appearance. The FadeInStyler controls the opacity of new content as it's added. ```dart class MyState extends State { late final MutableDocument _document; late final MutableDocumentComposer _composer; late final Editor _editor; late final FadeInStyler _fadeInStylePhase; @override void initState() { super.initState(); _document = MutableDocument.empty(); _composer = MutableDocumentComposer( initialSelection: DocumentSelection.collapsed( position: DocumentPosition( nodeId: _document.first.id, nodePosition: TextNodePosition(offset: 0), ), ), ); _editor = createDefaultDocumentEditor(document: _document, composer: _composer); _fadeInStylePhase = FadeInStyler(this); } @override void dispose() { _fadeInStylePhase.dispose(); _composer.dispose(); _editor.dispose(); _document.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return SuperReader( editor: _editor, customStylePhases: [ _fadeInStylePhase, ], ); } } ``` -------------------------------- ### Configure Flutter Library Dependencies (CMake) Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/super_editor/example_perf/linux/flutter/CMakeLists.txt Configures the Flutter library by finding PkgConfig modules for GTK, GLIB, and GIO. It then sets up an interface library target named 'flutter' and links against these dependencies and the Flutter library itself. ```cmake # === Flutter Library === # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Setup Focus Sharing for Popover Toolbar Source: https://github.com/flutter-bounty-hunters/super_editor/blob/main/doc/website/source/super-editor/guides/editing-ui/add-a-popover-toolbar.md Create a `FocusNode` for the popover and use `SuperEditorPopover` to manage focus sharing between the editor and the toolbar, allowing interaction with toolbar items while the editor retains non-primary focus. ```dart class MyAppState extends State { // ... final FocusNode _popoverFocusNode = FocusNode(); @override void dispose() { _popoverFocusNode.dispose(); super.dispose(); } // ... Widget _buildToolbarContent() { return SuperEditorPopover( popoverFocusNode: _popoverFocusNode, editorFocusNode: _editorFocusNode, // The toolbar content. child: SizedBox(), ); } } ```