Skip to content

Commit

Permalink
fix: manage update editor content
Browse files Browse the repository at this point in the history
work on #24
  • Loading branch information
bsorrentino committed Sep 12, 2023
1 parent 0d24262 commit 9e736ec
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions PlantUMLEditor/Sources/CodeViewer/CodeViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct CodeViewer: ViewRepresentable {
}

public func makeCoordinator() -> Coordinator {
Coordinator(content: $content,
Coordinator(content: content,
colorScheme: colorScheme,
lightTheme: lightTheme,
darkTheme: darkTheme,
Expand All @@ -78,7 +78,8 @@ public struct CodeViewer: ViewRepresentable {
codeView.clearSelection()
codeView.setShowGutter(showGutter)
codeView.textDidChanged = { text in
context.coordinator.set(content: text)
self.content = text
context.coordinator.content = text
self.textDidChanged?(text)
}
codeView.setTheme( colorScheme == .dark ? darkTheme : lightTheme )
Expand All @@ -87,8 +88,11 @@ public struct CodeViewer: ViewRepresentable {
}

private func updateView(_ webview: CodeWebView, context: Context) {
webview.setContent(content)
webview.clearSelection()
if context.coordinator.content != content {
context.coordinator.content = content
webview.setContent(content)
print(content)
}

if context.coordinator.fontSize != fontSize {
context.coordinator.fontSize = fontSize
Expand Down Expand Up @@ -147,34 +151,28 @@ public struct CodeViewer: ViewRepresentable {
public extension CodeViewer {

class Coordinator: NSObject {
@Binding private(set) var content: String
var content: String
var colorScheme: ColorScheme
var fontSize: CGFloat
var showGutter: Bool
var darkTheme:CodeWebView.Theme
var lightTheme:CodeWebView.Theme

init(content: Binding<String>,
init(content: String,
colorScheme: ColorScheme,
lightTheme:CodeWebView.Theme,
darkTheme:CodeWebView.Theme,
fontSize: CGFloat,
showGutter: Bool ) {

_content = content
self.content = content
self.colorScheme = colorScheme
self.darkTheme = darkTheme
self.lightTheme = lightTheme
self.fontSize = fontSize
self.showGutter = showGutter
}

func set(content: String) {
if self.content != content {
self.content = content
}
}

}
}

Expand Down

0 comments on commit 9e736ec

Please sign in to comment.