Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SwiftUI wrapper for CodeMirror 6.

License

NotificationsYou must be signed in to change notification settings

jaywcjlove/swiftui-codemirror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Usingmy app is also a way tosupport me:
KeyzerVidwall HubVidCropVidwallMousio HintMousioMusicerAudioerFileSentinelFocusCursorVideoerKeyClickerDayBarIconedMousioQuick RSSQuick RSSWeb ServeCopybook GeneratorDevTutor for SwiftUIRegexMateTime PassageIconize FolderTextsound SaverCreate Custom SymbolsDevHubResume RevisePalette GeniusSymbol Scribe

CodeMirror

CodeMirror for macOS/iOS

SwiftUI wrapper for CodeMirror 6.

Features

  • Minimal and fast
  • Handles large documents with ease
  • 40+ themes available
  • macOS & iOS support
  • Built with SwiftUI

Installation

Swift Package Manager

Add CodeMirror to your project using Xcode:

  1. In Xcode, go toFileAdd Package Dependencies...
  2. Enter the repository URL:https://github.com/jaywcjlove/swiftui-codemirror.git
  3. ClickAdd Package

Or add it to yourPackage.swift file:

dependencies:[.package(url:"https://github.com/jaywcjlove/swiftui-codemirror.git", from:"1.0.0")]

Usage

CodeMirror

import SwiftUIimport CodeMirrorstructContentView:View{@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value, prompt:String(localized:"Please enter text"))CodeMirror(value: $value).onLoadSuccess(){print("Hello!")}.onLoadFailed{ errorinprint("@@@2\(#function)\(error)")}.onContentChange{ valueinprint("@@@3 Content Did Change")}}}

Set Line Wrapping

structContentView:View{@StatevarlineWrapping=false@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value).cmLineWrapping($lineWrapping)}}

Show Line Numbers

structContentView:View{@StatevarlineNumber=true@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value).cmLineNumber($lineNumber)}}

Show Fold Gutter

structContentView:View{@StatevarfoldGutter=false@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value).cmFoldGutter($foldGutter)}}

Set Editor Read-Only

structContentView:View{@StatevarreadOnly=false@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value).cmReadOnly($readOnly)}}

Set enabled search

structContentView:View{@StatevarenabledSearch=false@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value).cmEnabledSearch(.constant(false))}}

Set Font Size

CodeMirror(value: $value).cmFontSize(.constant(14))

Set Highlight Active Line

CodeMirror(value: $value).cmHighlightActiveLine(.constant(false))

Set Programming Language

structContentView:View{@Statevarlanguage:Language=.json@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value).cmLanguage($language)}}

Support:C,C++,CQL,CSS,Go,HTML,Java,JavaScript,JSON,JSX,LESS,Liquid,MariaDB SQL,Markdown,MS SQL,MySQL,PHP,PLSQL,PostgreSQL,Python,Rust,Sass,SCSS,SQL,SQLite,TSX,TypeScript,WebAssembly,XML,YAML,APL,PGP,ASN.1,Asterisk,Brainfuck,Cobol,C#,Clojure,ClojureScript,Closure Stylesheets (GSS),CMake,CoffeeScript,Common Lisp,Cypher,Cython,Crystal,D,Dart,diff,Dockerfile,DTD,Dylan,EBNF,ECL,edn,Eiffel,Elm,Erlang,Esper,Factor,FCL,Forth,Fortran,F#,Gas,Gherkin,Groovy,Haskell,Haxe,HXML,HTTP,IDL,JSON-LD,Jinja2,Julia,Kotlin,LiveScript,Lua,mIRC,Mathematica,Modelica,MUMPS,Mbox,Nginx,NSIS,NTriples,Objective-C,Objective-C++,OCaml,Octave,Oz,Pascal,Perl,Pig,PowerShell,Properties files,ProtoBuf,Pug,Puppet,Q,R,RPM Changes,RPM Spec,Ruby,SAS,Scala,Scheme,Shell,Sieve,Smalltalk,Solr,SML,SPARQL,Spreadsheet,Squirrel,Stylus,Swift,sTeX,LaTeX,SystemVerilog,Tcl,Textile,TiddlyWiki,Tiki wiki,TOML,Troff,TTCN,TTCN_CFG,Turtle,Web IDL,VB.NET,VBScript,Velocity,Verilog,VHDL,XQuery,Yacas,Z80,MscGen,,MsGenny,Vue,Angular Template,

Set Theme

structContentView:View{@Environment(\.colorScheme)varcolorScheme@Statevartheme:Themes=.vscodelight@Statevarvalue:String=""varbody:someView{CodeMirror(value: $value).cmTheme($theme).cmTheme(                colorScheme==.dark?.constant(.vscodedark):.constant(.vscodelight))}}

CodeMirrorView

import SwiftUIimport CodeMirrorstructContentView:View{@ObservedObjectvarvm:CodeMirrorVM=.init()@Statevarvalue:String=""varbody:someView{CodeMirrorView(vm, value: $value).onAppear{                vm.setContent(jsonString)}}}

Set Theme

import SwiftUIimport CodeMirrorstructContentView:View{@ObservedObjectvarvm:CodeMirrorVM=.init()@Statevarvalue:String=""varbody:someView{VStack{CodeMirrorView(vm, value: $value).onAppear{                    vm.setContent(jsonString)}Picker("Theme", selection: $vm.theme){ForEach(Themes.allCases, id: \.rawValue){Text($0.rawValue).tag($0)}}}}}

Set Programming Language

Picker("Lang", selection: $vm.language){ForEach(Language.allCases, id: \.rawValue){Text($0.rawValue).tag($0)}}
vm.language=.json

Set Editor Content

Button{    vm.setContent("Hello World!")} label:{Text("SET")}

Get Editor Text Content

Button{Task{letcontent=try?await vm.getContent()print(content??"")}} label:{Text("GET")}

Set Editor Read-Only

Toggle(isOn: $vm.readOnly, label:{Text("Read Only")}).toggleStyle(.checkbox)

Show Line Numbers

ToolbarItem{Toggle(isOn: $vm.lineNumber, label:{Text("Line Number")}).toggleStyle(.checkbox)}

Set Line Wrapping

ToolbarItem{Toggle(isOn: $vm.lineWrapping, label:{Text("Line Wrapping")}).toggleStyle(.checkbox)}

Event

@ObservedObjectvarvm:CodeMirrorVM=.init(    onLoadSuccess:{print("@@@1\(#function)")},    onLoadFailed:{ errorinprint("@@@2\(#function)\(error)")},    onContentChange:{ valueinprint("@@@3 Content Did Change")})

Acknowledgments

Thanks to these projects:

License

Licensed under the MIT License.


[8]ページ先頭

©2009-2025 Movatter.jp