Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Don't autosave on focus-in to editor #4387

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions core/client/components/gh-post-title-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import FocusInput from 'ghost/components/gh-trim-focus-input';

var PostTitleInput = FocusInput.extend({
click: function (event) {
this._super(event);
if (this.get('value') === '(Untitled)') {
this.$().select();
}
},
focusOut: function (event) {
this._super(event);
if (!this.get('value')) {
this.set('value', '(Untitled)');
}
},
selectOnInsert: function () {
this.$().select();
}.on('didInsertElement')
});

This comment was marked as abuse.

This comment was marked as abuse.


export default PostTitleInput;
11 changes: 5 additions & 6 deletions core/client/components/gh-trim-focus-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ var TrimFocusInput = Ember.TextField.extend({
focus: true,

setFocus: function () {
if (this.focus) {
this.$().val(this.$().val()).focus();
if (this.get('focus')) {
this.$().focus();
}
}.on('didInsertElement'),

focusOut: function () {
var text = this.$().val();

this.$().val(text.trim());
focusOut: function (event) {
this._super(event);
this.set('value', this.get('value').trim());
}
});

Expand Down
4 changes: 2 additions & 2 deletions core/client/controllers/post-settings-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
afterSave = this.get('lastPromise'),
promise;

// Only set an "untitled" slug once per post
if (title === '(Untitled)' && this.get('slug')) {
// Don't set a slug for an untitled post
if (title === '(Untitled)' || !title) {
return;
}

Expand Down
15 changes: 2 additions & 13 deletions core/client/mixins/editor-base-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
markdown = this.get('markdown'),
title = this.get('title'),
titleScratch = this.get('titleScratch'),
isDefaultTitleState = (titleScratch === '(Untitled)' && !title),
scratch = this.getMarkdown().withoutMarkers,
changedAttributes;

if (!this.tagNamesEqual()) {
return true;
}

if (titleScratch !== title) {
if (titleScratch !== title && !isDefaultTitleState) {
return true;
}

Expand Down Expand Up @@ -224,12 +225,6 @@ EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
// set markdown equal to what's in the editor, minus the image markers.
this.set('markdown', this.getMarkdown().withoutMarkers);
this.set('status', status);

// Set a default title
if (!this.get('titleScratch')) {
this.set('titleScratch', '(Untitled)');
}

this.set('title', this.get('titleScratch'));
this.set('meta_title', psmController.get('metaTitleScratch'));
this.set('meta_description', psmController.get('metaDescriptionScratch'));
Expand Down Expand Up @@ -346,12 +341,6 @@ EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
autoSaveId = Ember.run.debounce(this, 'send', 'save', {silent: true, disableNProgress: true}, 3000);
this.set('autoSaveId', autoSaveId);
}
},

autoSaveNew: function () {
if (this.get('isNew')) {
this.send('save', {silent: true, disableNProgress: true});
}
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion core/client/models/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Post = DS.Model.extend(NProgressSaveMixin, ValidationEngine, {
validationType: 'post',

uuid: DS.attr('string'),
title: DS.attr('string', {defaultValue: ''}),
title: DS.attr('string', {defaultValue: '(Untitled)'}),

This comment was marked as abuse.

slug: DS.attr('string'),
markdown: DS.attr('string', {defaultValue: ''}),
html: DS.attr('string'),
Expand Down
4 changes: 2 additions & 2 deletions core/client/templates/editor/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="page-content">
<header>
<section class="box entry-title">
{{gh-trim-focus-input type="text" id="entry-title" placeholder="Your Post Title" value=titleScratch
{{gh-post-title-input type="text" id="entry-title" placeholder="Your Post Title" value=titleScratch
tabindex="1" focus=shouldFocusTitle}}
</section>
</header>
Expand All @@ -19,7 +19,7 @@
<section id="entry-markdown-content" class="entry-markdown-content">
{{gh-codemirror value=scratch scrollInfo=view.markdownScrollInfo
setCodeMirror="setCodeMirror" openModal="openModal" typingPause="autoSave"
focus=shouldFocusEditor onFocusIn="autoSaveNew"}}
focus=shouldFocusEditor}}
</section>
</section>

Expand Down
16 changes: 0 additions & 16 deletions core/test/functional/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,6 @@ screens = {
casper.writeContentToCodeMirror = function (content) {
var lines = content.split('\n');

// If we are on a new editor, the autosave is going to get triggered when we try to type, so we need to trigger
// that and wait for it to sort itself out
if (/ghost\/editor\/$/.test(casper.getCurrentUrl())) {
casper.waitForSelector('.CodeMirror-wrap textarea', function onSuccess() {
casper.click('.CodeMirror-wrap textarea');
}, function onTimeout() {
casper.test.fail('CodeMirror was not found on initial load.');
}, 2000);

casper.waitForUrl(/\/ghost\/editor\/\d+\/$/, function onSuccess() {
// do nothing
}, function onTimeout() {
casper.test.fail('The url didn\'t change: ' + casper.getCurrentUrl());
}, 2000);
}

casper.waitForSelector('.CodeMirror-wrap textarea', function onSuccess() {
casper.each(lines, function (self, line) {
self.sendKeys('.CodeMirror-wrap textarea', line, {keepFocus: true});
Expand Down