搜尋套件、儲存庫與 APP 分類

re_editor 封面
套件詳情v0.10.0

re_editor

Re-Editor 是一個功能強大且輕量級的文本和程式碼編輯器組件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
5.4萬
喜歡數
140
Pub 分數
130

安裝套件

flutter pub add re_editor

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Re-Editor 是一個輕量級、強大的文字與程式碼編輯器小部件,專為跨多個平台的無縫整合而設計。它支援語法強調、可自訂主題,以及即時編輯與高效能渲染。以效能為核心打造,無論是簡單的文字輸入還是複雜的程式碼編輯任務,都能提供順暢的體驗。此套件非常適合希望在 Flutter 應用中建構類似 IDE 功能或豐富文字介面的開發者。

適用情境

  • 開發者工具中的程式碼編輯
  • 即時協作文字編輯
  • 語法高亮的筆記應用
  • 文件中的嵌入程式碼片段
  • 建構自定義 IDE 或編輯器

主要特色

  • 語法強調
  • 跨平台支援
  • 可自訂主題
  • 高效渲染
  • 輕量級佔用
  • 即時編輯

適合對象

  • Flutter 開發人員建構程式碼編輯器
  • 需要富文本輸入的應用程式
  • 帶有程式碼範例的教育工具
  • 文件與教學應用程式

使用建議

  • 可能需要額外設定才能使用進階功能
  • 性能取決於內容大小
  • 有限的內建協作功能
  • 未針對非常大的檔案進行優化

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Re-Editor

latest version

中文版本

Re-Editor is a powerful lightweight text and code editor widget and a module in the Reqable project. It can be used as a simple text area or to develop a code editor with complex functions. Unlike Flutter's default TextField, Re-Editor is specifically tailored for the display and input of multi-line text and offers the following features:

  • Two-way horizontal and vertical scrolling.
  • Text syntax highlighting.
  • Content collapsing and expanding.
  • Input hints and auto-completion.
  • Search and replace.
  • Custom context menu builder.
  • Shortcut keys.
  • Large text display and editing.
  • Line numbers and focus line builder.
  • Smart input.

Re-Editor is not a secondary encapsulation based on TextField, but independently implements the layout, drawing, event processing, etc. It is specifically optimized for large texts, providing extremely high performance and fixed some issues of TextField.

Re-Editor offers a high degree of freedom. For example, developers can control whether to enable horizontal scrolling (word wrap), enable read-only mode, display line numbers, display content folding, define custom shortcut keys, and specify text syntax highlighting.

You can run the example project to experience it.

Getting Started

Add the followings in pubspec.yaml.

dependencies:
  re_editor: ^0.10.0

Like TextField, Re-Editor uses CodeLineEditingController as the controller. The following sample code creates the simplest multi-line input area, which is not much different from TextField.

Widget build(BuildContext context) {
  return CodeEditor(
    controller: CodeLineEditingController.fromText('Hello Reqable'),
  );
}
Text Syntax Highlighting

The text highlighting of Re-Editor is based on Re-Highlight and supports nearly a hundred languages ​​and theme styles. Developers can freely choose and configure the code Highlight. The following code specifies the JSON syntax highlighting rules and applies the Atom One Light code coloring.

CodeEditor(
  style: CodeEditorStyle(
    codeTheme: CodeHighlightTheme(
      languages: {
        'json': CodeHighlightThemeMode(
          mode: langJson
        )
      },
      theme: atomOneLightTheme
    ),
  ),
);
Line Numbers and Fold/Unfold Markers

Re-Editor supports configuring whether to display code line numbers and code folding marks, and developers can also implement display styles and layouts by themselves. The example code below shows the default style, built with indicatorBuilder.

CodeEditor(
  indicatorBuilder: (context, editingController, chunkController, notifier) {
    return Row(
      children: [
        DefaultCodeLineNumber(
          controller: editingController,
          notifier: notifier,
        ),
        DefaultCodeChunkIndicator(
          width: 20,
          controller: chunkController,
          notifier: notifier
        )
      ],
    );
  },
);
Code Folding and Unfolding Detection

