1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #1443: Allow opening external editor on new notes

This commit is contained in:
Laurent Cozic 2019-06-13 08:48:19 +01:00
parent a37961dccc
commit 7fae9fda10
2 changed files with 17 additions and 8 deletions

View File

@ -398,7 +398,7 @@ class NoteTextComponent extends React.Component {
return this.webviewRef_.current.wrappedInstance;
}
async saveIfNeeded(saveIfNewNote = false) {
async saveIfNeeded(saveIfNewNote = false, options = {}) {
const forceSave = saveIfNewNote && (this.state.note && !this.state.note.id);
if (this.scheduleSaveTimeout_) clearTimeout(this.scheduleSaveTimeout_);
@ -406,7 +406,7 @@ class NoteTextComponent extends React.Component {
if (!forceSave) {
if (!shared.isModified(this)) return;
}
await shared.saveNoteButton_press(this);
await shared.saveNoteButton_press(this, null, options);
ExternalEditWatcher.instance().updateNoteFile(this.state.note);
}
@ -1172,6 +1172,9 @@ class NoteTextComponent extends React.Component {
async commandStartExternalEditing() {
try {
await this.saveIfNeeded(true, {
autoTitle: false,
});
await ExternalEditWatcher.instance().openAndWatch(this.state.note);
} catch (error) {
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));

View File

@ -19,7 +19,11 @@ shared.noteExists = async function(noteId) {
return !!existingNote;
}
shared.saveNoteButton_press = async function(comp, folderId = null) {
shared.saveNoteButton_press = async function(comp, folderId = null, options = null) {
options = Object.assign({}, {
autoTitle: true,
}, options);
const releaseMutex = await saveNoteMutex_.acquire();
let note = Object.assign({}, comp.state.note);
@ -40,18 +44,18 @@ shared.saveNoteButton_press = async function(comp, folderId = null) {
let isNew = !note.id;
let options = { userSideValidation: true };
let saveOptions = { userSideValidation: true };
if (!isNew) {
options.fields = BaseModel.diffObjectsFields(comp.state.lastSavedNote, note);
saveOptions.fields = BaseModel.diffObjectsFields(comp.state.lastSavedNote, note);
}
const hasAutoTitle = comp.state.newAndNoTitleChangeNoteId || (isNew && !note.title);
if (hasAutoTitle) {
if (hasAutoTitle && options.autoTitle) {
note.title = Note.defaultTitle(note);
if (options.fields && options.fields.indexOf('title') < 0) options.fields.push('title');
if (saveOptions.fields && saveOptions.fields.indexOf('title') < 0) saveOptions.fields.push('title');
}
const savedNote = ('fields' in options) && !options.fields.length ? Object.assign({}, note) : await Note.save(note, options);
const savedNote = ('fields' in saveOptions) && !saveOptions.fields.length ? Object.assign({}, note) : await Note.save(note, saveOptions);
const stateNote = comp.state.note;
@ -80,6 +84,8 @@ shared.saveNoteButton_press = async function(comp, folderId = null) {
if (isNew && hasAutoTitle) newState.newAndNoTitleChangeNoteId = note.id;
if (!options.autoTitle) newState.newAndNoTitleChangeNoteId = null;
comp.setState(newState);
// await shared.refreshAttachedResources(comp, newState.note.body);