You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-05 22:57:29 +02:00
Desktop, Cli: Fixes #2331: Only de-duplicate imported notebook titles when needed
This commit is contained in:
@@ -29,11 +29,21 @@ class BaseItem extends BaseModel {
|
||||
throw new Error(`Invalid class name: ${className}`);
|
||||
}
|
||||
|
||||
static async findUniqueItemTitle(title) {
|
||||
static async findUniqueItemTitle(title, parentId = null) {
|
||||
let counter = 1;
|
||||
let titleToTry = title;
|
||||
while (true) {
|
||||
const item = await this.loadByField('title', titleToTry);
|
||||
let item = null;
|
||||
|
||||
if (parentId !== null) {
|
||||
item = await this.loadByFields({
|
||||
title: titleToTry,
|
||||
parent_id: parentId,
|
||||
});
|
||||
} else {
|
||||
item = await this.loadByField('title', titleToTry);
|
||||
}
|
||||
|
||||
if (!item) return titleToTry;
|
||||
titleToTry = `${title} (${counter})`;
|
||||
counter++;
|
||||
|
||||
Reference in New Issue
Block a user