-
Notifications
You must be signed in to change notification settings - Fork 64
/
rtl.py
32 lines (24 loc) · 821 Bytes
/
rtl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sublime, sublime_plugin, sys
sys.path.append( 'bidi' )
try:
# Python 3
from .bidi.arabic_reshaper import reshape
from .bidi.algorithm import get_display
except ValueError:
# Python 2
from bidi.arabic_reshaper import reshape
from bidi.algorithm import get_display
class bidiCommand(sublime_plugin.TextCommand):
def run(self, edit):
region = sublime.Region(0, self.view.size())
bidiRegion(region, self.view, edit)
class bidiselectionCommand(sublime_plugin.TextCommand):
def run(self, edit):
selectionSet = self.view.sel()
for selectionRegion in selectionSet:
bidiRegion(selectionRegion, self.view, edit)
def bidiRegion(region, view, edit):
txt = view.substr(region)
reshaped_text = reshape(txt)
bdiText = get_display(reshaped_text)
view.replace(edit, region, bdiText)