dwarvesf / CodeViewer

A custom code editor SwiftUI view
MIT License
140 stars 17 forks source link

Why is the View not refreshed when JSON is dynamically modified by code #10

Open yikogd opened 3 years ago

yikogd commented 3 years ago

iShot2021-07-16 09 09 34 "hello": "world" no show!

jhoughjr commented 2 years ago

Im on macOS 12, Xcode 13 b5 and nothing shows for me. I get a lot of web page proxy errors.

jhoughjr commented 2 years ago

2021-08-28 00:48:54.968984-0500 RepoMan[7808:230187] IMKInputSession [0x600002dc4f30 activate] Invoking activateServerWithReply:, from Main thread = 1, bundleID=com.apple.PressAndHold 2021-08-28 00:48:54.969050-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopAddObserver( 0x600002ec4820 ) on IMKInputSessionXPCInvocation (0x600000aba200), runLoopMode(s) = com.apple.run-loop-mode.view-bridge.blocks + CommonModes 2021-08-28 00:48:54.969077-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopObserver on IMKInputSessionXPCInvocation (0x600000aba200) runLoop fired on IMK _replyObserver, (kCFRunLoopEntry) 2021-08-28 00:48:54.969093-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopObserver kCFRunLoopEntry - innerRunLoopCount=1, otherInnerRunLoopDetected=0 2021-08-28 00:48:54.969653-0500 RepoMan[7808:230231] IMKInputSession -imkxpc_bundleIdentifierWithReply: delivered on IMK Client side!! 2021-08-28 00:48:54.969682-0500 RepoMan[7808:230231] IMKInputSession -imkxpc_bundleIdentifierWithReply: waitCount = 1, Will Perform block on main thread in Mode='com.apple.run-loop-mode.view-bridge.blocks' + CFRunLoopWakeUp 2021-08-28 00:48:54.969712-0500 RepoMan[7808:230187] [IMKInputSession imkxpc_bundleIdentifierWithReply:] ^() Perform block invoked 2021-08-28 00:48:54.969912-0500 RepoMan[7808:230231] IMKInputSession -imkxpc_windowLevelWithReply: delivered on IMK Client side!! 2021-08-28 00:48:54.969934-0500 RepoMan[7808:230231] IMKInputSession -imkxpc_windowLevelWithReply: waitCount = 1, Will Perform block on main thread in Mode='com.apple.run-loop-mode.view-bridge.blocks' + CFRunLoopWakeUp 2021-08-28 00:48:54.969960-0500 RepoMan[7808:230187] [IMKInputSession imkxpc_windowLevelWithReply] ^() Perform block invoked 2021-08-28 00:48:54.970105-0500 RepoMan[7808:230231] IMKInputSession [0x600002dc4f30 activate] ^() ReplyBlock invoked -> IMKInvocationInterrupt, bundleID=com.apple.PressAndHold 2021-08-28 00:48:54.970133-0500 RepoMan[7808:230187] IMKClientInvocationInterruptCurrentXPCReply for SEL=activate - Perform Block (Main thread) 2021-08-28 00:48:54.970151-0500 RepoMan[7808:230187] IMKClientInvocationInterruptCurrentXPCReply for SEL=activate - CFRunLoopTimerInvalidate( 0x600002ac8fc0 ) 2021-08-28 00:48:54.970167-0500 RepoMan[7808:230187] IMKClientInvocationInterruptCurrentXPCReply for SEL=activate - CFRunLoopStop( 0x6000023dc100 ) 2021-08-28 00:48:54.970187-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopObserver on IMKInputSessionXPCInvocation (0x600000aba200) runLoop fired on IMK _replyObserver, (kCFRunLoopExit) 2021-08-28 00:48:54.970201-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopObserver kCFRunLoopExit (State change BEGIN) - innerRunLoopCount=1, otherInnerRunLoopDetected=0 2021-08-28 00:48:54.970215-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopObserver kCFRunLoopExit (State change END) - innerRunLoopCount=0, otherInnerRunLoopDetected=0 2021-08-28 00:48:54.970229-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopRunInMode exited, (kCFRunLoopRunStopped) 2021-08-28 00:48:54.970247-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopRunInMode (kIMKXPCPrivateRunLoopMode) ] RunLoopFinished(1)/Stopped(2) - Run result = 2, (Invocation already done = 1) (Sentinel IsZombie = 0) 2021-08-28 00:48:54.970284-0500 RepoMan[7808:230187] IMKInputSession (activate) CFRunLoopRunInMode() LOOP DONE! 2021-08-28 00:48:54.970352-0500 RepoMan[7808:230187] IMKInputSession [0x600002dc4f30 activate] activateServerWithReply : Call completed = 1 (noError=1), bundleID=com.apple.PressAndHold

khorbushk commented 1 year ago

looks like there is some typo in SwiftUIViewRepresentable

    private func getWebView(context: Context) -> CodeWebView {
        let codeView = CodeWebView()

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

        codeView.setContent(content)
        codeView.clearSelection()

        codeView.textDidChanged = { text in
//            context.coordinator.set(content: text) //  <----
             if content != text && !text.isEmpty {      //  <---- but one more problem on select-remove or on remove last char; looks like lib returns empty string before any change... this needs to be handled
                 content = text                                      //  <----
            }                                                                 //  <----
            self.textDidChanged?(text)
        }

        colorScheme == .dark ? codeView.setTheme(darkTheme) : codeView.setTheme(lightTheme)

        return codeView
    }

    private func updateView(_ webview: CodeWebView, context: Context) {
        if context.coordinator.colorScheme != colorScheme {
            colorScheme == .dark ? webview.setTheme(darkTheme) : webview.setTheme(lightTheme)
            context.coordinator.set(colorScheme: colorScheme)
        }

      webview.setContent(content) // <----
      webview.clearSelection() // <----
    }
khorbushk commented 1 year ago

the problem is that "aceEditorDidChanged" returns at first value and than empty string - at any change (maybe indicator of end line or so...) but this triggers the issue