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

Commit

Permalink
🐜 🐝 Create link from toolbar (#586)
Browse files Browse the repository at this point in the history
closes TryGhost/Ghost#8163

Previously when you created a link the toolbar component would re-render and dissapear.

This update ensures that the logic that must happen on first render does not happen on subsequent renders.
  • Loading branch information
disordinary authored and kevinansfield committed Mar 15, 2017
1 parent 867cb41 commit 1c0a252
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/gh-koenig/addon/components/koenig-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default Component.extend({
classNameBindings: ['isVisible'],
isVisible: false,
tools: [],

hasRendered: false,
isLink: computed({
get() {
return this._isLink;
Expand Down Expand Up @@ -58,19 +58,21 @@ export default Component.extend({
},

didRender() {
let $this = this.$();
if (this.get('hasRendered')) {
return;
}
let toolbar = this.$();
let {editor} = this;
let $editor = $(this.get('containerSelector')); // TODO - this element is part of ghost-admin, we need to separate them more.
let isMousedown = false;
if (!editor.range || editor.range.head.isBlank) {
this.set('isVisible', false);
}

$editor.mousedown(() => isMousedown = true);
$editor.mouseup(() => {
isMousedown = false;
updateToolbarToRange(this, $this, $editor, isMousedown);
updateToolbarToRange(this, toolbar, $editor, isMousedown);
});
editor.cursorDidChange(() => updateToolbarToRange(this, $this, $editor, isMousedown));
editor.cursorDidChange(() => updateToolbarToRange(this, toolbar, $editor, isMousedown));
this.set('hasRendered', true);
},

willDestroyElement() {
Expand All @@ -89,7 +91,7 @@ export default Component.extend({
// if enter run link
if (event.keyCode === 13) {
this.set('isLink', false);

this.set('isVisible', false);
this.editor.run((postEditor) => {
let markup = postEditor.builder.createMarkup('a', {href: event.target.value});
postEditor.addMarkupToRange(this.get('linkRange'), markup);
Expand Down

0 comments on commit 1c0a252

Please sign in to comment.