Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Link dialog doesn't show in Safari when caret within word #2584

Merged
merged 3 commits into from Aug 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions blocks/editable/index.js
Expand Up @@ -218,9 +218,33 @@ export default class Editable extends Component {
this.props.onChange( this.savedContent );
}

getEditorSelectionRect() {
let range = this.editor.selection.getRng();

// getBoundingClientRect doesn't work in Safari when range is collapsed
if ( range.collapsed ) {
const { startContainer, startOffset } = range;
range = document.createRange();

if ( ( ! startContainer.nodeValue ) || startContainer.nodeValue.length === 0 ) {
// container has no text content, select node (empty block)
range.selectNode( startContainer );
} else if ( startOffset === startContainer.nodeValue.length ) {
// at end of text content, select last character
range.setStart( startContainer, startContainer.nodeValue.length - 1 );
range.setEnd( startContainer, startContainer.nodeValue.length );
} else {
// select 1 character from current position
range.setStart( startContainer, startOffset );
range.setEnd( startContainer, startOffset + 1 );
}
}

return range.getBoundingClientRect();
}

getFocusPosition() {
const range = this.editor.selection.getRng();
const position = range.getBoundingClientRect();
const position = this.getEditorSelectionRect();

// Find the parent "relative" positioned container
const container = this.props.inlineToolbar
Expand Down