🎨 Keep the width when duplicating database table view field https://github.com/siyuan-note/siyuan/issues/11552

This commit is contained in:
Daniel 2024-06-10 16:25:57 +08:00
parent f1993e13e3
commit 68585e21e3
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
5 changed files with 69 additions and 19 deletions

View file

@ -18,7 +18,9 @@ package util
import (
"bytes"
"fmt"
"math/rand"
"regexp"
"strconv"
"strings"
"time"
@ -32,6 +34,20 @@ func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
func GetDuplicateName(master string) (ret string) {
ret = master + " (1)"
r := regexp.MustCompile("^(.*) \\((\\d+)\\)$")
m := r.FindStringSubmatch(master)
if nil == m || 3 > len(m) {
return
}
num, _ := strconv.Atoi(m[2])
num++
ret = fmt.Sprintf("%s (%d)", m[1], num)
return
}
var (
letter = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
)