mirror of
https://github.com/Investigamer/cardconjurer.git
synced 2025-07-26 21:04:58 -05:00
Add italic toggle button
This commit is contained in:
@@ -3907,6 +3907,36 @@ function fetchScryfallData(cardName, callback = console.log, searchUniqueArt = '
|
||||
console.log('Scryfall API search failed.')
|
||||
}
|
||||
}
|
||||
|
||||
function toggleTextTag(tag) {
|
||||
var element = document.getElementById('text-editor');
|
||||
|
||||
var text = element.value;
|
||||
|
||||
var start = element.selectionStart;
|
||||
var end = element.selectionEnd;
|
||||
var selection = text.substring(start, end);
|
||||
|
||||
var openTag = '{' + tag + '}';
|
||||
var closeTag = '{/' + tag + '}';
|
||||
|
||||
var prefix = text.substring(0, start);
|
||||
var suffix = text.substring(end);
|
||||
|
||||
if (prefix.endsWith(openTag) && suffix.startsWith(closeTag)) {
|
||||
prefix = prefix.substring(0, prefix.length-openTag.length);
|
||||
suffix = suffix.substring(closeTag.length);
|
||||
} else if (selection.startsWith(openTag) && selection.endsWith(closeTag)) {
|
||||
selection = selection.substring(openTag.length, selection.length-closeTag.length);
|
||||
} else {
|
||||
selection = openTag + selection + closeTag;
|
||||
}
|
||||
|
||||
element.value = prefix + selection + suffix;
|
||||
|
||||
textEdited();
|
||||
}
|
||||
|
||||
// INITIALIZATION
|
||||
|
||||
// auto load frame version (user defaults)
|
||||
|
@@ -123,3 +123,12 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
document.body.dispatchEvent(new Event('doCreate'));
|
||||
})
|
||||
|
||||
document.onkeyup = function(e) {
|
||||
if (document.activeElement === document.getElementById('text-editor')) {
|
||||
if (e.ctrlKey && e.which == 73) {
|
||||
toggleTextTag('i');
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user