• Stars
    star
    564
  • Rank 79,014 (Top 2 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

SwiftUI code editor view for iOS and macOS

SwiftUI code editor view for iOS and macOS

The CodeEditorView Swift package provides a SwiftUI view implementing a rich code editor for iOS and macOS whose visual style is inspired by Xcode. The currently supported functionality includes syntax highlighting with configurable themes, inline message (warnings, errors, etc) reporting, bracket matching, matching bracket insertion, current line highlighting, and a minimap (only on macOS).

Screenshots of the demo app

This is the default dark theme on macOS. Like in Xcode, messages have got an inline view on the right-hand side of the screen, which pops up into a larger overlay to display more information. The minimap on the right provides an outline of the edited text.

The following is the default light theme on iOS. Both line highlighting and the minimap are currently not supported on iOS due to limitations in the iOS version of TextKit. Instead of the line highlight, both the current line (or the current selection range) and lines with messages are indicated with differently coloured line numbers in the gutter.

How to use it

Typical usage of the view is as follows.

struct ContentView: View {
  @State private var text:     String                    = "My awesome code..."
  @State private var position: CodeEditor.Position       = CodeEditor.Position()
  @State private var messages: Set<TextLocated<Message>> = Set()

  @Environment(\.colorScheme) private var colorScheme: ColorScheme

  var body: some View {
    CodeEditor(text: $text, position: $position, messages: $messages, language: .swift)
      .environment(\.codeEditorTheme,
                   colorScheme == .dark ? Theme.defaultDark : Theme.defaultLight)
  }
}

Demo app

To see the CodeEditorView in action, have a look at the repo with a cross-platform demo app.

Documentation

For more information, see the package documentation.

Status

I consider this to be pre-release quality. It is sufficient to start building something on it, but it is not yet ready for production. While the CodeEditor view already supports quite a bit of advanced functionality (such as the inline messages and minimap), other components are still quite simple, such as the range of tokens covered by the language configuration. Moreover, performance is still an issue that needs to be addressed. The core architecture, such as the incremental tokenisation for syntax highlighting, is designed to handle larger files smoothly, but the overall implementation still needs some performance debugging.

License

Copyright [2021..2023] Manuel M. T. Chakravarty.

Distributed under the Apache-2.0 license — see the license file for details.

More Repositories

1

HaskellSpriteKit

Haskell binding to Apple's SpriteKit framework
Haskell
172
star
2

language-c-inline

Inline C & Objective-C in Haskell
Haskell
147
star
3

BigPixel

Pixel art for games
Haskell
137
star
4

lets-program

Let's program! Get into programming writing a simple game.
Haskell
76
star
5

lazy-lambda

Lazy Lambda — a Flappy Bird clone in Haskell with SpriteKit
Haskell
73
star
6

goalsapp

Track periodic goals — a sample iPhone app
Swift
27
star
7

haskell.sty

LaTeX style file to typeset functional languages like Haskell
26
star
8

ProjectNavigator

SwiftUI project navigation view for macOS and iOS
Swift
21
star
9

gloss-game

A convenience wrapper around the Gloss library to make writing games in Haskell even easier
Haskell
17
star
10

hoas-conv

Toy language to show the conversion of embedded higher-order abstract syntax (HOAS)
Haskell
17
star
11

CodeEditorDemo

Demo app for CodeEditorView
Swift
16
star
12

language-swift-quote

Quasiquotation for Swift in Haskell
9
star
13

welcome-to-fp-workshop

Support material for the “Introduction to Functional Programming” workshop @ the "Welcome to Functional Programming" day of YOW! Lambda Jam, Sydney, 2018 & 2019
8
star
14

fp-in-swift

Support material for "Functional Programming in Swift" @ Functional Conf, Bangalore, 2017
Swift
7
star
15

accelerate-agda

Accelerate in Agda
Haskell
6
star
16

ylj14-workshop

Code for the YOW! Lambda Jam Workshop on Inline C in Haskell
Haskell
3
star
17

galactico

Drive the economy of galactic colonies
Haskell
3
star
18

haskell-containers

Docker container images for Haskell apps
2
star
19

lets-code

Let's code! A playful introduction to coding
Haskell
1
star