Skip to content
Open
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
7 changes: 6 additions & 1 deletion src/components/moduleAppendString.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import InputCheckbox from "/src/components/inputCheckbox.svelte";
import InputText from "/src/components/inputText.svelte";
import Button from "/src/components/button.svelte";
import { pairsStore, appendToCaptions } from '/src/lib/store/GlobalStore.js';
import { pairsStore, appendToCaptions, prependToCaptions } from '/src/lib/store/GlobalStore.js';

let pairsData = [];

Expand All @@ -17,6 +17,10 @@
function handleAppendToCaptions(){
appendToCaptions(appendString, appendUseComma)
}

function handlePrependToCaptions(){
prependToCaptions(appendString, appendUseComma)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to update the input variable so it makes sense for both prepend and append action.

}
</script>
<div class="p-4 flex flex-col gap-4 items-stretch">
<!-- Search and Replace -->
Expand All @@ -26,6 +30,7 @@

<InputCheckbox bind:value={appendUseComma} label="Separate with comma"/>

<Button on:click={ handlePrependToCaptions }>Prepend</Button>
<Button on:click={ handleAppendToCaptions }>Append</Button>
</form>
</div>
22 changes: 22 additions & 0 deletions src/lib/store/GlobalStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ export const appendToCaptions = function (appendString, appendUseComma) {
}
}

///////////////////////////////////////////////////////////
/////////// Prepend to captions functionality //////////////
///////////////////////////////////////////////////////////

export const prependToCaptions = function (appendString, appendUseComma) {
for (let i = 0; i < pairsData.length; i++) {
let pair = pairsData[i];
let captionContent = pair.caption_content.replaceAll("\n", ""); // Remove all newlines to check if caption is empty
let newCaptionContent = "";

if (captionContent == "") {
newCaptionContent = "" + appendString;
}else if (appendUseComma) {
newCaptionContent = appendString + ", " + captionContent;
} else {
newCaptionContent = appendString + " " + captionContent;
}
pair.caption_content = newCaptionContent.replaceAll("\n", "");
saveCaption(pair)
}
}

////////////////////////////////////////////////////////
/////////// Search and replace functionality ///////////
////////////////////////////////////////////////////////
Expand Down
7 changes: 7 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@
appendToCaptions(string, useComma);
}

function handlePrependToCaptions(event) {
let string = event.detail.string;
let useComma = event.detail.useComma;
prependToCaptions(string, useComma);
}

function handleSaveCaption(event) {
console.log("handleSaveCaption", event.detail.pair);
let pair = event.detail.pair;
Expand Down Expand Up @@ -217,6 +223,7 @@
on:cleanCaptions={handleCleanCaption}
on:clearAllCaptions={clearAllCaptions}
on:appendToCaptions={handleAppendToCaptions}
on:prependToCaptions={handlePrependToCaptions}
on:addFilenamesToCaptions={addFilenamesToCaptions}
/>

Expand Down