Rev 17702 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 17702 | Rev 18249 | ||
---|---|---|---|
Line 110... | Line 110... | ||
110 | if (child.nodeType == 11) { child = child.host; } |
110 | if (child.nodeType == 11) { child = child.host; } |
111 | if (child == parent) { return true } |
111 | if (child == parent) { return true } |
112 | } while (child = child.parentNode) |
112 | } while (child = child.parentNode) |
113 | } |
113 | } |
114 | 114 | ||
115 | function activeElt( |
115 | function activeElt(rootNode) { |
116 | // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement. |
116 | // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement. |
117 | // IE < 10 will throw when accessed while the page is loading or in an iframe. |
117 | // IE < 10 will throw when accessed while the page is loading or in an iframe. |
118 | // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable. |
118 | // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable. |
- | 119 | var doc = rootNode.ownerDocument || rootNode; |
|
119 | var activeElement; |
120 | var activeElement; |
120 | try { |
121 | try { |
121 | activeElement = |
122 | activeElement = rootNode.activeElement; |
122 | } catch(e) { |
123 | } catch(e) { |
123 | activeElement = doc.body || null; |
124 | activeElement = doc.body || null; |
124 | } |
125 | } |
125 | while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) |
126 | while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) |
126 | { activeElement = activeElement.shadowRoot.activeElement; } |
127 | { activeElement = activeElement.shadowRoot.activeElement; } |
Line 143... | Line 144... | ||
143 | { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; } |
144 | { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; } |
144 | else if (ie) // Suppress mysterious IE10 errors |
145 | else if (ie) // Suppress mysterious IE10 errors |
145 | { selectInput = function(node) { try { node.select(); } catch(_e) {} }; } |
146 | { selectInput = function(node) { try { node.select(); } catch(_e) {} }; } |
146 | 147 | ||
147 | function doc(cm) { return cm.display.wrapper.ownerDocument } |
148 | function doc(cm) { return cm.display.wrapper.ownerDocument } |
- | 149 | ||
- | 150 | function root(cm) { |
|
- | 151 | return rootNode(cm.display.wrapper) |
|
- | 152 | } |
|
- | 153 | ||
- | 154 | function rootNode(element) { |
|
- | 155 | // Detect modern browsers (2017+). |
|
- | 156 | return element.getRootNode ? element.getRootNode() : element.ownerDocument |
|
- | 157 | } |
|
148 | 158 | ||
149 | function win(cm) { return doc(cm).defaultView } |
159 | function win(cm) { return doc(cm).defaultView } |
150 | 160 | ||
151 | function bind(f) { |
161 | function bind(f) { |
152 | var args = Array.prototype.slice.call(arguments, 1); |
162 | var args = Array.prototype.slice.call(arguments, 1); |
Line 2898... | Line 2908... | ||
2898 | removeChildrenAndAdd(display.measure, measureText); |
2908 | removeChildrenAndAdd(display.measure, measureText); |
2899 | var height = measureText.offsetHeight / 50; |
2909 | var height = measureText.offsetHeight / 50; |
2900 | if (height > 3) { display.cachedTextHeight = height; } |
2910 | if (height > 3) { display.cachedTextHeight = height; } |
2901 | removeChildren(display.measure); |
2911 | removeChildren(display.measure); |
2902 | return height || 1 |
2912 | return height || 1 |
2903 | } |
2913 | } |
2904 | 2914 | ||
2905 | // Compute the default character width. |
2915 | // Compute the default character width. |
2906 | function charWidth(display) { |
2916 | function charWidth(display) { |
2907 | if (display.cachedCharWidth != null) { return display.cachedCharWidth } |
2917 | if (display.cachedCharWidth != null) { return display.cachedCharWidth } |
2908 | var anchor = elt("span", "xxxxxxxxxx"); |
2918 | var anchor = elt("span", "xxxxxxxxxx"); |
Line 3898... | Line 3908... | ||
3898 | if (op.maxScrollLeft < cm.doc.scrollLeft) |
3908 | if (op.maxScrollLeft < cm.doc.scrollLeft) |
3899 | { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); } |
3909 | { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); } |
3900 | cm.display.maxLineChanged = false; |
3910 | cm.display.maxLineChanged = false; |
3901 | } |
3911 | } |
3902 | 3912 | ||
3903 | var takeFocus = op.focus && op.focus == activeElt( |
3913 | var takeFocus = op.focus && op.focus == activeElt(root(cm)); |
3904 | if (op.preparedSelection) |
3914 | if (op.preparedSelection) |
3905 | { cm.display.input.showSelection(op.preparedSelection, takeFocus); } |
3915 | { cm.display.input.showSelection(op.preparedSelection, takeFocus); } |
3906 | if (op.updatedDisplay || op.startHeight != cm.doc.height) |
3916 | if (op.updatedDisplay || op.startHeight != cm.doc.height) |
3907 | { updateScrollbars(cm, op.barMeasure); } |
3917 | { updateScrollbars(cm, op.barMeasure); } |
3908 | if (op.updatedDisplay) |
3918 | if (op.updatedDisplay) |
Line 4075... | Line 4085... | ||
4075 | } |
4085 | } |
4076 | } |
4086 | } |
4077 | 4087 | ||
4078 | function selectionSnapshot(cm) { |
4088 | function selectionSnapshot(cm) { |
4079 | if (cm.hasFocus()) { return null } |
4089 | if (cm.hasFocus()) { return null } |
4080 | var active = activeElt( |
4090 | var active = activeElt(root(cm)); |
4081 | if (!active || !contains(cm.display.lineDiv, active)) { return null } |
4091 | if (!active || !contains(cm.display.lineDiv, active)) { return null } |
4082 | var result = {activeElt: active}; |
4092 | var result = {activeElt: active}; |
4083 | if (window.getSelection) { |
4093 | if (window.getSelection) { |
4084 | var sel = win(cm).getSelection(); |
4094 | var sel = win(cm).getSelection(); |
4085 | if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) { |
4095 | if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) { |
Line 4091... | Line 4101... | ||
4091 | } |
4101 | } |
4092 | return result |
4102 | return result |
4093 | } |
4103 | } |
4094 | 4104 | ||
4095 | function restoreSelection(snapshot) { |
4105 | function restoreSelection(snapshot) { |
4096 | if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(snapshot |
4106 | if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt(rootNode(snapshot.activeElt))) { return } |
4097 | snapshot.activeElt.focus(); |
4107 | snapshot.activeElt.focus(); |
4098 | if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) && |
4108 | if (!/^(INPUT|TEXTAREA)$/.test(snapshot.activeElt.nodeName) && |
4099 | snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) { |
4109 | snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) { |
4100 | var doc = snapshot.activeElt.ownerDocument; |
4110 | var doc = snapshot.activeElt.ownerDocument; |
4101 | var sel = doc.defaultView.getSelection(), range = doc.createRange(); |
4111 | var sel = doc.defaultView.getSelection(), range = doc.createRange(); |
Line 4737... | Line 4747... | ||
4737 | if (hint == "around") { |
4747 | if (hint == "around") { |
4738 | var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0; |
4748 | var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0; |
4739 | out[i] = new Range(inv ? to : from, inv ? from : to); |
4749 | out[i] = new Range(inv ? to : from, inv ? from : to); |
4740 | } else { |
4750 | } else { |
4741 | out[i] = new Range(from, from); |
4751 | out[i] = new Range(from, from); |
4742 | } |
4752 | } |
4743 | } |
4753 | } |
4744 | return new Selection(out, doc.sel.primIndex) |
4754 | return new Selection(out, doc.sel.primIndex) |
4745 | } |
4755 | } |
4746 | 4756 | ||
4747 | // Used to get the editor into a consistent state again when options change. |
4757 | // Used to get the editor into a consistent state again when options change. |
Line 6573... | Line 6583... | ||
6573 | text.filter(function (t) { return t != null; }).join(cm.doc.lineSeparator())), |
6583 | text.filter(function (t) { return t != null; }).join(cm.doc.lineSeparator())), |
6574 | origin: "paste"}; |
6584 | origin: "paste"}; |
6575 | makeChange(cm.doc, change); |
6585 | makeChange(cm.doc, change); |
6576 | setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change)))); |
6586 | setSelectionReplaceHistory(cm.doc, simpleSelection(clipPos(cm.doc, pos), clipPos(cm.doc, changeEnd(change)))); |
6577 | })(); |
6587 | })(); |
6578 | } |
6588 | } |
6579 | }; |
6589 | }; |
6580 | var readTextFromFile = function (file, i) { |
6590 | var readTextFromFile = function (file, i) { |
6581 | if (cm.options.allowDropFileTypes && |
6591 | if (cm.options.allowDropFileTypes && |
6582 | indexOf(cm.options.allowDropFileTypes, file.type) == -1) { |
6592 | indexOf(cm.options.allowDropFileTypes, file.type) == -1) { |
6583 | markAsReadAndPasteIfAllFilesAreRead(); |
6593 | markAsReadAndPasteIfAllFilesAreRead(); |
Line 7262... | Line 7272... | ||
7262 | 7272 | ||
7263 | var lastStoppedKey = null; |
7273 | var lastStoppedKey = null; |
7264 | function onKeyDown(e) { |
7274 | function onKeyDown(e) { |
7265 | var cm = this; |
7275 | var cm = this; |
7266 | if (e.target && e.target != cm.display.input.getField()) { return } |
7276 | if (e.target && e.target != cm.display.input.getField()) { return } |
7267 | cm.curOp.focus = activeElt( |
7277 | cm.curOp.focus = activeElt(root(cm)); |
7268 | if (signalDOMEvent(cm, e)) { return } |
7278 | if (signalDOMEvent(cm, e)) { return } |
7269 | // IE does strange things with escape. |
7279 | // IE does strange things with escape. |
7270 | if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; } |
7280 | if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; } |
7271 | var code = e.keyCode; |
7281 | var code = e.keyCode; |
7272 | cm.display.shift = code == 16 || e.shiftKey; |
7282 | cm.display.shift = code == 16 || e.shiftKey; |
Line 7424... | Line 7434... | ||
7424 | return value |
7434 | return value |
7425 | } |
7435 | } |
7426 | 7436 | ||
7427 | function leftButtonDown(cm, pos, repeat, event) { |
7437 | function leftButtonDown(cm, pos, repeat, event) { |
7428 | if (ie) { setTimeout(bind(ensureFocus, cm), 0); } |
7438 | if (ie) { setTimeout(bind(ensureFocus, cm), 0); } |
7429 | else { cm.curOp.focus = activeElt( |
7439 | else { cm.curOp.focus = activeElt(root(cm)); } |
7430 | 7440 | ||
7431 | var behavior = configureMouse(cm, repeat, event); |
7441 | var behavior = configureMouse(cm, repeat, event); |
7432 | 7442 | ||
7433 | var sel = cm.doc.sel, contained; |
7443 | var sel = cm.doc.sel, contained; |
7434 | if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() && |
7444 | if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() && |
Line 7494... | Line 7504... | ||
7494 | } |
7504 | } |
7495 | 7505 | ||
7496 | // Normal selection, as opposed to text dragging. |
7506 | // Normal selection, as opposed to text dragging. |
7497 | function leftButtonSelect(cm, event, start, behavior) { |
7507 | function leftButtonSelect(cm, event, start, behavior) { |
7498 | if (ie) { delayBlurEvent(cm); } |
7508 | if (ie) { delayBlurEvent(cm); } |
7499 | var display = cm.display, |
7509 | var display = cm.display, doc = cm.doc; |
7500 | e_preventDefault(event); |
7510 | e_preventDefault(event); |
7501 | 7511 | ||
7502 | var ourRange, ourIndex, startSel = |
7512 | var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges; |
7503 | if (behavior.addNew && !behavior.extend) { |
7513 | if (behavior.addNew && !behavior.extend) { |
7504 | ourIndex = |
7514 | ourIndex = doc.sel.contains(start); |
7505 | if (ourIndex > -1) |
7515 | if (ourIndex > -1) |
7506 | { ourRange = ranges[ourIndex]; } |
7516 | { ourRange = ranges[ourIndex]; } |
7507 | else |
7517 | else |
7508 | { ourRange = new Range(start, start); } |
7518 | { ourRange = new Range(start, start); } |
7509 | } else { |
7519 | } else { |
7510 | ourRange = |
7520 | ourRange = doc.sel.primary(); |
7511 | ourIndex = |
7521 | ourIndex = doc.sel.primIndex; |
7512 | } |
7522 | } |
7513 | 7523 | ||
7514 | if (behavior.unit == "rectangle") { |
7524 | if (behavior.unit == "rectangle") { |
7515 | if (!behavior.addNew) { ourRange = new Range(start, start); } |
7525 | if (!behavior.addNew) { ourRange = new Range(start, start); } |
7516 | start = posFromMouse(cm, event, true, true); |
7526 | start = posFromMouse(cm, event, true, true); |
Line 7523... | Line 7533... | ||
7523 | { ourRange = range; } |
7533 | { ourRange = range; } |
7524 | } |
7534 | } |
7525 | 7535 | ||
7526 | if (!behavior.addNew) { |
7536 | if (!behavior.addNew) { |
7527 | ourIndex = 0; |
7537 | ourIndex = 0; |
7528 | setSelection( |
7538 | setSelection(doc, new Selection([ourRange], 0), sel_mouse); |
7529 | startSel = |
7539 | startSel = doc.sel; |
7530 | } else if (ourIndex == -1) { |
7540 | } else if (ourIndex == -1) { |
7531 | ourIndex = ranges.length; |
7541 | ourIndex = ranges.length; |
7532 | setSelection( |
7542 | setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex), |
7533 | {scroll: false, origin: "*mouse"}); |
7543 | {scroll: false, origin: "*mouse"}); |
7534 | } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) { |
7544 | } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) { |
7535 | setSelection( |
7545 | setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0), |
7536 | {scroll: false, origin: "*mouse"}); |
7546 | {scroll: false, origin: "*mouse"}); |
7537 | startSel = |
7547 | startSel = doc.sel; |
7538 | } else { |
7548 | } else { |
7539 | replaceOneSelection( |
7549 | replaceOneSelection(doc, ourIndex, ourRange, sel_mouse); |
7540 | } |
7550 | } |
7541 | 7551 | ||
7542 | var lastPos = start; |
7552 | var lastPos = start; |
7543 | function extendTo(pos) { |
7553 | function extendTo(pos) { |
7544 | if (cmp(lastPos, pos) == 0) { return } |
7554 | if (cmp(lastPos, pos) == 0) { return } |
7545 | lastPos = pos; |
7555 | lastPos = pos; |
7546 | 7556 | ||
7547 | if (behavior.unit == "rectangle") { |
7557 | if (behavior.unit == "rectangle") { |
7548 | var ranges = [], tabSize = cm.options.tabSize; |
7558 | var ranges = [], tabSize = cm.options.tabSize; |
7549 | var startCol = countColumn(getLine( |
7559 | var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize); |
7550 | var posCol = countColumn(getLine( |
7560 | var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize); |
7551 | var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol); |
7561 | var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol); |
7552 | for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); |
7562 | for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line)); |
7553 | line <= end; line++) { |
7563 | line <= end; line++) { |
7554 | var text = getLine( |
7564 | var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize); |
7555 | if (left == right) |
7565 | if (left == right) |
7556 | { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); } |
7566 | { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); } |
7557 | else if (text.length > leftPos) |
7567 | else if (text.length > leftPos) |
7558 | { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); } |
7568 | { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); } |
7559 | } |
7569 | } |
7560 | if (!ranges.length) { ranges.push(new Range(start, start)); } |
7570 | if (!ranges.length) { ranges.push(new Range(start, start)); } |
7561 | setSelection( |
7571 | setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex), |
7562 | {origin: "*mouse", scroll: false}); |
7572 | {origin: "*mouse", scroll: false}); |
7563 | cm.scrollIntoView(pos); |
7573 | cm.scrollIntoView(pos); |
7564 | } else { |
7574 | } else { |
7565 | var oldRange = ourRange; |
7575 | var oldRange = ourRange; |
7566 | var range = rangeForUnit(cm, pos, behavior.unit); |
7576 | var range = rangeForUnit(cm, pos, behavior.unit); |
Line 7571... | Line 7581... | ||
7571 | } else { |
7581 | } else { |
7572 | head = range.anchor; |
7582 | head = range.anchor; |
7573 | anchor = maxPos(oldRange.to(), range.head); |
7583 | anchor = maxPos(oldRange.to(), range.head); |
7574 | } |
7584 | } |
7575 | var ranges$1 = startSel.ranges.slice(0); |
7585 | var ranges$1 = startSel.ranges.slice(0); |
7576 | ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos( |
7586 | ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head)); |
7577 | setSelection( |
7587 | setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse); |
7578 | } |
7588 | } |
7579 | } |
7589 | } |
7580 | 7590 | ||
7581 | var editorSize = display.wrapper.getBoundingClientRect(); |
7591 | var editorSize = display.wrapper.getBoundingClientRect(); |
7582 | // Used to ensure timeout re-tries don't fire when another extend |
7592 | // Used to ensure timeout re-tries don't fire when another extend |
Line 7588... | Line 7598... | ||
7588 | function extend(e) { |
7598 | function extend(e) { |
7589 | var curCount = ++counter; |
7599 | var curCount = ++counter; |
7590 | var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle"); |
7600 | var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle"); |
7591 | if (!cur) { return } |
7601 | if (!cur) { return } |
7592 | if (cmp(cur, lastPos) != 0) { |
7602 | if (cmp(cur, lastPos) != 0) { |
7593 | cm.curOp.focus = activeElt( |
7603 | cm.curOp.focus = activeElt(root(cm)); |
7594 | extendTo(cur); |
7604 | extendTo(cur); |
7595 | var visible = visibleLines(display, |
7605 | var visible = visibleLines(display, doc); |
7596 | if (cur.line >= visible.to || cur.line < visible.from) |
7606 | if (cur.line >= visible.to || cur.line < visible.from) |
7597 | { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); } |
7607 | { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); } |
7598 | } else { |
7608 | } else { |
7599 | var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0; |
7609 | var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0; |
7600 | if (outside) { setTimeout(operation(cm, function () { |
7610 | if (outside) { setTimeout(operation(cm, function () { |
Line 7615... | Line 7625... | ||
7615 | e_preventDefault(e); |
7625 | e_preventDefault(e); |
7616 | display.input.focus(); |
7626 | display.input.focus(); |
7617 | } |
7627 | } |
7618 | off(display.wrapper.ownerDocument, "mousemove", move); |
7628 | off(display.wrapper.ownerDocument, "mousemove", move); |
7619 | off(display.wrapper.ownerDocument, "mouseup", up); |
7629 | off(display.wrapper.ownerDocument, "mouseup", up); |
7620 |
|
7630 | doc.history.lastSelOrigin = null; |
7621 | } |
7631 | } |
7622 | 7632 | ||
7623 | var move = operation(cm, function (e) { |
7633 | var move = operation(cm, function (e) { |
7624 | if (e.buttons === 0 || !e_button(e)) { done(e); } |
7634 | if (e.buttons === 0 || !e_button(e)) { done(e); } |
7625 | else { extend(e); } |
7635 | else { extend(e); } |
Line 8615... | Line 8625... | ||
8615 | else |
8625 | else |
8616 | { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); } |
8626 | { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); } |
8617 | 8627 | ||
8618 | signal(this, "overwriteToggle", this, this.state.overwrite); |
8628 | signal(this, "overwriteToggle", this, this.state.overwrite); |
8619 | }, |
8629 | }, |
8620 | hasFocus: function() { return this.display.input.getField() == activeElt( |
8630 | hasFocus: function() { return this.display.input.getField() == activeElt(root(this)) }, |
8621 | isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) }, |
8631 | isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) }, |
8622 | 8632 | ||
8623 | scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }), |
8633 | scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }), |
8624 | getScrollInfo: function() { |
8634 | getScrollInfo: function() { |
8625 | var scroller = this.display.scroller; |
8635 | var scroller = this.display.scroller; |
Line 8897... | Line 8907... | ||
8897 | // Old-fashioned briefly-focus-a-textarea hack |
8907 | // Old-fashioned briefly-focus-a-textarea hack |
8898 | var kludge = hiddenTextarea(), te = kludge.firstChild; |
8908 | var kludge = hiddenTextarea(), te = kludge.firstChild; |
8899 | disableBrowserMagic(te); |
8909 | disableBrowserMagic(te); |
8900 | cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild); |
8910 | cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild); |
8901 | te.value = lastCopied.text.join("\n"); |
8911 | te.value = lastCopied.text.join("\n"); |
8902 | var hadFocus = activeElt(div |
8912 | var hadFocus = activeElt(rootNode(div)); |
8903 | selectInput(te); |
8913 | selectInput(te); |
8904 | setTimeout(function () { |
8914 | setTimeout(function () { |
8905 | cm.display.lineSpace.removeChild(kludge); |
8915 | cm.display.lineSpace.removeChild(kludge); |
8906 | hadFocus.focus(); |
8916 | hadFocus.focus(); |
8907 | if (hadFocus == div) { input.showPrimarySelection(); } |
8917 | if (hadFocus == div) { input.showPrimarySelection(); } |
Line 8920... | Line 8930... | ||
8920 | } |
8930 | } |
8921 | }; |
8931 | }; |
8922 | 8932 | ||
8923 | ContentEditableInput.prototype.prepareSelection = function () { |
8933 | ContentEditableInput.prototype.prepareSelection = function () { |
8924 | var result = prepareSelection(this.cm, false); |
8934 | var result = prepareSelection(this.cm, false); |
8925 | result.focus = activeElt(this. |
8935 | result.focus = activeElt(rootNode(this.div)) == this.div; |
8926 | return result |
8936 | return result |
8927 | }; |
8937 | }; |
8928 | 8938 | ||
8929 | ContentEditableInput.prototype.showSelection = function (info, takeFocus) { |
8939 | ContentEditableInput.prototype.showSelection = function (info, takeFocus) { |
8930 | if (!info || !this.cm.display.view.length) { return } |
8940 | if (!info || !this.cm.display.view.length) { return } |
Line 9016... | Line 9026... | ||
9016 | return contains(this.div, node) |
9026 | return contains(this.div, node) |
9017 | }; |
9027 | }; |
9018 | 9028 | ||
9019 | ContentEditableInput.prototype.focus = function () { |
9029 | ContentEditableInput.prototype.focus = function () { |
9020 | if (this.cm.options.readOnly != "nocursor") { |
9030 | if (this.cm.options.readOnly != "nocursor") { |
9021 | if (!this.selectionInEditor() || activeElt(this. |
9031 | if (!this.selectionInEditor() || activeElt(rootNode(this.div)) != this.div) |
9022 | { this.showSelection(this.prepareSelection(), true); } |
9032 | { this.showSelection(this.prepareSelection(), true); } |
9023 | this.div.focus(); |
9033 | this.div.focus(); |
9024 | } |
9034 | } |
9025 | }; |
9035 | }; |
9026 | ContentEditableInput.prototype.blur = function () { this.div.blur(); }; |
9036 | ContentEditableInput.prototype.blur = function () { this.div.blur(); }; |
Line 9524... | Line 9534... | ||
9524 | TextareaInput.prototype.getField = function () { return this.textarea }; |
9534 | TextareaInput.prototype.getField = function () { return this.textarea }; |
9525 | 9535 | ||
9526 | TextareaInput.prototype.supportsTouch = function () { return false }; |
9536 | TextareaInput.prototype.supportsTouch = function () { return false }; |
9527 | 9537 | ||
9528 | TextareaInput.prototype.focus = function () { |
9538 | TextareaInput.prototype.focus = function () { |
9529 | if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(this. |
9539 | if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt(rootNode(this.textarea)) != this.textarea)) { |
9530 | try { this.textarea.focus(); } |
9540 | try { this.textarea.focus(); } |
9531 | catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM |
9541 | catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM |
9532 | } |
9542 | } |
9533 | }; |
9543 | }; |
9534 | 9544 | ||
Line 9731... | Line 9741... | ||
9731 | if (!options.placeholder && textarea.placeholder) |
9741 | if (!options.placeholder && textarea.placeholder) |
9732 | { options.placeholder = textarea.placeholder; } |
9742 | { options.placeholder = textarea.placeholder; } |
9733 | // Set autofocus to true if this textarea is focused, or if it has |
9743 | // Set autofocus to true if this textarea is focused, or if it has |
9734 | // autofocus and no other element is focused. |
9744 | // autofocus and no other element is focused. |
9735 | if (options.autofocus == null) { |
9745 | if (options.autofocus == null) { |
9736 | var hasFocus = activeElt(textarea |
9746 | var hasFocus = activeElt(rootNode(textarea)); |
9737 | options.autofocus = hasFocus == textarea || |
9747 | options.autofocus = hasFocus == textarea || |
9738 | textarea.getAttribute("autofocus") != null && hasFocus == document.body; |
9748 | textarea.getAttribute("autofocus") != null && hasFocus == document.body; |
9739 | } |
9749 | } |
9740 | 9750 | ||
9741 | function save() {textarea.value = cm.getValue();} |
9751 | function save() {textarea.value = cm.getValue();} |
Line 9865... | Line 9875... | ||
9865 | 9875 | ||
9866 | CodeMirror.fromTextArea = fromTextArea; |
9876 | CodeMirror.fromTextArea = fromTextArea; |
9867 | 9877 | ||
9868 | addLegacyProps(CodeMirror); |
9878 | addLegacyProps(CodeMirror); |
9869 | 9879 | ||
9870 | CodeMirror.version = "5.65. |
9880 | CodeMirror.version = "5.65.16"; |
9871 | 9881 | ||
9872 | return CodeMirror; |
9882 | return CodeMirror; |
9873 | 9883 | ||
9874 | }))); |
9884 | }))); |