🐜 fix key up to empty title (#629)

closes https://github.com/TryGhost/Ghost/issues/8293
- when a title is empty it has no textnode to get a length of so we automaticlly put the horizontal offset of the cursor to 0
This commit is contained in:
Ryan McCarvill 2017-04-10 21:12:04 +12:00 committed by Kevin Ansfield
parent 4670d3fe03
commit 4f33b83035
2 changed files with 38 additions and 1 deletions

View File

@ -98,7 +98,7 @@ export default Component.extend({
let cursorPositionInEditor = editor.positionAtPoint(cursorPositionOnScreen.left, loc.top);
if (cursorPositionInEditor.isBlank) {
if (!cursorPositionInEditor || cursorPositionInEditor.isBlank) {
editor.element.focus();
} else {
editor.selectRange(cursorPositionInEditor.toRange());
@ -176,6 +176,9 @@ export default Component.extend({
// gets the character in the last line of the title that best matches the editor
getOffsetAtPosition(horizontalOffset) {
let [title] = this.$('.gh-editor-title')[0].childNodes;
if (!title || !title.textContent) {
return 0;
}
let len = title.textContent.length;
let range = document.createRange();

View File

@ -425,6 +425,40 @@ describe('Acceptance: Editor', function() {
});
});
it('if title is blank it correctly shows the placeholder', function () {
server.createList('post', 1);
// post id 1 is a draft, checking for draft behaviour now
visit('/editor/1');
andThen(() => {
expect(currentURL(), 'currentURL')
.to.equal('/editor/1');
});
andThen(() => {
titleRendered();
});
andThen(() => {
let title = find('#gh-editor-title div');
expect(title.data('placeholder')).to.equal('Your Post Title');
expect(title.hasClass('no-content')).to.be.false;
title.html('');
});
andThen(() => {
let title = find('#gh-editor-title div');
expect(title.hasClass('no-content')).to.be.true;
title.html('test');
});
andThen(() => {
let title = find('#gh-editor-title div');
expect(title.hasClass('no-content')).to.be.false;
});
});
it('renders first countdown notification before scheduled time', function () {
let clock = sinon.useFakeTimers(moment().valueOf());
let compareDate = moment().tz('Etc/UTC').add(4, 'minutes').format('DD MMM YY @ HH:mm').toString();