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 @@ -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<String>,
Expand All @@ -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
Expand All @@ -37,6 +39,7 @@ public struct CodeViewer: ViewRepresentable {
self.lightTheme = lightTheme
self.isReadOnly = isReadOnly
self.fontSize = fontSize
self.lineHeight = lineHeight
self.textDidChanged = textDidChanged
}

Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions Sources/CodeViewer/CodeWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Sources/CodeViewer/Resources/ace.bundle/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Set viewport. -->
<meta name="viewport" content="initial-scale=1">
<title>ACE in Action</title>
<style type="text/css" media="screen">
#editor {
Expand Down