Permalink
Browse files

fix new line problem in FF, IE9, IE10

  • Loading branch information...
laobubu committed Feb 18, 2016
1 parent 8699c51 commit 958e61ea7de3b692e9a099fc8e65b95ca7cbd761
Showing with 25 additions and 8 deletions.
  1. +1 −1 src/Editor.ts
  2. +24 −7 src/Utils.ts
View
@@ -21,7 +21,7 @@ export class Editor {
static globalConfig: EditorConfig = {
wrapper: 'p',
- emptyBreak: '<br data-mdime-bogus="true">',
+ emptyBreak: /MSIE (9|10)\./.test(navigator.appVersion) ? '' : '<br data-mdime-bogus="true">',
__proto_check__: true
};
View
@@ -20,14 +20,31 @@ namespace MarkdownIME.Utils {
var selection = ele.ownerDocument.defaultView.getSelection();
var range = ele.ownerDocument.createRange();
var focusNode = ele;
- while (focusNode.nodeType == 1) {
- var children = focusNode.childNodes;
- var t = children[children.length - 1];
- if (!t) break;
- focusNode = t;
+
+ while (focusNode.nodeType === Node.ELEMENT_NODE) {
+ //find the last non-autoClose child element node, or child text node
+ let i = focusNode.childNodes.length;
+ while (--i !== -1) {
+ let c = focusNode.childNodes[i];
+ if (
+ (c.nodeType === Node.TEXT_NODE) ||
+ (c.nodeType === Node.ELEMENT_NODE)
+ ) {
+ focusNode = c;
+ break;
+ }
+ }
+ if (i === -1) {
+ break; //not found...
+ }
}
- range.selectNodeContents(focusNode);
- range.collapse((focusNode.nodeName == "BR"));
+
+ if (Pattern.NodeName.autoClose.test(focusNode.nodeName))
+ range.selectNode(focusNode);
+ else
+ range.selectNodeContents(focusNode);
+ range.collapse(focusNode.nodeName === "BR");
+
selection.removeAllRanges();
selection.addRange(range);
}

1 comment on commit 958e61e

@laobubu

This comment has been minimized.

Show comment
Hide comment
Please sign in to comment.