mirror of https://github.com/procxx/kepka.git
Allow non-lower template keys replacements.
This commit is contained in:
parent
4ab0e693c1
commit
93b7a797d2
|
@ -122,7 +122,7 @@ void Inner::prepareRow(Row &row) {
|
||||||
row.question.setText(st::autocompleteRowTitle, row.data.question);
|
row.question.setText(st::autocompleteRowTitle, row.data.question);
|
||||||
row.keys.setText(
|
row.keys.setText(
|
||||||
st::autocompleteRowKeys,
|
st::autocompleteRowKeys,
|
||||||
row.data.keys.join(qstr(", ")));
|
row.data.originalKeys.join(qstr(", ")));
|
||||||
row.answer.setText(st::autocompleteRowAnswer, row.data.value);
|
row.answer.setText(st::autocompleteRowAnswer, row.data.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,10 @@ QString NormalizeQuestion(const QString &question) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString NormalizeKey(const QString &query) {
|
||||||
|
return TextUtilities::RemoveAccents(query.trimmed().toLower());
|
||||||
|
}
|
||||||
|
|
||||||
struct FileResult {
|
struct FileResult {
|
||||||
TemplatesFile result;
|
TemplatesFile result;
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
|
@ -128,7 +132,10 @@ QString ReadByLineGetUrl(const QByteArray &blob, Callback &&callback) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case State::Keys:
|
case State::Keys:
|
||||||
if (!line.isEmpty()) {
|
if (!line.isEmpty()) {
|
||||||
question.keys.push_back(line);
|
question.originalKeys.push_back(line);
|
||||||
|
if (const auto norm = NormalizeKey(line); !norm.isEmpty()) {
|
||||||
|
question.normalizedKeys.push_back(norm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::Value:
|
case State::Value:
|
||||||
|
@ -278,7 +285,7 @@ TemplatesIndex ComputeIndex(const TemplatesData &data) {
|
||||||
for (const auto &[path, file] : data.files) {
|
for (const auto &[path, file] : data.files) {
|
||||||
for (const auto &[normalized, question] : file.questions) {
|
for (const auto &[normalized, question] : file.questions) {
|
||||||
const auto id = std::make_pair(path, normalized);
|
const auto id = std::make_pair(path, normalized);
|
||||||
for (const auto &key : question.keys) {
|
for (const auto &key : question.normalizedKeys) {
|
||||||
pushString(id, key, kWeightStep * kWeightStep);
|
pushString(id, key, kWeightStep * kWeightStep);
|
||||||
}
|
}
|
||||||
pushString(id, question.question, kWeightStep);
|
pushString(id, question.question, kWeightStep);
|
||||||
|
@ -335,7 +342,8 @@ void MoveKeys(TemplatesFile &to, const TemplatesFile &from) {
|
||||||
const auto &existing = from.questions;
|
const auto &existing = from.questions;
|
||||||
for (auto &[normalized, question] : to.questions) {
|
for (auto &[normalized, question] : to.questions) {
|
||||||
if (const auto i = existing.find(normalized); i != end(existing)) {
|
if (const auto i = existing.find(normalized); i != end(existing)) {
|
||||||
question.keys = i->second.keys;
|
question.originalKeys = i->second.originalKeys;
|
||||||
|
question.normalizedKeys = i->second.normalizedKeys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,7 +355,7 @@ Delta ComputeDelta(const TemplatesFile &was, const TemplatesFile &now) {
|
||||||
if (i == end(was.questions)) {
|
if (i == end(was.questions)) {
|
||||||
result.added.push_back(&question);
|
result.added.push_back(&question);
|
||||||
} else {
|
} else {
|
||||||
result.keys.emplace(normalized, i->second.keys);
|
result.keys.emplace(normalized, i->second.originalKeys);
|
||||||
if (i->second.value != question.value) {
|
if (i->second.value != question.value) {
|
||||||
result.changed.push_back(&question);
|
result.changed.push_back(&question);
|
||||||
}
|
}
|
||||||
|
@ -368,7 +376,7 @@ QString FormatUpdateNotification(const QString &path, const Delta &delta) {
|
||||||
for (const auto question : delta.added) {
|
for (const auto question : delta.added) {
|
||||||
result += qsl("Q: %1\nK: %2\nA: %3\n\n"
|
result += qsl("Q: %1\nK: %2\nA: %3\n\n"
|
||||||
).arg(question->question
|
).arg(question->question
|
||||||
).arg(question->keys.join(qsl(", "))
|
).arg(question->originalKeys.join(qsl(", "))
|
||||||
).arg(question->value.trimmed());
|
).arg(question->value.trimmed());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,7 +428,7 @@ int CountMaxKeyLength(const TemplatesData &data) {
|
||||||
auto result = 0;
|
auto result = 0;
|
||||||
for (const auto &[path, file] : data.files) {
|
for (const auto &[path, file] : data.files) {
|
||||||
for (const auto &[normalized, question] : file.questions) {
|
for (const auto &[normalized, question] : file.questions) {
|
||||||
for (const auto &key : question.keys) {
|
for (const auto &key : question.normalizedKeys) {
|
||||||
accumulate_max(result, key.size());
|
accumulate_max(result, key.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -428,10 +436,6 @@ int CountMaxKeyLength(const TemplatesData &data) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString NormalizeKey(const QString &query) {
|
|
||||||
return TextUtilities::RemoveAccents(query.trimmed().toLower());
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace details
|
} // namespace details
|
||||||
|
|
||||||
|
@ -601,7 +605,7 @@ auto Templates::matchExact(QString query) const
|
||||||
|
|
||||||
for (const auto &[path, file] : _data.files) {
|
for (const auto &[path, file] : _data.files) {
|
||||||
for (const auto &[normalized, question] : file.questions) {
|
for (const auto &[normalized, question] : file.questions) {
|
||||||
for (const auto &key : question.keys) {
|
for (const auto &key : question.normalizedKeys) {
|
||||||
if (key == query) {
|
if (key == query) {
|
||||||
return QuestionByKey{ question, key };
|
return QuestionByKey{ question, key };
|
||||||
}
|
}
|
||||||
|
@ -627,7 +631,7 @@ auto Templates::matchFromEnd(QString query) const
|
||||||
auto result = std::optional<QuestionByKey>();
|
auto result = std::optional<QuestionByKey>();
|
||||||
for (const auto &[path, file] : _data.files) {
|
for (const auto &[path, file] : _data.files) {
|
||||||
for (const auto &[normalized, question] : file.questions) {
|
for (const auto &[normalized, question] : file.questions) {
|
||||||
for (const auto &key : question.keys) {
|
for (const auto &key : question.normalizedKeys) {
|
||||||
if (key.size() <= queries.size()
|
if (key.size() <= queries.size()
|
||||||
&& queries[key.size() - 1] == key
|
&& queries[key.size() - 1] == key
|
||||||
&& (!result || result->key.size() < key.size())) {
|
&& (!result || result->key.size() < key.size())) {
|
||||||
|
|
|
@ -16,7 +16,8 @@ namespace details {
|
||||||
|
|
||||||
struct TemplatesQuestion {
|
struct TemplatesQuestion {
|
||||||
QString question;
|
QString question;
|
||||||
QStringList keys;
|
QStringList originalKeys;
|
||||||
|
QStringList normalizedKeys;
|
||||||
QString value;
|
QString value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue