1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Electron: Resolves #612: Allow duplicating a note

This commit is contained in:
Laurent Cozic
2018-06-27 21:45:31 +01:00
parent 7d7e1e1637
commit 310afb0ad6
8 changed files with 33 additions and 18 deletions

View File

@@ -29,6 +29,19 @@ class BaseItem extends BaseModel {
throw new Error('Invalid class name: ' + className);
}
static async findUniqueItemTitle(title) {
let counter = 1;
let titleToTry = title;
while (true) {
const item = await this.loadByField('title', titleToTry);
if (!item) return titleToTry;
titleToTry = title + ' (' + counter + ')';
counter++;
if (counter >= 100) titleToTry = title + ' (' + ((new Date()).getTime()) + ')';
if (counter >= 1000) throw new Error('Cannot find unique title');
}
}
// Need to dynamically load the classes like this to avoid circular dependencies
static getClass(name) {
for (let i = 0; i < BaseItem.syncItemDefinitions_.length; i++) {