diff --git a/Sources/CodeViewer/CodeViewer.swift b/Sources/CodeViewer/CodeViewer.swift index 4c4f592..8176f9d 100644 --- a/Sources/CodeViewer/CodeViewer.swift +++ b/Sources/CodeViewer/CodeViewer.swift @@ -21,6 +21,7 @@ public struct CodeViewer: ViewRepresentable { private let lightTheme: CodeWebView.Theme private let isReadOnly: Bool private let fontSize: Int + private let lineHeight: Float public init( content: Binding, @@ -29,6 +30,7 @@ public struct CodeViewer: ViewRepresentable { lightTheme: CodeWebView.Theme = .solarized_light, isReadOnly: Bool = false, fontSize: Int = 12, + lineHeight: Float = 1.3, textDidChanged: ((String) -> Void)? = nil ) { self._content = content @@ -37,6 +39,7 @@ public struct CodeViewer: ViewRepresentable { self.lightTheme = lightTheme self.isReadOnly = isReadOnly self.fontSize = fontSize + self.lineHeight = lineHeight self.textDidChanged = textDidChanged } @@ -50,6 +53,7 @@ public struct CodeViewer: ViewRepresentable { codeView.setReadOnly(isReadOnly) codeView.setMode(mode) codeView.setFontSize(fontSize) + codeView.setLineHeight(lineHeight) codeView.setContent(content) codeView.clearSelection() diff --git a/Sources/CodeViewer/CodeWebView.swift b/Sources/CodeViewer/CodeWebView.swift index 3904b7b..94f7a7b 100644 --- a/Sources/CodeViewer/CodeWebView.swift +++ b/Sources/CodeViewer/CodeWebView.swift @@ -332,6 +332,11 @@ public class CodeWebView: CustomView { callJavascript(javascriptString: script) } + func setLineHeight(_ lineHeight: Float) { + let script = "document.getElementById('editor').style.lineHeight='\(lineHeight)';" + callJavascript(javascriptString: script) + } + func clearSelection() { let script = "editor.clearSelection();" callJavascript(javascriptString: script) diff --git a/Sources/CodeViewer/Resources/ace.bundle/index.html b/Sources/CodeViewer/Resources/ace.bundle/index.html index bf9a759..e695d88 100644 --- a/Sources/CodeViewer/Resources/ace.bundle/index.html +++ b/Sources/CodeViewer/Resources/ace.bundle/index.html @@ -1,6 +1,8 @@ + + ACE in Action