Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐝 Fix editor toolbar link focus issues. (#599)
Browse files Browse the repository at this point in the history
closes TryGhost/Ghost#8195

When the toolbar is toggled into link mode the link input field should always focus, however this only happens on the first time which leads to issues with mobiledoc having focus but not the range.

This fix means that the toolbar always focuses.
  • Loading branch information
disordinary authored and kevinansfield committed Mar 21, 2017
1 parent ab118ba commit 72c0694
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions lib/gh-koenig/addon/components/koenig-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,18 @@ export default Component.extend({
event.stopPropagation();
}
},

doLink(range) {
this.set('isLink', true);
this.set('linkRange', range);
run.schedule('afterRender', this,
() => {
this.$('input').focus();
}
);
},
closeLink() {
this.set('isLink', false);
}
},
doLink(range) {
this.set('isLink', true);
this.set('linkRange', range);
}
});

Expand Down Expand Up @@ -140,7 +144,7 @@ function updateToolbarToRange(self, $holder, $editor, isMouseDown) {
}
);

self.set('isLink', false);
self.send('closeLink');

self.tools.forEach((tool) => {
if (tool.hasOwnProperty('checkElements')) {
Expand All @@ -152,7 +156,7 @@ function updateToolbarToRange(self, $holder, $editor, isMouseDown) {
} else {
if (self.isVisible) {
self.set('isVisible', false);
self.set('isLink', false);
self.send('closeLink');
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/gh-koenig/addon/options/default-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default function (editor, toolbar) {
type: 'markup',
visibility: 'primary',
onClick: (editor) => {
toolbar.doLink(editor.range);
toolbar.send('doLink', editor.range);
},
checkElements(elements) {
set(this, 'selected', elements.filter((element) => element.tagName === 'a').length > 0);
Expand Down

0 comments on commit 72c0694

Please sign in to comment.