Skip to content

Instantly share code, notes, and snippets.

@oriadam
Last active April 25, 2022 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oriadam/df53f89cd371aa296fc11fdce90956d5 to your computer and use it in GitHub Desktop.
Save oriadam/df53f89cd371aa296fc11fdce90956d5 to your computer and use it in GitHub Desktop.
support rtl in coda
// ==UserScript==
// @name support rtl in coda
// @namespace http://tampermonkey.net/
// @version 8
// @author Oria
// @match https://coda.io/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// remove the custom selection highlight and bring back the browser's
GM_addStyle(`data-editable-id="editor-caret-selection"] { display: none !important; }
::selection { background-color: #bbf5 !important; }
.rightify { position: absolute; right: -60px;}
.kr-cell .rightify { right: -30px; }
.kr-cell .kr-olist, .kr-cell .kr-ulist { margin-right: 30px; }
`);
const elemRTL = elem => /^\W*[\u0591-\u07FF]/.test(elem.innerText);
const magic = function(){
document.querySelectorAll('.kr-span').
forEach(x=>x.setAttribute('dir','auto'));
// move the ... context menu to the far right
// document.querySelectorAll('[data-editable-ignore-node="true"]:not([style]) [data-transparent-container-forward-to-first-child="true"] .kr-icon').
// forEach(x=>x.closest('[data-editable-ignore-node="true"]').
// setAttribute('style','position: absolute;right: -37px;'));
// make the containers rtl so that the cursor will be in the correct location
document.querySelectorAll('.kr-line,.kr-paragraph').
forEach(x=>{
if (elemRTL(x))
{
x.style.direction = 'rtl';
const child = x.querySelector('[data-editable-ignore-node="true"]:first-child:not(.rightify)');
if (child)
{
child.classList.add('rightify');
if (child.children.length)
child.children[0].style.transform = 'none';
}
}
});
}
setInterval(magic, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment