【ngx-ueditor】百度编辑器按下Shift键不触发contentChange事件
背景:基于Angular 6,引入ngx-ueditor
發現現象:如果以Shift鍵+任意鍵結尾,則ngModel會丟失包含shift鍵的字符
? ? ? ? ? ? ? ? ?例如:輸入“ABC+AB++++”,則ngModel中只能獲得“ABC+AB”,丟失最后的幾個+號
原因:按下Shift鍵不觸發編輯器的contentChange事件,
? ? ? ? ? ?但如果輸入shift鍵+任意鍵后,又輸入其他正常字符,觸發了contentChange事件,則可以獲得完整文本,
? ? ? ? ? ?即,若不是以shift鍵+任意鍵結尾,就不存在問題
解決方案一:在保存的時候,調用ueditor的getContent()方法,賦值給,接口參數,手動獲取完整文本保存
Html:
<ueditor [(ngModel)]="content" #full_content></ueditor>? ? ? ?定義ViewChild:
@ViewChild('full_content') full_content: UEditorComponent;保存的時候,獲取完整文本,傳到接口參數:
let content = this.full_content.Instance.getContent();缺點:每次使用ueditor插件都要在提交接口的時候,再獲取一次完整文本,代碼重復,且對開發人員來說,Bug修復需要修改每個使用uEditor的頁面,繁瑣,易出錯
? ? ? ??
解決方案二:? 需要修改Ueditor.all.js(V1.4.3.3版本)文件的三處位置,具體如下:
7487行:刪除“|| evt.shiftKey”條件判斷;
14390行:刪除me.keydown事件的“?&& !evt.shiftKey”條件判斷;
14429行:刪除me.keydown事件的“&& !evt.shiftKey”條件判斷;?
但由于考慮修改插件源碼不利于插件維護和插件升級,故沒有采取第二種方案。
?
?
?
參考資料:https://github.com/cipchk/ngx-ueditor/blob/master/README.md
轉載于:https://www.cnblogs.com/alwaysblog/p/11283752.html
總結
以上是生活随笔為你收集整理的【ngx-ueditor】百度编辑器按下Shift键不触发contentChange事件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Homebrew学习(六)之替换及重置h
- 下一篇: vuex-class用法