3
3
4
4
import { forLines } from "./scopes"
5
5
6
- export function getLine ( ed , l ) {
6
+ export function getLine ( editor , l ) {
7
7
return {
8
- scope : ed . scopeDescriptorForBufferPosition ( [ l , 0 ] ) . scopes ,
9
- line : ed . getTextInBufferRange ( [
8
+ scope : editor . scopeDescriptorForBufferPosition ( [ l , 0 ] ) . scopes ,
9
+ line : editor . getTextInBufferRange ( [
10
10
[ l , 0 ] ,
11
11
[ l , Infinity ]
12
12
] )
@@ -43,19 +43,19 @@ function isStart(lineInfo) {
43
43
return ! ( / ^ \s / . test ( lineInfo . line ) || isBlank ( lineInfo ) || isEnd ( lineInfo ) || isCont ( lineInfo ) )
44
44
}
45
45
46
- function walkBack ( ed , row ) {
47
- while ( row > 0 && ! isStart ( getLine ( ed , row ) ) ) {
46
+ function walkBack ( editor , row ) {
47
+ while ( row > 0 && ! isStart ( getLine ( editor , row ) ) ) {
48
48
row --
49
49
}
50
50
return row
51
51
}
52
52
53
- function walkForward ( ed , start ) {
53
+ function walkForward ( editor , start ) {
54
54
let end = start
55
55
let mark = start
56
- while ( mark < ed . getLastBufferRow ( ) ) {
56
+ while ( mark < editor . getLastBufferRow ( ) ) {
57
57
mark ++
58
- const lineInfo = getLine ( ed , mark )
58
+ const lineInfo = getLine ( editor , mark )
59
59
60
60
if ( isStart ( lineInfo ) ) {
61
61
break
@@ -64,7 +64,7 @@ function walkForward(ed, start) {
64
64
// An `end` only counts when there still are unclosed blocks (indicated by `forLines`
65
65
// returning a non-empty array).
66
66
// If the line closes a multiline string we also take that as ending the block.
67
- if ( ! ( forLines ( ed , start , mark - 1 ) . length === 0 ) || isStringEnd ( lineInfo ) ) {
67
+ if ( ! ( forLines ( editor , start , mark - 1 ) . length === 0 ) || isStringEnd ( lineInfo ) ) {
68
68
end = mark
69
69
}
70
70
} else if ( ! ( isBlank ( lineInfo ) || isStart ( lineInfo ) ) ) {
@@ -74,9 +74,9 @@ function walkForward(ed, start) {
74
74
return end
75
75
}
76
76
77
- function getRange ( ed , row ) {
78
- const start = walkBack ( ed , row )
79
- const end = walkForward ( ed , start )
77
+ function getRange ( editor , row ) {
78
+ const start = walkBack ( editor , row )
79
+ const end = walkForward ( editor , start )
80
80
if ( start <= row && row <= end ) {
81
81
return [
82
82
[ start , 0 ] ,
@@ -85,29 +85,29 @@ function getRange(ed, row) {
85
85
}
86
86
}
87
87
88
- function getSelection ( ed , sel ) {
88
+ function getSelection ( editor , sel ) {
89
89
const { start, end } = sel . getBufferRange ( )
90
90
const range = [
91
91
[ start . row , start . column ] ,
92
92
[ end . row , end . column ]
93
93
]
94
- while ( isBlank ( getLine ( ed , range [ 0 ] [ 0 ] ) , true ) && range [ 0 ] [ 0 ] <= range [ 1 ] [ 0 ] ) {
94
+ while ( isBlank ( getLine ( editor , range [ 0 ] [ 0 ] ) , true ) && range [ 0 ] [ 0 ] <= range [ 1 ] [ 0 ] ) {
95
95
range [ 0 ] [ 0 ] ++
96
96
range [ 0 ] [ 1 ] = 0
97
97
}
98
- while ( isBlank ( getLine ( ed , range [ 1 ] [ 0 ] ) , true ) && range [ 1 ] [ 0 ] >= range [ 0 ] [ 0 ] ) {
98
+ while ( isBlank ( getLine ( editor , range [ 1 ] [ 0 ] ) , true ) && range [ 1 ] [ 0 ] >= range [ 0 ] [ 0 ] ) {
99
99
range [ 1 ] [ 0 ] --
100
100
range [ 1 ] [ 1 ] = Infinity
101
101
}
102
102
return range
103
103
}
104
104
105
- export function moveNext ( ed , sel , range ) {
105
+ export function moveNext ( editor , sel , range ) {
106
106
// Ensure enough room at the end of the buffer
107
107
const row = range [ 1 ] [ 0 ]
108
108
let last
109
- while ( ( last = ed . getLastBufferRow ( ) ) < row + 2 ) {
110
- if ( last !== row && ! isBlank ( getLine ( ed , last ) ) ) {
109
+ while ( ( last = editor . getLastBufferRow ( ) ) < row + 2 ) {
110
+ if ( last !== row && ! isBlank ( getLine ( editor , last ) ) ) {
111
111
break
112
112
}
113
113
sel . setBufferRange ( [
@@ -118,35 +118,35 @@ export function moveNext(ed, sel, range) {
118
118
}
119
119
// Move the cursor
120
120
let to = row + 1
121
- while ( to < ed . getLastBufferRow ( ) && isBlank ( getLine ( ed , to ) ) ) {
121
+ while ( to < editor . getLastBufferRow ( ) && isBlank ( getLine ( editor , to ) ) ) {
122
122
to ++
123
123
}
124
- to = walkForward ( ed , to )
124
+ to = walkForward ( editor , to )
125
125
return sel . setBufferRange ( [
126
126
[ to , Infinity ] ,
127
127
[ to , Infinity ]
128
128
] )
129
129
}
130
130
131
- function getRanges ( ed ) {
132
- const ranges = ed . getSelections ( ) . map ( sel => {
131
+ function getRanges ( editor ) {
132
+ const ranges = editor . getSelections ( ) . map ( sel => {
133
133
return {
134
134
selection : sel ,
135
- range : sel . isEmpty ( ) ? getRange ( ed , sel . getHeadBufferPosition ( ) . row ) : getSelection ( ed , sel )
135
+ range : sel . isEmpty ( ) ? getRange ( editor , sel . getHeadBufferPosition ( ) . row ) : getSelection ( editor , sel )
136
136
}
137
137
} )
138
138
return ranges . filter ( ( { range } ) => {
139
- return range && ed . getTextInBufferRange ( range ) . trim ( )
139
+ return range && editor . getTextInBufferRange ( range ) . trim ( )
140
140
} )
141
141
}
142
142
143
- export function get ( ed ) {
144
- return getRanges ( ed ) . map ( ( { range, selection } ) => {
143
+ export function get ( editor ) {
144
+ return getRanges ( editor ) . map ( ( { range, selection } ) => {
145
145
return {
146
146
range,
147
147
selection,
148
148
line : range [ 0 ] [ 0 ] ,
149
- text : ed . getTextInBufferRange ( range )
149
+ text : editor . getTextInBufferRange ( range )
150
150
}
151
151
} )
152
152
}
@@ -165,10 +165,10 @@ export function getLocalContext(editor, row) {
165
165
}
166
166
}
167
167
168
- export function select ( ed = atom . workspace . getActiveTextEditor ( ) ) {
169
- if ( ! ed ) return
170
- return ed . mutateSelectedText ( selection => {
171
- const range = getRange ( ed , selection . getHeadBufferPosition ( ) . row )
168
+ export function select ( editor = atom . workspace . getActiveTextEditor ( ) ) {
169
+ if ( ! editor ) return
170
+ return editor . mutateSelectedText ( selection => {
171
+ const range = getRange ( editor , selection . getHeadBufferPosition ( ) . row )
172
172
if ( range ) {
173
173
selection . setBufferRange ( range )
174
174
}
0 commit comments