Last active
March 9, 2021 06:48
-
-
Save c3founder/31c05a70a3ed71f3057ca22ae59a284f to your computer and use it in GitHub Desktop.
Auto Text Direction for Roam Research
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*****RTL*****/ | |
.roam-block-container[data-direction*="RTL"] .rm-block-main, | |
.rm-block-children .rm-block__children .rm-level-0 .flex-h-box { | |
direction: rtl; | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-children | |
.rm-multibar{ | |
left:unset; | |
right:1px; | |
border-right:unset; | |
border-left:1px solid #BFCCD6 | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-children | |
.rm-multibar:hover{ | |
border-right:unset; | |
border-left:3px solid #5C7080 | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-main | |
.rm-caret.rm-caret-closed { | |
transform: rotate(90deg) !important; | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-children, | |
.flex-v-box { | |
margin-left: 0px !important; | |
margin-right: 20px; | |
} | |
.roam-block-container[data-direction*="RTL"] | |
.rm-emoji-block-view { | |
margin-left: 0px; | |
margin-right: 40px; | |
direction: rtl; | |
} | |
.roam-block-container[data-direction*="RTL"] | |
.rm-emoji-block-view .rm-emoji-button .rm-emoji-number { | |
height: 100%; | |
font-size: 10px; | |
margin-left: 6px; | |
margin-right: 0px; | |
font-weight: 500; | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-children | |
.block-bullet-view { | |
margin-left: 0px; | |
margin-right: 5px; | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-children, | |
.controls .rm-block__controls { | |
padding-left: 0px; | |
padding-right: 4px; | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-main, | |
.tags-output-item2 { | |
margin-left: 0px; | |
margin-right: 6px; | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-children | |
.rm-bullet--numbered-double-digit { | |
margin-left: 10px; | |
margin-right: unset; | |
} | |
.roam-block-container[data-direction*="RTL"] .rm-block-children | |
.rm-bullet--numbered-single-digit { | |
margin-left: -4px; | |
margin-right: unset; | |
} | |
/*****LTR*****/ | |
.roam-block-container[data-direction*="LTR"] .rm-block-main, | |
.rm-block-children .rm-block__children .rm-level-0 .flex-h-box { | |
direction: ltr; | |
} | |
.roam-block-container[data-page-links*="ENG"] .rm-block-children | |
.rm-multibar{ | |
right:unset; | |
left:1px; | |
border-left:unset; | |
border-right:1px solid #BFCCD6 | |
} | |
.roam-block-container[data-page-links*="ENG"] .rm-block-children | |
.rm-multibar:hover{ | |
border-left:unset; | |
border-right:3px solid #5C7080 | |
} | |
.roam-block-container[data-direction*="LTR"] .rm-block-main | |
.rm-caret.rm-caret-closed { | |
transform: rotate(-90deg) !important; | |
} | |
.roam-block-container[data-direction*="LTR"] .rm-block-children, | |
.flex-v-box { | |
margin-left: 20px; | |
margin-right: 0px !important; | |
} | |
.roam-block-container[data-direction*="LTR"] | |
.rm-emoji-block-view { | |
margin-left: 40px; | |
margin-right: 0px; | |
direction: ltr; | |
} | |
.roam-block-container[data-direction*="LTR"] | |
.rm-emoji-block-view .rm-emoji-button .rm-emoji-number { | |
height: 100%; | |
font-size: 10px; | |
margin-left: 0px; | |
margin-right: 6px; | |
font-weight: 500; | |
} | |
.roam-block-container[data-direction*="LTR"] .rm-block-children | |
.block-bullet-view { | |
margin-left: 5px; | |
margin-right: 0px; | |
} | |
.roam-block-container[data-direction*="LTR"] .rm-block-children, | |
.controls .rm-block__controls { | |
padding-left: 4px; | |
padding-right: 0px; | |
} | |
.roam-block-container[data-direction*="LTR"] .rm-block-main, | |
.tags-output-item2 { | |
margin-left: 6px; | |
margin-right: 0px; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isRTL(s){ | |
var ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF'+'\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF', | |
rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC', | |
rtlDirCheck = new RegExp('^[^'+ltrChars+']*['+rtlChars+']'); | |
return rtlDirCheck.test(s); | |
}; | |
const activateAutoDir = () => { | |
if(typeof(document) == 'undefined') return; | |
Array.from(document.querySelectorAll("div.rm-block__input > span")) | |
.forEach(txtEl => { | |
var content = txtEl.textContent; | |
if(content.length > 0){ | |
var container = txtEl.closest('.roam-block-container') | |
var newContent = content.replace(/[\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]*/gi, ''); | |
if(isRTL(newContent[0])){ | |
container.dataset.direction = "RTL"; | |
} else { | |
container.dataset.direction = "LTR"; | |
} | |
} | |
} | |
); | |
var txtEl = document.querySelector("textarea"); | |
if(txtEl != null){ | |
var content = txtEl.value; | |
var newContent = content.replace(/[\x20-\x2f\x3a-\x40\x5b-\x60\x7b-\x7e]*/gi, ''); | |
if(isRTL(newContent[0])){ | |
txtEl.closest('.roam-block-container').dataset.direction = "RTL"; | |
} else { | |
txtEl.closest('.roam-block-container').dataset.direction = "LTR"; | |
} | |
} | |
} | |
setInterval(activateAutoDir, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This eases the mixture of RTL and LFR and oh my! how I needed such a thing