Better feedback for JSON errors in dialog

Include sub keybindings in keybinding search results
This commit is contained in:
JannisX11 2023-04-05 21:32:08 +02:00
parent bc9c85cb53
commit fac7c26b33
3 changed files with 26 additions and 3 deletions

View File

@ -299,6 +299,18 @@
.markdown a {
cursor: pointer;
}
.markdown pre {
border: 1px solid var(--color-border);
background: var(--color-back);
font-family: var(--font-code);
padding: 6px 10px;
clear: both;
cursor: text;
user-select: text;
}
.markdown pre code {
user-select: text;
}
/*Actions*/
.toolbar {

View File

@ -540,12 +540,21 @@ onVueSetup(function() {
var missmatch = false;
for (var word of keywords) {
if (
!missmatch &&
!action.name.toLowerCase().includes(word) &&
!action.id.toLowerCase().includes(word) &&
!action.keybind.label.toLowerCase().includes(word)
) {
missmatch = true;
}
if (missmatch && action.sub_keybinds) {
for (let key in action.sub_keybinds) {
if (action.sub_keybinds[key].name.toLowerCase().includes(word)) {
missmatch = false;
}
}
}
if (missmatch) break;
}
if (!missmatch) {
actions.push(action)

View File

@ -499,6 +499,7 @@ function autoParseJSON(data, feedback) {
data = JSON.parse(data)
} catch (err) {
if (feedback === false) return;
let error_part = '';
function logErrantPart(whole, start, length) {
var line = whole.substr(0, start).match(/\n/gm)
line = line ? line.length+1 : 1
@ -507,7 +508,8 @@ function autoParseJSON(data, feedback) {
lines.forEach((s, i) => {
result += `#${line+i} ${s}\n`
})
console.log(result.substr(0, result.length-1) + ' <-- HERE')
error_part = result.substr(0, result.length-1) + ' <-- HERE';
console.log(error_part);
}
console.error(err)
var length = err.toString().split('at position ')[1]
@ -523,7 +525,7 @@ function autoParseJSON(data, feedback) {
Blockbench.showMessageBox({
translateKey: 'invalid_file',
icon: 'error',
message: tl('message.invalid_file.message', [err])
message: tl('message.invalid_file.message', [err]) + (error_part ? `\n\n\`\`\`\n${error_part}\n\`\`\`` : '')
})
return;
}