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