1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00

🐜 ️ Card menu fixes:

Closes #8164

- When a user clicks on a card within a '/' menu it now executes that tool.
- If a user engages a card with the / menu the content of the paragraph is now inserted into the card.
This commit is contained in:
Ryan McCarvill 2017-03-15 19:14:29 +13:00 committed by Kevin Ansfield
parent e87762c723
commit 8d19c13b3c
4 changed files with 20 additions and 9 deletions

View file

@ -12,12 +12,12 @@ export default Component.extend({
this.set('selected', this.get('tool').selected);
},
click: function () { // eslint-disable-line
let {section} = this.get('range');
let {section, startOffset, endOffset} = this.get('range');
let editor = this.get('editor');
editor.range = Range.create(section, 0, section, 0);
editor.range = Range.create(section, startOffset, section, endOffset);
this.get('tool').onClick(editor, section);
this.sendAction('clicked');
this.get('tool').onClick(editor, section);
}
});

View file

@ -68,6 +68,7 @@ export default Component.extend({
let $editor = $(this.get('containerSelector'));
input.blur(() => {
// nasty hack - give the tool time to execute before removing this from the dom.
window.setTimeout(() => {
this.send('closeMenuKeepButton');
}, 200);

View file

@ -47,9 +47,6 @@ export default Component.extend({
selectedTool.selected = true;
}
if (i === 0) {
// this.send('closeMenu');
}
return tools;
}),
init() {
@ -79,12 +76,18 @@ export default Component.extend({
cursorChange() {
let editor = this.get('editor');
let range = this.get('range');
let isOpen = this.get('isOpen');
// if the cursor isn't in the editor then close the menu
if (!range || !editor.range.isCollapsed || editor.range.head.section !== range.section || this.editor.range.head.offset < 1 || !this.editor.range.head.section) {
this.send('closeMenu');
// unless we click on a tool because the tool will close the menu.
if (isOpen && !$(window.getSelection().anchorNode).parents('.gh-cardmenu').length) {
this.send('closeMenu');
}
return;
}
if (this.get('isOpen')) {
if (isOpen) {
let queryString = editor.range.head.section.text.substring(range.startOffset, editor.range.head.offset);
this.set('query', queryString);
// if we've typed 5 characters and have no tools then close.
@ -208,6 +211,13 @@ export default Component.extend({
editor._keyCommands.splice(i, 1);
}
}
},
clickedMenu: function () { // eslint-disable-line
// let{section, startOffset, endOffset} = this.get('range');
window.editor.range.head.offset = this.get('range').startOffset - 1;
window.editor.deleteRange(window.editor.range);
this.send('closeMenu');
}
}
});

View file

@ -1,7 +1,7 @@
{{#if isOpen}}
<div class="gh-cardmenu">
{{#each toolbar as |tool index|}}
{{koenig-menu-item tool=tool editor=editor range=range selected=tool.selected clicked=(action "closeMenu")}}
{{koenig-menu-item tool=tool editor=editor range=range selected=tool.selected clicked=(action "clickedMenu")}}
{{/each}}
</div>
{{/if}}