Giter Site home page Giter Site logo

pictarine / codemirror-swiftui Goto Github PK

View Code? Open in Web Editor NEW
90.0 6.0 20.0 1.34 MB

CodeMirror-SwiftUI is a lightweight wrapper of CodeMirror for macOS and iOS packaged for SwiftUI.

License: MIT License

Swift 0.97% CSS 4.73% JavaScript 78.19% HTML 16.11%
swift codemirror swiftui codemirror-editor

codemirror-swiftui's Introduction

CodeMirror-SwiftUI

GitHub tag (latest by date) Swift Package Manager Swift5 Platform GitHub repo size

CodeMirror-SwiftUI

CodeMirror-SwiftUI is a lightweight wrapper of CodeMirror for macOS and iOS packaged for SwiftUI.

This package is a fork from CodeMirror-Swift

Features

  • ๐Ÿญ Lightweight CodeMirror wrapper (build 5.59.4)
  • โœ… 100% Native Swift 5 and modern WKWebView
  • ๐Ÿ‘‘ Support iOS & macOS
  • ๐ŸŽง Built-in addons
  • ๐Ÿ“• 100+ built-in themes and syntax highlight modes
  • โšก๏ธ Ready to go

Requirements

  • Xcode 12
  • Swift 5.3

Integration

CodeMirror-SwiftUI is available via Swift Package Manager

Using Xcode 12, go to File -> Swift Packages -> Add Package Dependency and enter https://github.com/Pictarine/CodeMirror-SwiftUI

Usage

CodeMirror gives you access to a new view called CodeView. It can be integrated within your view body like this :

CodeView(theme: themes[selectedTheme],
         code: $codeBlock,
         mode: codeMode,
         fontSize: fontSize,
         showInvisibleCharacters: showInvisibleCharacters,
         lineWrapping: lineWrapping)
.onLoadSuccess {
  print("Loaded")
}
.onContentChange { newCodeBlock in
  print("Content Change")
}
.onLoadFail { error in
  print("Load failed : \(error.localizedDescription)")
}

Details

Code Editor Features

  • CodeMirror v5.59.4
  • Better find and replace dialog integration
  • Autocompletion hints (ctrl+space)
  • Reindent (ctrl+i)
  • Auto close tags and brackets

Parameters

CodeView has multiple params:

Parameter name Optional Type Default
code false Binding
mode false Mode
theme true CodeViewTheme .materialPalenight
fontSize true Int 12 (px)
showInvisibleCharacters true Bool true
lineWrapping true Bool true

Modifiers

CodeView comes with three modifiers

onLoadSuccess { ... }
onLoadFail { ... }
onContentChange { ... }

Demo

black_light_theme

License

CodeMirror-SwiftUI is available under the MIT license. See the LICENSE file for more info.

codemirror-swiftui's People

Contributors

greystone avatar l1cardo avatar marshallino16 avatar rafali avatar sethadam1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

codemirror-swiftui's Issues

Disable User Interactions

Is there any way I can disable user interactions. I just need to show code not to edit it.

Thank you.
Screenshot 2021-08-10 at 12 19 37

Missing Modes

I need toml badly, but I can not found toml mode.
There is the resource but it seems you did not implement it.
image

Programmatic scrolling

Is there a way to do programmatic scrolling so that I can automatically go to a certain line number or character offset?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.