@@ -1099,43 +1099,77 @@ class TextBuffer
1099
1099
# {::backwardsScan} to avoid tripping over your own changes.
1100
1100
#
1101
1101
# * `regex` A {RegExp} to search for.
1102
+ # * `options` (optional) {Object}
1103
+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1104
+ # matched line to include in the results object.
1105
+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1106
+ # matched line to include in the results object.
1102
1107
# * `iterator` A {Function} that's called on each match with an {Object}
1103
1108
# containing the following keys:
1104
1109
# * `match` The current regular expression match.
1105
1110
# * `matchText` A {String} with the text of the match.
1106
1111
# * `range` The {Range} of the match.
1107
1112
# * `stop` Call this {Function} to terminate the scan.
1108
1113
# * `replace` Call this {Function} with a {String} to replace the match.
1109
- scan : (regex , iterator ) ->
1110
- @ scanInRange (regex, @ getRange (), iterator)
1114
+ # * `leadingContextLines` An {Array} with `leadingContextLineCount` lines before the match.
1115
+ # * `trailingContextLines` An {Array} with `trailingContextLineCount` lines after the match.
1116
+ scan : (regex , options = {}, iterator ) ->
1117
+ if _ .isFunction (options)
1118
+ iterator = options
1119
+ options = {}
1120
+
1121
+ @ scanInRange (regex, @ getRange (), options, iterator)
1111
1122
1112
1123
# Public: Scan regular expression matches in the entire buffer in reverse
1113
1124
# order, calling the given iterator function on each match.
1114
1125
#
1115
1126
# * `regex` A {RegExp} to search for.
1127
+ # * `options` (optional) {Object}
1128
+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1129
+ # matched line to include in the results object.
1130
+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1131
+ # matched line to include in the results object.
1116
1132
# * `iterator` A {Function} that's called on each match with an {Object}
1117
1133
# containing the following keys:
1118
1134
# * `match` The current regular expression match.
1119
1135
# * `matchText` A {String} with the text of the match.
1120
1136
# * `range` The {Range} of the match.
1121
1137
# * `stop` Call this {Function} to terminate the scan.
1122
1138
# * `replace` Call this {Function} with a {String} to replace the match.
1123
- backwardsScan : (regex , iterator ) ->
1124
- @ backwardsScanInRange (regex, @ getRange (), iterator)
1139
+ # * `leadingContextLines` An {Array} with `leadingContextLineCount` lines before the match.
1140
+ # * `trailingContextLines` An {Array} with `trailingContextLineCount` lines after the match.
1141
+ backwardsScan : (regex , options = {}, iterator ) ->
1142
+ if _ .isFunction (options)
1143
+ iterator = options
1144
+ options = {}
1145
+
1146
+ @ backwardsScanInRange (regex, @ getRange (), options, iterator)
1125
1147
1126
1148
# Public: Scan regular expression matches in a given range , calling the given
1127
1149
# iterator function on each match.
1128
1150
#
1129
1151
# * `regex` A {RegExp} to search for.
1130
1152
# * `range` A {Range} in which to search.
1153
+ # * `options` (optional) {Object}
1154
+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1155
+ # matched line to include in the results object.
1156
+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1157
+ # matched line to include in the results object.
1131
1158
# * `callback` A {Function} that's called on each match with an {Object}
1132
1159
# containing the following keys:
1133
1160
# * `match` The current regular expression match.
1134
1161
# * `matchText` A {String} with the text of the match.
1135
1162
# * `range` The {Range} of the match.
1136
1163
# * `stop` Call this {Function} to terminate the scan.
1137
1164
# * `replace` Call this {Function} with a {String} to replace the match.
1138
- scanInRange : (regex , range , callback , reverse = false ) ->
1165
+ # * `leadingContextLines` An {Array} with `leadingContextLineCount` lines before the match.
1166
+ # * `trailingContextLines` An {Array} with `trailingContextLineCount` lines after the match.
1167
+ scanInRange : (regex , range , options = {}, callback , reverse = false ) ->
1168
+ if _ .isFunction (options)
1169
+ reverse = callback
1170
+ callback = options
1171
+ options = {}
1172
+
1139
1173
range = @ clipRange (range)
1140
1174
global = regex .global
1141
1175
flags = " gm"
@@ -1144,14 +1178,14 @@ class TextBuffer
1144
1178
1145
1179
if regexIsSingleLine (regex)
1146
1180
if reverse
1147
- iterator = new MatchIterator.BackwardsSingleLine (this , regex, range)
1181
+ iterator = new MatchIterator.BackwardsSingleLine (this , regex, range, options )
1148
1182
else
1149
- iterator = new MatchIterator.ForwardsSingleLine (this , regex, range)
1183
+ iterator = new MatchIterator.ForwardsSingleLine (this , regex, range, options )
1150
1184
else
1151
1185
if reverse
1152
- iterator = new MatchIterator.BackwardsMultiLine (this , regex, range, @backwardsScanChunkSize )
1186
+ iterator = new MatchIterator.BackwardsMultiLine (this , regex, range, @backwardsScanChunkSize , options )
1153
1187
else
1154
- iterator = new MatchIterator.ForwardsMultiLine (this , regex, range)
1188
+ iterator = new MatchIterator.ForwardsMultiLine (this , regex, range, options )
1155
1189
1156
1190
iterator .iterate (callback, global )
1157
1191
@@ -1160,15 +1194,24 @@ class TextBuffer
1160
1194
#
1161
1195
# * `regex` A {RegExp} to search for.
1162
1196
# * `range` A {Range} in which to search.
1197
+ # * `options` (optional) {Object}
1198
+ # * `leadingContextLineCount` {Number} default `0`; The number of lines before the
1199
+ # matched line to include in the results object.
1200
+ # * `trailingContextLineCount` {Number} default `0`; The number of lines after the
1201
+ # matched line to include in the results object.
1163
1202
# * `iterator` A {Function} that's called on each match with an {Object}
1164
1203
# containing the following keys:
1165
1204
# * `match` The current regular expression match.
1166
1205
# * `matchText` A {String} with the text of the match.
1167
1206
# * `range` The {Range} of the match.
1168
1207
# * `stop` Call this {Function} to terminate the scan.
1169
1208
# * `replace` Call this {Function} with a {String} to replace the match.
1170
- backwardsScanInRange : (regex , range , iterator ) ->
1171
- @ scanInRange regex, range, iterator, true
1209
+ backwardsScanInRange : (regex , range , options = {}, iterator ) ->
1210
+ if _ .isFunction (options)
1211
+ iterator = options
1212
+ options = {}
1213
+
1214
+ @ scanInRange regex, range, options, iterator, true
1172
1215
1173
1216
# Public: Replace all regular expression matches in the entire buffer.
1174
1217
#
0 commit comments