浏览代码

bug 修复

lilei 3 年之前
父节点
当前提交
dea6e6d950
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      public/menus.js

+ 7 - 1
public/menus.js

@@ -85,12 +85,17 @@ function getContextMenu(){
       let flag = false // menu中是否有菜单项,true有,false没有
       const tagName = document.activeElement.tagName // 焦点元素的tagName
       const str = clipboard.readText() // 剪贴板中的内容
-      const selectStr = getSelections() // 选中的内容
+      let selectStr = getSelections()// 选中的内容
       const text = e.target.innerText || '' // 目标标签的innerText
       const value = e.target.value || '' // 目标标签的value
   
       if (selectStr) { // 如果有选中内容
         flag = true
+        selectStr = selectStr.replace(/\r\n\t\f\v/g,"")
+        selectStr = selectStr.replace(/\n/g,"")
+        selectStr = selectStr.replace(/\t/g,"")
+        selectStr = selectStr.replace(/\f/g,"")
+        selectStr = selectStr.replace(/\v/g,"")
         // 在 选中的元素或者输入框 上面点右键,这样在选中后点别处就不会出现右键复制菜单
         if (text.indexOf(selectStr) !== -1 || value.indexOf(selectStr) !== -1) menu.append(new MenuItem({ label: '复制', click: copyString }))
       }
@@ -101,6 +106,7 @@ function getContextMenu(){
   
       // ↑ 情况二
       // menu中有菜单项 且(有选中内容 或 剪贴板中有内容)
+      console.log(flag,getSelections(),str)
       if (flag && (getSelections() || str)) {
         // 将此menu菜单作为 当前窗口 remote.getCurrentWindow() 中的上下文菜单弹出。
         menu.popup(remote.getCurrentWindow())