mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-01 21:24:45 +02:00
Desktop: Fixes #1443: Allow opening external editor on new notes
This commit is contained in:
parent
a37961dccc
commit
7fae9fda10
@ -398,7 +398,7 @@ class NoteTextComponent extends React.Component {
|
|||||||
return this.webviewRef_.current.wrappedInstance;
|
return this.webviewRef_.current.wrappedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
async saveIfNeeded(saveIfNewNote = false) {
|
async saveIfNeeded(saveIfNewNote = false, options = {}) {
|
||||||
const forceSave = saveIfNewNote && (this.state.note && !this.state.note.id);
|
const forceSave = saveIfNewNote && (this.state.note && !this.state.note.id);
|
||||||
|
|
||||||
if (this.scheduleSaveTimeout_) clearTimeout(this.scheduleSaveTimeout_);
|
if (this.scheduleSaveTimeout_) clearTimeout(this.scheduleSaveTimeout_);
|
||||||
@ -406,7 +406,7 @@ class NoteTextComponent extends React.Component {
|
|||||||
if (!forceSave) {
|
if (!forceSave) {
|
||||||
if (!shared.isModified(this)) return;
|
if (!shared.isModified(this)) return;
|
||||||
}
|
}
|
||||||
await shared.saveNoteButton_press(this);
|
await shared.saveNoteButton_press(this, null, options);
|
||||||
|
|
||||||
ExternalEditWatcher.instance().updateNoteFile(this.state.note);
|
ExternalEditWatcher.instance().updateNoteFile(this.state.note);
|
||||||
}
|
}
|
||||||
@ -1172,6 +1172,9 @@ class NoteTextComponent extends React.Component {
|
|||||||
|
|
||||||
async commandStartExternalEditing() {
|
async commandStartExternalEditing() {
|
||||||
try {
|
try {
|
||||||
|
await this.saveIfNeeded(true, {
|
||||||
|
autoTitle: false,
|
||||||
|
});
|
||||||
await ExternalEditWatcher.instance().openAndWatch(this.state.note);
|
await ExternalEditWatcher.instance().openAndWatch(this.state.note);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));
|
bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message));
|
||||||
|
@ -19,7 +19,11 @@ shared.noteExists = async function(noteId) {
|
|||||||
return !!existingNote;
|
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();
|
const releaseMutex = await saveNoteMutex_.acquire();
|
||||||
|
|
||||||
let note = Object.assign({}, comp.state.note);
|
let note = Object.assign({}, comp.state.note);
|
||||||
@ -40,18 +44,18 @@ shared.saveNoteButton_press = async function(comp, folderId = null) {
|
|||||||
|
|
||||||
let isNew = !note.id;
|
let isNew = !note.id;
|
||||||
|
|
||||||
let options = { userSideValidation: true };
|
let saveOptions = { userSideValidation: true };
|
||||||
if (!isNew) {
|
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);
|
const hasAutoTitle = comp.state.newAndNoTitleChangeNoteId || (isNew && !note.title);
|
||||||
if (hasAutoTitle) {
|
if (hasAutoTitle && options.autoTitle) {
|
||||||
note.title = Note.defaultTitle(note);
|
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;
|
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 (isNew && hasAutoTitle) newState.newAndNoTitleChangeNoteId = note.id;
|
||||||
|
|
||||||
|
if (!options.autoTitle) newState.newAndNoTitleChangeNoteId = null;
|
||||||
|
|
||||||
comp.setState(newState);
|
comp.setState(newState);
|
||||||
|
|
||||||
// await shared.refreshAttachedResources(comp, newState.note.body);
|
// await shared.refreshAttachedResources(comp, newState.note.body);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user