selectall.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * 全选
  3. * @file
  4. * @since 1.2.6.1
  5. */
  6. /**
  7. * 选中所有内容
  8. * @command selectall
  9. * @method execCommand
  10. * @param { String } cmd 命令字符串
  11. * @example
  12. * ```javascript
  13. * editor.execCommand( 'selectall' );
  14. * ```
  15. */
  16. UE.plugins["selectall"] = function() {
  17. var me = this;
  18. me.commands["selectall"] = {
  19. execCommand: function() {
  20. //去掉了原生的selectAll,因为会出现报错和当内容为空时,不能出现闭合状态的光标
  21. var me = this,
  22. body = me.body,
  23. range = me.selection.getRange();
  24. range.selectNodeContents(body);
  25. if (domUtils.isEmptyBlock(body)) {
  26. //opera不能自动合并到元素的里边,要手动处理一下
  27. if (browser.opera && body.firstChild && body.firstChild.nodeType == 1) {
  28. range.setStartAtFirst(body.firstChild);
  29. }
  30. range.collapse(true);
  31. }
  32. range.select(true);
  33. },
  34. notNeedUndo: 1
  35. };
  36. //快捷键
  37. me.addshortcutkey({
  38. selectAll: "ctrl+65"
  39. });
  40. };