Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/CodeViewer/CodeViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public struct CodeViewer: ViewRepresentable {
private let darkTheme: CodeWebView.Theme
private let lightTheme: CodeWebView.Theme
private let isReadOnly: Bool
private let isWrap: Bool
private let fontSize: Int

public init(
Expand All @@ -28,6 +29,7 @@ public struct CodeViewer: ViewRepresentable {
darkTheme: CodeWebView.Theme = .solarized_dark,
lightTheme: CodeWebView.Theme = .solarized_light,
isReadOnly: Bool = false,
isWrap: Bool = false,
fontSize: Int = 12,
textDidChanged: ((String) -> Void)? = nil
) {
Expand All @@ -36,6 +38,7 @@ public struct CodeViewer: ViewRepresentable {
self.darkTheme = darkTheme
self.lightTheme = lightTheme
self.isReadOnly = isReadOnly
self.isWrap = isWrap
self.fontSize = fontSize
self.textDidChanged = textDidChanged
}
Expand All @@ -48,6 +51,7 @@ public struct CodeViewer: ViewRepresentable {
let codeView = CodeWebView()

codeView.setReadOnly(isReadOnly)
codeView.setUseWrapMode(isWrap)
codeView.setMode(mode)
codeView.setFontSize(fontSize)

Expand Down
4 changes: 4 additions & 0 deletions Sources/CodeViewer/CodeWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ public class CodeWebView: CustomView {
callback(result)
}
}

func setUseWrapMode(_ isWrap: Bool) {
callJavascript(javascriptString: "editor.session.setUseWrapMode(\(isWrap));")
}
}

extension CodeWebView {
Expand Down