Until we either get formal RTL support or the formal plugin API, here’s a hacky Volcano plugin for RTL/LTR switching.
It adds a global command “Switch Document Direction” which can be mapped to a key.
It’s probably not perfect and there’s plenty of room for improvement, but maybe it will be useful for some.
(to be saved as rtl.js
under ~/volcano/plugins
after installing Volcano)
class RTLPlugin {
constructor() {
this.id = 'rtl'
this.name = 'RTL plugin'
this.description = 'RTL support for Obsidian.'
this.defaultOn = true // Whether or not to enable the plugin on load
}
init(app, instance) {
console.log('RTL plugin is initializing!')
this.app = app
this.instance = instance
this.enabled = false
this.instance.registerGlobalCommand({
id: 'switch_direction',
name: 'Switch Document Direction',
callback: () => this.switchDocumentDirection()
})
}
onEnable(app, instance) {
console.log('RTL support is now enabled')
this.enabled = true
}
onDisable(app, instance) {
console.log('RTL support is now disabled')
this.enabled = false
}
switchDocumentDirection() {
if (this.enabled) {
var cmEditor = this.app.workspace.activeLeaf.view.currentMode.cmEditor
if (cmEditor) {
var newDirection = cmEditor.getOption("direction") == "ltr" ? "rtl" : "ltr"
cmEditor.setOption("direction", newDirection)
}
}
}
}
module.exports = () => new RTLPlugin()