fix(shortcuts-settings): settingsJSON must be defined if note doesn't exist

This commit is contained in:
Frederic Hemberger 2024-08-03 13:30:22 +02:00 committed by GitHub
parent 818f58b460
commit 0febcacb93
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1055,16 +1055,16 @@ function ImportExport({ shortcuts, onClose }) {
const { note = '' } = relationship; const { note = '' } = relationship;
// const newNote = `${note}\n\n\n$<phanpy-shortcuts-settings>{shortcutsStr}</phanpy-shortcuts-settings>`; // const newNote = `${note}\n\n\n$<phanpy-shortcuts-settings>{shortcutsStr}</phanpy-shortcuts-settings>`;
let newNote = ''; let newNote = '';
if (
/<phanpy-shortcuts-settings>(.*)<\/phanpy-shortcuts-settings>/.test(
note,
)
) {
const settingsJSON = JSON.stringify({ const settingsJSON = JSON.stringify({
v: '1', // version v: '1', // version
dt: Date.now(), // datetime stamp dt: Date.now(), // datetime stamp
data: shortcutsStr, // shortcuts settings string data: shortcutsStr, // shortcuts settings string
}); });
if (
/<phanpy-shortcuts-settings>(.*)<\/phanpy-shortcuts-settings>/.test(
note,
)
) {
newNote = note.replace( newNote = note.replace(
/<phanpy-shortcuts-settings>(.*)<\/phanpy-shortcuts-settings>/, /<phanpy-shortcuts-settings>(.*)<\/phanpy-shortcuts-settings>/,
`<phanpy-shortcuts-settings>${settingsJSON}</phanpy-shortcuts-settings>`, `<phanpy-shortcuts-settings>${settingsJSON}</phanpy-shortcuts-settings>`,