Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dictionary priority from settings #1606

Merged
merged 4 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions ext/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -2288,14 +2288,11 @@ button.hotkey-list-item-enabled-button[data-scope-count='0'] {
.dictionary-list {
width: 100%;
display: grid;
grid-template-columns: auto auto 1fr auto auto auto auto;
grid-template-columns: auto auto 1fr auto auto auto;
grid-template-rows: auto;
place-items: center start;
margin-top: 0.5em;
}
:root:not([data-advanced=true]) .dictionary-list {
grid-template-columns: auto auto 1fr auto auto auto;
}
.dictionary-list-index {
margin-right: 0.5em;
}
Expand Down Expand Up @@ -2329,10 +2326,6 @@ button.hotkey-list-item-enabled-button[data-scope-count='0'] {
.dictionary-item[data-enabled=false] .dictionary-title {
color: var(--text-color-light2);
}
input[type=number].dictionary-priority {
margin-top: 0;
margin-right: 0.5em;
}
.dictionary-outdated-button,
.dictionary-update-available,
.dictionary-integrity-button {
Expand Down
5 changes: 0 additions & 5 deletions ext/data/schemas/options-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,6 @@
"required": [
"name",
"alias",
"priority",
"enabled",
"allowSecondarySearches",
"definitionsCollapsible",
Expand All @@ -842,10 +841,6 @@
"type": "string",
"default": ""
},
"priority": {
"type": "number",
"default": 0
},
"enabled": {
"type": "boolean",
"default": true
Expand Down
4 changes: 1 addition & 3 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,6 @@ export class Backend {
enabledDictionaryMap.set(mainDictionary, {
index: enabledDictionaryMap.size,
alias: mainDictionary,
priority: 0,
allowSecondarySearches: false,
partsOfSpeechFilter: true,
useDeinflections: true,
Expand Down Expand Up @@ -2542,11 +2541,10 @@ export class Backend {
const enabledDictionaryMap = new Map();
for (const dictionary of options.dictionaries) {
if (!dictionary.enabled) { continue; }
const {name, alias, priority, allowSecondarySearches, partsOfSpeechFilter, useDeinflections} = dictionary;
const {name, alias, allowSecondarySearches, partsOfSpeechFilter, useDeinflections} = dictionary;
enabledDictionaryMap.set(name, {
index: enabledDictionaryMap.size,
alias,
priority,
allowSecondarySearches,
partsOfSpeechFilter,
useDeinflections,
Expand Down
21 changes: 7 additions & 14 deletions ext/js/data/anki-note-data-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,13 @@ function convertKanjiStat({name, category, content, order, score, dictionary, va
function getKanjiFrequencies(dictionaryEntry) {
/** @type {import('anki-templates').KanjiFrequency[]} */
const results = [];
for (const {index, dictionary, dictionaryAlias, dictionaryIndex, dictionaryPriority, character, frequency, displayValue} of dictionaryEntry.frequencies) {
for (const {index, dictionary, dictionaryAlias, dictionaryIndex, character, frequency, displayValue} of dictionaryEntry.frequencies) {
results.push({
index,
dictionary,
dictionaryAlias,
dictionaryOrder: {
index: dictionaryIndex,
priority: dictionaryPriority,
},
character,
frequency: displayValue !== null ? displayValue : frequency,
Expand All @@ -429,7 +428,7 @@ function getTermDefinition(dictionaryEntry, context, resultOutputMode, dictionar
case 'merge': type = 'termMerged'; break;
}

const {inflectionRuleChainCandidates, score, dictionaryIndex, dictionaryPriority, sourceTermExactMatchCount, definitions} = dictionaryEntry;
const {inflectionRuleChainCandidates, score, dictionaryIndex, sourceTermExactMatchCount, definitions} = dictionaryEntry;

let {url} = context;
if (typeof url !== 'string') { url = ''; }
Expand Down Expand Up @@ -466,7 +465,6 @@ function getTermDefinition(dictionaryEntry, context, resultOutputMode, dictionar
get dictionaryAlias() { return getCachedValue(dictionaryAliases)[0]; },
dictionaryOrder: {
index: dictionaryIndex,
priority: dictionaryPriority,
},
get dictionaryNames() { return getCachedValue(dictionaryNames); },
get expression() {
Expand Down Expand Up @@ -620,7 +618,7 @@ function addScopeToCss(css, scopeSelector) {
function getTermFrequencies(dictionaryEntry) {
const results = [];
const {headwords} = dictionaryEntry;
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, dictionaryPriority, hasReading, frequency, displayValue} of dictionaryEntry.frequencies) {
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, hasReading, frequency, displayValue} of dictionaryEntry.frequencies) {
const {term, reading} = headwords[headwordIndex];
results.push({
index: results.length,
Expand All @@ -629,7 +627,6 @@ function getTermFrequencies(dictionaryEntry) {
dictionaryAlias,
dictionaryOrder: {
index: dictionaryIndex,
priority: dictionaryPriority,
},
expression: term,
reading,
Expand All @@ -647,7 +644,7 @@ function getTermFrequencies(dictionaryEntry) {
function getTermPitches(dictionaryEntry) {
const results = [];
const {headwords} = dictionaryEntry;
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, dictionaryPriority, pronunciations} of dictionaryEntry.pronunciations) {
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, pronunciations} of dictionaryEntry.pronunciations) {
const {term, reading} = headwords[headwordIndex];
const pitches = getPronunciationsOfType(pronunciations, 'pitch-accent');
const cachedPitches = createCachedValue(getTermPitchesInner.bind(null, pitches));
Expand All @@ -658,7 +655,6 @@ function getTermPitches(dictionaryEntry) {
dictionaryAlias,
dictionaryOrder: {
index: dictionaryIndex,
priority: dictionaryPriority,
},
expression: term,
reading,
Expand Down Expand Up @@ -691,7 +687,7 @@ function getTermPitchesInner(pitches) {
function getTermPhoneticTranscriptions(dictionaryEntry) {
const results = [];
const {headwords} = dictionaryEntry;
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, dictionaryPriority, pronunciations} of dictionaryEntry.pronunciations) {
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, pronunciations} of dictionaryEntry.pronunciations) {
const {term, reading} = headwords[headwordIndex];
const phoneticTranscriptions = getPronunciationsOfType(pronunciations, 'phonetic-transcription');
const termPhoneticTranscriptions = getTermPhoneticTranscriptionsInner(phoneticTranscriptions);
Expand All @@ -702,7 +698,6 @@ function getTermPhoneticTranscriptions(dictionaryEntry) {
dictionaryAlias,
dictionaryOrder: {
index: dictionaryIndex,
priority: dictionaryPriority,
},
expression: term,
reading,
Expand Down Expand Up @@ -767,7 +762,7 @@ function getTermExpressions(dictionaryEntry) {
function getTermExpressionFrequencies(dictionaryEntry, i) {
const results = [];
const {headwords, frequencies} = dictionaryEntry;
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, dictionaryPriority, hasReading, frequency, displayValue} of frequencies) {
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, hasReading, frequency, displayValue} of frequencies) {
if (headwordIndex !== i) { continue; }
const {term, reading} = headwords[headwordIndex];
results.push({
Expand All @@ -777,7 +772,6 @@ function getTermExpressionFrequencies(dictionaryEntry, i) {
dictionaryAlias,
dictionaryOrder: {
index: dictionaryIndex,
priority: dictionaryPriority,
},
expression: term,
reading,
Expand All @@ -796,7 +790,7 @@ function getTermExpressionFrequencies(dictionaryEntry, i) {
function getTermExpressionPitches(dictionaryEntry, i) {
const results = [];
const {headwords, pronunciations: termPronunciations} = dictionaryEntry;
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, dictionaryPriority, pronunciations} of termPronunciations) {
for (const {headwordIndex, dictionary, dictionaryAlias, dictionaryIndex, pronunciations} of termPronunciations) {
if (headwordIndex !== i) { continue; }
const {term, reading} = headwords[headwordIndex];
const pitches = getPronunciationsOfType(pronunciations, 'pitch-accent');
Expand All @@ -808,7 +802,6 @@ function getTermExpressionPitches(dictionaryEntry, i) {
dictionaryAlias,
dictionaryOrder: {
index: dictionaryIndex,
priority: dictionaryPriority,
},
expression: term,
reading,
Expand Down
19 changes: 19 additions & 0 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ export class OptionsUtil {
this._updateVersion53,
this._updateVersion54,
this._updateVersion55,
this._updateVersion56,
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -1534,6 +1535,24 @@ export class OptionsUtil {
}
}

/**
* - Sorted dictionaries by priority
* - Removed priority from dictionaries
* @type {import('options-util').UpdateFunction}
*/
async _updateVersion56(options) {
for (const {options: profileOptions} of options.profiles) {
if (Array.isArray(profileOptions.dictionaries)) {
profileOptions.dictionaries.sort((/** @type {{ priority: number; }} */ a, /** @type {{ priority: number; }} */ b) => {
return b.priority - a.priority;
});
for (const dictionary of profileOptions.dictionaries) {
delete dictionary.priority;
}
}
}
}

/**
* @param {string} url
* @returns {Promise<chrome.tabs.Tab>}
Expand Down
Loading
Loading