Skip to content

Commit

Permalink
Don’t put unneeded CGJs in the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
dscorbett committed Aug 14, 2024
1 parent 33ceddb commit 971e7b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 2 additions & 6 deletions assets/js/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
*/

import transliterate0 from "./transliterate.js";
import serializeParameters from "./state.js";
import serializeParameters, { protectWhiteSpace, unprotectWhiteSpace } from "./state.js";

const autotransliteration = document.querySelector('#autotransliteration');
const autosyllabification = document.querySelector('#autosyllabification');
Expand Down Expand Up @@ -55,10 +55,6 @@ window.addEventListener('load', () => {
});
});

function protectWhiteSpace(text) {
return text.replaceAll(/[\t\n\r ]/g, '$&\u034F\u034F\u034F');
}

function extract(node) {
function extract(node) {
return [...node.childNodes].reduce(
Expand Down Expand Up @@ -224,7 +220,7 @@ autosyllabification.addEventListener('change', serializeParameters);
function copyOrCut(e) {
e.preventDefault();
const selection = window.getSelection();
e.clipboardData.setData('text/plain', selection.toString().replaceAll(/(^|[\t\n\r ])\u034F\u034F\u034F/g, '$1'));
e.clipboardData.setData('text/plain', unprotectWhiteSpace(selection.toString()));
if (e.type === 'cut') {
selection.deleteFromDocument();
}
Expand Down
12 changes: 10 additions & 2 deletions assets/js/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function deserializeParameters() {
const boldParam = url.searchParams.get('b');
const decorationParam = url.searchParams.get('d');
if (textContentParam !== null) {
output.textContent = textContentParam;
output.textContent = protectWhiteSpace(textContentParam);
}
if (noAutotransliterationParam !== null) {
autotransliteration.checked = !noAutotransliterationParam;
Expand All @@ -55,7 +55,7 @@ function serializeParameters() {
const url = new URL(window.location);
url.search = '';
if (output.textContent) {
url.searchParams.set('t', output.textContent);
url.searchParams.set('t', unprotectWhiteSpace(output.textContent));
}
if (!autotransliteration.checked) {
url.searchParams.set('T', '1');
Expand All @@ -71,3 +71,11 @@ function serializeParameters() {
}
window.history.replaceState(null, '', url);
}

export function protectWhiteSpace(text) {
return text.replaceAll(/[\t\n\r ]\u034F*/g, '$&\u034F\u034F\u034F');
}

export function unprotectWhiteSpace(text) {
return text.replaceAll(/(^|[\t\n\r ])\u034F+/g, '$1');
}

0 comments on commit 971e7b2

Please sign in to comment.