Browse Source

【fix】【BOTA】注释回复输入内容,点击蓝色区域退出输入状态,此时点击下拉按钮和回复icon,输入框内容消失(参考Windows)

tangchao 5 months ago
parent
commit
ec906fd6f5

+ 7 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/View/KMNoteFooterCellView.swift

@@ -41,6 +41,7 @@ class KMNoteFooterCellView: NSTableCellView, NibLoadable {
     }()
     
     var itemClick: KMCommonClickBlock?
+    var inputDidChanged: KMValueDidChangeBlock?
     
     var model: KMBotaAnnotationFooterModel?
     
@@ -248,6 +249,12 @@ extension KMNoteFooterCellView: NSTextFieldDelegate {
         }
     }
     
+    func controlTextDidChange(_ obj: Notification) {
+        if self.inputTextF.isEqual(to: obj.object) {
+            self.inputDidChanged?(self.inputTextF.stringValue, nil)
+        }
+    }
+    
     func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool {
         switch commandSelector {
         case #selector(NSResponder.insertNewline(_:)):

+ 12 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -2189,7 +2189,11 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                         self.view.window?.makeFirstResponder(cell?.inputTextF)
                     }
                 } else {
-                    cell?.inputTextF.stringValue = ""
+                    if let cont = data.inputContent {
+                        cell?.inputTextF.stringValue = cont
+                    } else {
+                        cell?.inputTextF.stringValue = ""
+                    }
                 }
                 
                 cell?.updateUI(expand: data.isExpand, animated: data.animated)
@@ -2202,6 +2206,10 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     data.isFirstResp = false
                 }
                 
+                cell?.inputDidChanged = { value, _ in
+                    data.inputContent = value as? String ?? ""
+                }
+                
                 cell?.itemClick = { [weak self] idx, param in
                     if idx == 1 { // comment
                         data.isExpand = !data.isExpand
@@ -2232,6 +2240,7 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                             
                             // 置空编辑状态
                             data.replyModel = nil
+                            data.inputContent = nil
                             return
                         }
                         if let replyAnno = self?.noteReplyHanddler.createReplyAnnotation(data.anno, content: content, userName: KMPreference.shared.author) {
@@ -2241,6 +2250,7 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                             model.replyAnno = replyAnno
                             model.annoModel = data.annoModel
                             data.annoModel?.replyAnnos.append(model)
+                            data.inputContent = nil
                             self?.noteOutlineView.reloadData()
 //                            if let row = self?.noteOutlineView.row(forItem: data) {
 //                                self?.noteOutlineView.scrollRowToVisible(row)
@@ -2254,6 +2264,7 @@ extension KMLeftSideViewController: NSOutlineViewDelegate, NSOutlineViewDataSour
                     } else if idx == 4 { // cancel
                         data.isExpand = false
                         data.replyModel = nil
+                        data.inputContent = nil
                         self?.noteOutlineView.reloadItem(data)
                     }
                 }

+ 2 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Model/KMAnnotationModel.swift

@@ -55,6 +55,8 @@ class KMBotaAnnotationFooterModel: KMBotaAnnotationBaseModel {
     
     weak var replyModel: KMBotaAnnotationReplyModel?
     
+    var inputContent: String?
+    
     var isFirstResp = false
 }