fix "cut to note", closes #2895, #1182

pull/255/head
zadam 2022-06-03 22:05:18 +07:00
parent 8fcc76ad6d
commit 5fbaed61c1
6 changed files with 27 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -248,6 +248,13 @@ class NoteContext extends Component {
ntxId: this.ntxId
}));
}
async getTypeWidget() {
return new Promise(resolve => appContext.triggerCommand('executeWithTypeWidget', {
resolve,
ntxId: this.ntxId
}));
}
}
export default NoteContext;

@ -24,8 +24,8 @@ async function createNote(parentNotePath, options = {}) {
options.saveSelection = false;
}
if (options.saveSelection && utils.isCKEditorInitialized()) {
[options.title, options.content] = parseSelectedHtml(window.cutToNote.getSelectedHtml());
if (options.saveSelection) {
[options.title, options.content] = parseSelectedHtml(options.textEditor.getSelectedHtml());
}
const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath);
@ -46,9 +46,9 @@ async function createNote(parentNotePath, options = {}) {
mime: options.mime
});
if (options.saveSelection && utils.isCKEditorInitialized()) {
if (options.saveSelection) {
// we remove the selection only after it was saved to server to make sure we don't lose anything
window.cutToNote.removeSelection();
options.textEditor.removeSelection();
}
await ws.waitForMaxKnownEntityChangeId();

@ -292,10 +292,6 @@ function copySelectionToClipboard() {
}
}
function isCKEditorInitialized() {
return !!(window && window.cutToNote);
}
function dynamicRequire(moduleName) {
if (typeof __non_webpack_require__ !== 'undefined') {
return __non_webpack_require__(moduleName);
@ -405,7 +401,6 @@ export default {
clearBrowserCache,
normalizeShortcut,
copySelectionToClipboard,
isCKEditorInitialized,
dynamicRequire,
timeLimit,
initHelpDropdown,

@ -327,7 +327,8 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
// without await as this otherwise causes deadlock through component mutex
noteCreateService.createNote(appContext.tabManager.getActiveContextNotePath(), {
isProtected: note.isProtected,
saveSelection: true
saveSelection: true,
textEditor: await this.noteContext.getTextEditor()
});
}
@ -341,4 +342,16 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
this.refresh();
}
}
async executeWithTypeWidgetEvent({resolve, ntxId}) {
if (!this.isNoteContext(ntxId)) {
return;
}
await this.initialized;
await this.getWidgetType();
resolve(this.getTypeWidget());
}
}