mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 14:50:29 +00:00
Fix selecting quote (#2678)
This commit is contained in:
@@ -216,12 +216,20 @@ class DraftReview extends React.Component {
|
|||||||
}
|
}
|
||||||
if (nativeSelection.isCollapsed === false) {
|
if (nativeSelection.isCollapsed === false) {
|
||||||
const nativeRange = nativeSelection.getRangeAt(0);
|
const nativeRange = nativeSelection.getRangeAt(0);
|
||||||
let range = findRange(nativeRange, this.refs.diffViewer.value);
|
const focusNode = nativeSelection.focusNode;
|
||||||
if (!range) {
|
if ((focusNode.tagName === "I") ||
|
||||||
this.range = null;
|
(focusNode.nodeType !== 3 && focusNode.getAttribute("class") === "language-type")) {
|
||||||
return;
|
// fix select last paragraph
|
||||||
|
let fragment = nativeRange.cloneContents();
|
||||||
|
let startNode = fragment.firstChild.firstChild;
|
||||||
|
let newNativeRange = document.createRange();
|
||||||
|
newNativeRange.setStartBefore(startNode);
|
||||||
|
newNativeRange.setEndAfter(startNode);
|
||||||
|
this.range = findRange(newNativeRange, this.refs.diffViewer.value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.range = findRange(nativeRange, this.refs.diffViewer.value);
|
||||||
}
|
}
|
||||||
this.range = range;
|
|
||||||
let rect = nativeRange.getBoundingClientRect();
|
let rect = nativeRange.getBoundingClientRect();
|
||||||
// fix Safari bug
|
// fix Safari bug
|
||||||
if (navigator.userAgent.indexOf('Chrome') < 0 && navigator.userAgent.indexOf('Safari') > 0) {
|
if (navigator.userAgent.indexOf('Chrome') < 0 && navigator.userAgent.indexOf('Safari') > 0) {
|
||||||
@@ -249,11 +257,11 @@ class DraftReview extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getQuote = () => {
|
getQuote = () => {
|
||||||
this.quote = '';
|
|
||||||
let range = this.range;
|
let range = this.range;
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.quote = '';
|
||||||
const { document } = this.refs.diffViewer.value;
|
const { document } = this.refs.diffViewer.value;
|
||||||
let { anchor, focus } = range;
|
let { anchor, focus } = range;
|
||||||
const anchorText = document.getNode(anchor.key);
|
const anchorText = document.getNode(anchor.key);
|
||||||
@@ -262,9 +270,6 @@ class DraftReview extends React.Component {
|
|||||||
const focusInline = document.getClosestInline(focus.key);
|
const focusInline = document.getClosestInline(focus.key);
|
||||||
const focusBlock = document.getClosestBlock(focus.key);
|
const focusBlock = document.getClosestBlock(focus.key);
|
||||||
const anchorBlock = document.getClosestBlock(anchor.key);
|
const anchorBlock = document.getClosestBlock(anchor.key);
|
||||||
if (anchorBlock && anchor.offset == 0 && focusBlock && focus.offset != 0) {
|
|
||||||
range = range.setFocus(focus.setOffset(0));
|
|
||||||
}
|
|
||||||
// COMPAT: If the selection is at the end of a non-void inline node, and
|
// COMPAT: If the selection is at the end of a non-void inline node, and
|
||||||
// there is a node after it, put it in the node after instead. This
|
// there is a node after it, put it in the node after instead. This
|
||||||
// standardizes the behavior, since it's indistinguishable to the user.
|
// standardizes the behavior, since it's indistinguishable to the user.
|
||||||
|
Reference in New Issue
Block a user