👋 Welcome to Runestone - a performant plain text editor for iOS with code editing features
Runestone uses GitHub's Tree-sitter to parse code to a syntax tree which is used for features that require an understanding of the code in the editor, for example syntax highlighting.
✨ Features
- Syntax highlighting.
- Line numbers.
- Highlight the selected line.
- Show invisible characters (tabs, spaces and line breaks).
- Insertion of character pairs, e.g. inserting the trailing quotation mark when inserting the leading.
- Customization of colors and fonts.
- Toggle line wrapping on and off.
- Adjust height of lines.
- Add a page guide.
- Add vertical and horizontal overscroll.
- Highlight ranges in the text view.
- Search the text using regular expressions.
- Automatically detects if a file is using spaces or tabs for indentation.
- Specify line endings (CR, LF, CRLF) to use when inserting a line break.
- Automatically detect line endings in a text.
🚀 Getting Started
Please refer to the Getting Started article in the documentation and the Meet Runestone series of tutorials.
📖 Documentation
The documentation of all public types is available at docs.runestone.app. The documentation is generated from the Swift code using Apple's DocC documentation compiler.
🏎 Performance
Runestone was built to be fast. Its good performance is by far mostly thanks to Tree-sitter's incremental parsing and AvalonEdit's approach for managing lines in a document.
When judging the performance of Runestone, it is key to build your app in the release configuration. The optimizations applied by the compiler when using the release configuration becomes very apparent when opening large documents.
🖥 Catalyst
The project should mostly work with Catalyst on the Mac, however, it isn't fully tested and the implementation isn't considered done. The focus is currently on the iPhone and iPad.
📱 Projects
The Runestone framework is used by an app of the same name. The Runestone app is a plain text editor for iPhone and iPad that uses all the features of this framework.
👨💻 Contributing
Pull requests with bugfixes and new features are much appreciated. I'll be happy to review them and merge them once they're ready, as long as they contain change that fit within the vision of Runestone and provide generally useful functionality.
Clone the repository to get started working on the project. Note that Runestone depends on Tree-sitter through a submodule. This submodule must be cloned as well before Runestone can be built. Pass the --recurse-submodules option when cloning the repository to clone all submodules.
git clone --recurse-submodules https://github.com/simonbs/Runestone.git
For an existing checkout, initialize or update the submodule to the commit recorded by Runestone:
git submodule update --init --recursive
SwiftPM initializes submodules automatically when resolving Runestone as a Git dependency. Downloaded GitHub source ZIP/tar archives omit submodule contents; use a Git checkout to build from source.
Tree-sitter runtime
Runestone pins the upstream Tree-sitter submodule to v0.27.1, commit 10eb5ac119eec9cb4267a8e035066473983f5f3a. Upstream removed its Swift package manifest, so Runestone defines a local C target at tree-sitter/lib. It compiles only src/lib.c, which includes the runtime implementation, and exposes only include/tree_sitter/api.h. Private parser headers stay private; generated grammars compile against their own matching headers. This runtime supports grammar ABI versions 13–15.
To upgrade, fetch the desired upstream release tag, check it out inside tree-sitter, and commit the updated submodule pointer together with any required binding changes. Update the version and commit documented here. Do not use git submodule update --remote for normal setup or CI: builds must use the recorded commit. Before merging an upgrade, run the Runestone simulator tests, build the example, run TreeSitterLanguages' compatibility checks, and verify a fresh SwiftPM Git consumer.
Upstream licenses remain in the submodule, including tree-sitter/LICENSE and tree-sitter/lib/src/unicode/LICENSE. Preserve applicable notices when redistributing source or binaries, including in an application's third-party acknowledgements.
Consumers needing the C API can depend on the TreeSitter product from Runestone. Use one Tree-sitter runtime in an application; do not also link an independent copy from another package.
❤️ Acknowledgments
- Tree-sitter is used to parse code incrementally.
- Line management is translated to Swift from AvalonEdit.
- swift-tree-sitter and SwiftTreeSitter which have served as inspiration for the Tree-sitter bindings.
- Detection of indent strategy inspired by auto-detect-indentation.
- And last (but not least!), thanks a ton to Alexander Blach (developer of Textastic), Till Konitzer (developer of Essayist), Greg Pierce (developer of Drafts) and Max Brunsfeld (developer of Tree-sitter) for pointing me in the right direction when I got stuck.
Writing Tools
When built with Xcode 16.2 or later, Runestone integrates with Apple's Writing Tools coordinator on iOS 18.2 and later. On supported Apple Intelligence devices this enables inline proofreading and rewriting, with line-by-line text previews, animations, and proofreading decorations. Runestone requests plain-text results and preserves the document's line endings. Earlier systems and builds retain the system-provided UITextInput experience; availability of Writing Tools is controlled by iOS.
TextView.writingToolsBehavior defaults to .complete. Set it to .limited for panel-based results or .none to disable Writing Tools. This configuration is available with Xcode 16.2 or later on iOS 18.0 and later.
Inline Writing Tools can replace text before the person accepts it. Observe TextView.isWritingToolsActive and the optional textViewWritingToolsWillBegin(_:) / textViewWritingToolsDidEnd(_:) delegate methods to defer autosaving or other persistent side effects until review finishes. Ordinary change callbacks still arrive for each revision, including restoration when a change is rejected. A completed session is a single undo operation; returning to the original text adds no undo entry.
stopWritingTools() ends the session synchronously from Runestone's perspective and keeps the currently displayed revision; it does not undo it. Programmatic document replacement, ordinary edits, undo, and removal from the window stop the session and invalidate outstanding context requests. When loading an external document, suppress persistence callbacks around stopping the session and assigning the new document so the previous editor contents cannot overwrite the incoming document.
Animation images contain only visible text and are bounded by the viewport. As the editor scrolls or reflows, Runestone refreshes the coordinator's geometry. Verifying the complete Apple Intelligence workflow, including generated results and animation timing, requires a supported physical device with Writing Tools enabled.