By default, Re-Editor will automatically detect the folding areas of {} and []. Developers can control whether to detect or write their own detection rules. DefaultCodeChunkAnalyzer is the default detector. If you wish to disable detection, you can use NonCodeChunkAnalyzer.

CodeEditor(
  chunkAnalyzer: DefaultCodeChunkAnalyzer(),
);

If you want to customize it, just implement the CodeChunkAnalyzer interface.

abstract class CodeChunkAnalyzer {

  List<CodeChunk> run(CodeLines codeLines);

}
Scroll Control

Re-Editor supports two-way scrolling, so two ScrollController are used, and developers can use CodeScrollController to construct.

CodeEditor(
  scrollController: CodeScrollController(
    verticalScroller: ScrollController(),
    horizontalScroller: ScrollController(),
  )
);
Find and Replace

Re-Editor implements search and replace control logic, but does not provide a default UI. Developers need to write the UI of the search panel according to the actual situation of their own projects, and use the findBuilder attribute to set up their own search and replace UI.

CodeEditor(
  findBuilder: (context, controller, readOnly) => CodeFindPanelView(controller: controller, readOnly: readOnly),
);

The CodeFindPanelView in the above example is implemented by the developer himself. For the detailed implementation process, please refer to the code in example.

Context Menu

Re-Editor implements the control logic of the desktop context menu and the mobile long-press selection menu, but does not provide a default UI. Developers need to implement the SelectionToolbarController interface and setup it through toolbarController.

CodeEditor(
  toolbarController: _MyToolbarController(),
);
Shortcuts

Re-Editor has the built-in default shortcut hotkeys, and developers can also use shortcutsActivatorsBuilder to set custom shortcut hotkeys. Of course, the shortcut keys only work on the desktop.

The shortcut keys supported by Re-Editor are as follows:

  • Select all (Control/Command + A)
  • Cut selected/current line (Control/Command + V)
  • Copy selected/current line (Control/Command + C)
  • Paste (Control/Command + V)
  • Undo (Control/Command + Z)
  • Redo (Shift + Control/Command + Z)
  • Select the current line (Control/Command + L)
  • Delete current line (Control/Command + D)
  • Move current line (Alt + ↑/↓)
  • Continuous selection (Shift + ↑/↓/←/→)
  • Move cursor (↑/↓/←/→)
  • Move cursor between word boundaries (Alt + ←/→)
  • Move to top/bottom of page (Control/Command + ↑/↓)
  • Indent (Tab)
  • Unindent (Shift + Tab)
  • Comment/uncomment a single line (Control/Command + /)
  • Comment/uncomment multiple lines (Shift + Control/Command + /)
  • Character transpose (Control/Command + T)
  • Search (Control/Command + F)
  • Replace (Alt + Control/Command + F)
  • Save (Control/Command + S)
Code Hints and Auto-Completion

Re-Editor supports using the CodeAutocomplete widget to implement code input prompts and automatic completion. Re-Editor implements basic control logic, but the code prompt content, auto-completion rules and display UI need to be defined by the developer.

CodeAutocomplete(
  viewBuilder: (context, notifier, onSelected) {
    // build the code prompts view
  },
  promptsBuilder: DefaultCodeAutocompletePromptsBuilder(
    language: langDart,
  ),
  child: CodeEditor()
);

Note that Re-Editor is only a lightweight editor and does not have the IDE dynamic syntax analysis, so the code prompts and completion have many limitations. You can refer to the code in example to implement a simple code prompt and completion.

Used By

Re-Editor has been extensively practiced in the Reqable project. You are welcome to download Reqable to experience it.

License

MIT License

Sponsor

If you would like to sponsor this project, you can support us by purchasing a Reqable license.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案