File size: 3,145 Bytes
08c964e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
ace.define(
	'ace/ext/rtl',
	['require', 'exports', 'module', 'ace/editor', 'ace/config'],
	function (e, t, n) {
		'use strict'
		function s(e, t) {
			var n = t.getSelection().lead
			t.session.$bidiHandler.isRtlLine(n.row) &&
				n.column === 0 &&
				(t.session.$bidiHandler.isMoveLeftOperation && n.row > 0
					? t.getSelection().moveCursorTo(n.row - 1, t.session.getLine(n.row - 1).length)
					: t.getSelection().isEmpty()
					  ? (n.column += 1)
					  : n.setPosition(n.row, n.column + 1))
		}
		function o(e) {
			e.editor.session.$bidiHandler.isMoveLeftOperation =
				/gotoleft|selectleft|backspace|removewordleft/.test(e.command.name)
		}
		function u(e, t) {
			var n = t.session
			n.$bidiHandler.currentRow = null
			if (n.$bidiHandler.isRtlLine(e.start.row) && e.action === 'insert' && e.lines.length > 1)
				for (var r = e.start.row; r < e.end.row; r++)
					n.getLine(r + 1).charAt(0) !== n.$bidiHandler.RLE &&
						(n.doc.$lines[r + 1] = n.$bidiHandler.RLE + n.getLine(r + 1))
		}
		function a(e, t) {
			var n = t.session,
				r = n.$bidiHandler,
				i = t.$textLayer.$lines.cells,
				s = t.layerConfig.width - t.layerConfig.padding + 'px'
			i.forEach(function (e) {
				var t = e.element.style
				r && r.isRtlLine(e.row)
					? ((t.direction = 'rtl'), (t.textAlign = 'right'), (t.width = s))
					: ((t.direction = ''), (t.textAlign = ''), (t.width = ''))
			})
		}
		function f(e) {
			function n(e) {
				var t = e.element.style
				t.direction = t.textAlign = t.width = ''
			}
			var t = e.$textLayer.$lines
			t.cells.forEach(n), t.cellCache.forEach(n)
		}
		var r = [
				{
					name: 'leftToRight',
					bindKey: { win: 'Ctrl-Alt-Shift-L', mac: 'Command-Alt-Shift-L' },
					exec: function (e) {
						e.session.$bidiHandler.setRtlDirection(e, !1)
					},
					readOnly: !0,
				},
				{
					name: 'rightToLeft',
					bindKey: { win: 'Ctrl-Alt-Shift-R', mac: 'Command-Alt-Shift-R' },
					exec: function (e) {
						e.session.$bidiHandler.setRtlDirection(e, !0)
					},
					readOnly: !0,
				},
			],
			i = e('../editor').Editor
		e('../config').defineOptions(i.prototype, 'editor', {
			rtlText: {
				set: function (e) {
					e
						? (this.on('change', u),
						  this.on('changeSelection', s),
						  this.renderer.on('afterRender', a),
						  this.commands.on('exec', o),
						  this.commands.addCommands(r))
						: (this.off('change', u),
						  this.off('changeSelection', s),
						  this.renderer.off('afterRender', a),
						  this.commands.off('exec', o),
						  this.commands.removeCommands(r),
						  f(this.renderer)),
						this.renderer.updateFull()
				},
			},
			rtl: {
				set: function (e) {
					;(this.session.$bidiHandler.$isRtl = e),
						e
							? (this.setOption('rtlText', !1),
							  this.renderer.on('afterRender', a),
							  (this.session.$bidiHandler.seenBidi = !0))
							: (this.renderer.off('afterRender', a), f(this.renderer)),
						this.renderer.updateFull()
				},
			},
		})
	}
)
;(function () {
	ace.require(['ace/ext/rtl'], function (m) {
		if (typeof module == 'object' && typeof exports == 'object' && module) {
			module.exports = m
		}
	})
})()