- Notifications
You must be signed in to change notification settings - Fork112
A code editor view written in Swift powered by tree-sitter.
License
CodeEditApp/CodeEditSourceEditor
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
An Xcode-inspired code editor view written in Swift powered by tree-sitter forCodeEdit. Features include syntax highlighting (based on the provided theme), code completion, find and replace, text diff, validation, current line highlighting, minimap, inline messages (warnings and errors), bracket matching, and more.
Important
CodeEditSourceEditor is currently in development and it is not ready for production use.
Please check back later for updates on this project. Contributors are welcome as we build out the features mentioned above!
This package is fully documentedhere.
CodeEditSourceEditor provides two APIs for creating an editor: SwiftUI and AppKit. The SwiftUI API provides extremely customizable and flexible configuration options, including two-way bindings for state like cursor positions and scroll position.
For more complex features that require access to the underlying text view or text storage, we've developed theTextViewCoordinators API. Using this API, developers can inject custom behavior into the editor as events happen, without having to work with state or bindings.
import CodeEditSourceEditorstructContentView:View{@Statevartext="let x = 1.0" /// Automatically updates with cursor positions, scroll position, find panel text. /// Everything in this object is two-way, use it to update cursor positions, scroll position, etc.@StatevareditorState=SourceEditorState() /// Configure the editor's appearance, features, and editing behavior...@Statevartheme=EditorTheme(...)@Statevarfont=NSFont.monospacedSystemFont(ofSize:11, weight:.regular)@StatevarindentOption=.spaces(count:4) /// *Powerful* customization options with our text view coordinators API@StatevarautoCompleteCoordinator=AutoCompleteCoordinator()varbody:someView{SourceEditor( $text, language: language, // Tons of customization options, with good defaults to get started quickly. configuration:SourceEditorConfiguration( appearance:.init(theme: theme, font: font), behavior:.init(indentOption: indentOption)), state: $editorState, coordinators:[autoCompleteCoordinator])} /// Autocompletes "Hello" to "Hello world!" whenever it's typed.finalclassAutoCompleteCoordinator:TextViewCoordinator{func prepareCoordinator(controller:TextViewController){}func textViewDidChangeText(controller:TextViewController){forcursorPositionin controller.cursorPositionswhere cursorPosition.range.location>=5{letlocation= cursorPosition.range.locationletpreviousRange=NSRange(start: location-5, end: location)letstring=(controller.textasNSString).substring(with: previousRange)if string.lowercased()=="hello"{ controller.textView.replaceCharacters(in:NSRange(location: location, length:0), with:" world!")}}}}}
An AppKit API is also available.
See this issueCodeEditApp/CodeEditLanguages#10 onCodeEditLanguages for more information on supported languages.
Special thanks toMatt Massicotte for the great work he's done!
| Package | Source | Author |
|---|---|---|
SwiftTreeSitter | GitHub | Matt Massicotte |
Licensed under theMIT license.
CodeEdit | CodeEditTextView | CodeEditLanguages | CodeEditCLI | CodeEditKit |
About
A code editor view written in Swift powered by tree-sitter.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
