Skip to content

Commit

Permalink
Backport improved suggestions & scroll into view
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenny-Hui committed Aug 10, 2024
1 parent f3b9891 commit 78d1e75
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
9 changes: 8 additions & 1 deletion src/components/layout/FileEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { projects, selectedFile, selectedUnit } from '../../stores/data';
import { forEachBlocking, getUnit } from '../../../lib/util';
import Tooltip from '../shared/Tooltip.svelte';
import { onMount } from 'svelte';
export let file: TranslationFile;
$: canShowSource = $preferences.langSelect.displayMode == 'src' || $preferences.langSelect.displayMode == 'both';
Expand Down Expand Up @@ -62,9 +63,15 @@
$: if($selectedFile && file) checkTranslatedUnits();
$: percentage = totalUnit == 0 ? 1 : (translatedUnit / totalUnit);
let btn;
onMount(() => {
if($selectedFile === file) btn.scrollIntoView(false); // Ensure visible
});
</script>

<button on:click={() => select()} on:keydown={() => select()} class:selected={$selectedFile === file}>
<button bind:this={btn} on:click={() => select()} on:keydown={() => select()} class:selected={$selectedFile === file}>
<div>
{#if canShowSource}
{getLangName(displayFileName, file.sourceLanguage)}
Expand Down
9 changes: 8 additions & 1 deletion src/components/layout/editor/listing/UnitRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { DialogProperty } from "../../../../utils/types";
import MoveUnitDialog from "../../../overlay/dialogs/MoveUnitDialog.svelte";
import { findGroup } from "../../../../../lib/util";
import { onMount } from "svelte";
export let unit: Unit;
function openMoveDialog() {
Expand All @@ -29,9 +30,15 @@
}
$selectedFile = $selectedFile;
}
let btn;
onMount(() => {
if($selectedUnit === unit) btn.scrollIntoView(false); // Ensure visible
});
</script>

<button class="container" class:active={$selectedUnit == unit} on:click={() => $selectedUnit = unit}>
<button bind:this={btn} class="container" class:active={$selectedUnit == unit} on:click={() => $selectedUnit = unit}>
<div class="translate-status">
<Tooltip tooltip="{unit.target == "" ? "Not " : ""}Translated">
<span class="status" class:translated={unit.target != ""}></span>
Expand Down
22 changes: 7 additions & 15 deletions src/components/layout/editor/subpane/SuggestionPane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,15 @@
}
function sortSuggestions(arr: any[]) {
// Speghetti code, don't ask me why this works, I tried reworking it but it no work.
let targetLanguage = selectedFile.targetLanguage ?? selectedFile.sourceLanguage;
arr.sort((a, b) => {
let targetLanguage = selectedFile.targetLanguage ?? selectedFile.sourceLanguage;
let point = 0;
let aMatchedPath = a.unit.getFullPathStr() == $selectedUnit.getFullPathStr() ? -1 : 0;
let bMatchedPath = b.unit.getFullPathStr() == $selectedUnit.getFullPathStr() ? 1 : 0;
let aMatchedId = a.unit.id == $selectedUnit.id ? -1 : 0;
let bMatchedId = b.unit.id == $selectedUnit.id ? 1 : 0;
let aSameLangGroup = a.lang.targetLanguage == null ? 0 : a.lang.targetLanguage.split("-")[0] == targetLanguage.split("-")[0] ? -1 : 0;
let aSamePath = a.unit.getFullPathStr() == $selectedUnit.getFullPathStr() ? 1 : 0;
let bSamePath = b.unit.getFullPathStr() == $selectedUnit.getFullPathStr() ? 1 : 0;
let aSameLang = a.lang?.targetLanguage == targetLanguage ? 1 : 0;
let bSameLang = b.lang?.targetLanguage == targetLanguage ? 1 : 0;
let aSameLangGroup = a.lang.targetLanguage == null ? 0 : a.lang.targetLanguage.split("-")[0] == targetLanguage.split("-")[0] ? 1 : 0;
let bSameLangGroup = b.lang.targetLanguage == null ? 0 : b.lang.targetLanguage.split("-")[0] == targetLanguage.split("-")[0] ? 1 : 0;
point += b.match > a.match ? 1 : b.match == a.match ? 0 : -1;
point += aSameLangGroup + bSameLangGroup + aMatchedId + bMatchedId + aMatchedPath + bMatchedPath;
point += ((a.lang.targetLanguage != null && b.lang.targetLanguage != null) && a.lang.targetLanguage.split("-")[0] == b.lang.targetLanguage.split("-")[0]) ? 1 : 0; // Match primary subtag
return point;
return (bSameLang - aSameLang) || (bSameLangGroup - aSameLangGroup) || (bSamePath - aSamePath) || (b.match - a.match);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/stores/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const VERSION = "0.4.1";
const VERSION = "0.4.2";

export default {
VERSION: VERSION
Expand Down

0 comments on commit 78d1e75

Please sign in to comment.