mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
🐜 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:
parent
00f4cab7b9
commit
ffb19b1727
2 changed files with 38 additions and 1 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue