Remove brackets if weight == 1

This commit is contained in:
missionfloyd 2023-04-20 23:55:20 -06:00 committed by GitHub
parent 520b2ea295
commit 726927e17b

View File

@ -128,8 +128,13 @@ app.registerExtension({
// Increment the weight
const weightDelta = event.key === "ArrowUp" ? delta : -delta;
const updatedText = selectedText.replace(/(.*:)(\d+(\.\d+)?)(.*)/, (match, prefix, weight, _, suffix) => {
return prefix + incrementWeight(weight, weightDelta) + suffix;
const updatedText = selectedText.replace(/\((.*):(\d+(?:\.\d+)?)\)/, (match, text, weight) => {
weight = incrementWeight(weight, weightDelta);
if (weight == 1) {
return text;
} else {
return `(${text}:${weight})`;
}
});
inputField.setRangeText(updatedText, start, end, "select");