-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (63 loc) · 1.55 KB
/
index.js
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
var position = require('position')
, query = require('query')
, Slider = require('slider')
module.exports = function (editor, el) {
var slider = new Slider({scale: .1})
, range = null
, changing = false
function change(number) {
console.log('gotchange', number, range)
if (!range) return
var r = editor.getSelectionRange()
, s = editor.getSelection()
, txt = number + ''
changing = true
r.setStart(range.row, range.start)
r.setEnd(range.row, range.end)
try {
console.log('set', r, txt, range)
s.setRange(r)
editor.insert(txt)
} catch (e) {
console.log('failed!', e, range, txt, number)
}
changing = false
range.end = range.start + txt.length
}
slider.on('change', change)
editor.getSession().selection.on('changeSelection', function (e) {
if (changing) return
var r = editor.getSelectionRange()
, pos = r.start
, num
if (!r.isEmpty()) {
range = null
try {
slider.hide()
} catch (e) {}
return
}
try {
num = editor.getNumberAt(pos.row, pos.column)
} catch (e) {
range = null
try {
slider.hide()
} catch (e) {}
return
}
if (!num) {
range = null
try {
slider.hide()
} catch (e) {}
return
}
console.log('got number', num)
var cursor = query('.ace_cursor', el)
range = {row: pos.row, start: num.start, end: num.end}
slider.set(parseInt(num.value, 10), true)
slider.show(cursor)
console.log('change', this, e)
})
}