summaryrefslogtreecommitdiff
path: root/src/ui/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/util.c')
-rw-r--r--src/ui/util.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ui/util.c b/src/ui/util.c
index cb9006f6..8074223b 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -164,6 +164,60 @@ iRangei union_Rangei(iRangei a, iRangei b) {
164 return (iRangei){ iMin(a.start, b.start), iMax(a.end, b.end) }; 164 return (iRangei){ iMin(a.start, b.start), iMax(a.end, b.end) };
165} 165}
166 166
167static iBool isSelectionBreakingChar_(iChar c) {
168 return isSpace_Char(c) || (c == '@' || c == '-' || c == '/' || c == '\\' || c == ',');
169}
170
171static const char *moveBackward_(const char *pos, iRangecc bounds, int mode) {
172 iChar ch;
173 while (pos > bounds.start) {
174 int len = decodePrecedingBytes_MultibyteChar(pos, bounds.start, &ch);
175 if (len > 0) {
176 if (mode & word_RangeExtension && isSelectionBreakingChar_(ch)) break;
177 if (mode & line_RangeExtension && ch == '\n') break;
178 pos -= len;
179 }
180 else break;
181 }
182 return pos;
183}
184
185static const char *moveForward_(const char *pos, iRangecc bounds, int mode) {
186 iChar ch;
187 while (pos < bounds.end) {
188 int len = decodeBytes_MultibyteChar(pos, bounds.end, &ch);
189 if (len > 0) {
190 if (mode & word_RangeExtension && isSelectionBreakingChar_(ch)) break;
191 if (mode & line_RangeExtension && ch == '\n') break;
192 pos += len;
193 }
194 else break;
195 }
196 return pos;
197}
198
199void extendRange_Rangecc(iRangecc *d, iRangecc bounds, int mode) {
200 if (!d->start) return;
201 if (d->end >= d->start) {
202 if (mode & bothStartAndEnd_RangeExtension) {
203 d->start = moveBackward_(d->start, bounds, mode);
204 d->end = moveForward_(d->end, bounds, mode);
205 }
206 else {
207 d->end = moveForward_(d->end, bounds, mode);
208 }
209 }
210 else {
211 if (mode & bothStartAndEnd_RangeExtension) {
212 d->start = moveForward_(d->start, bounds, mode);
213 d->end = moveBackward_(d->end, bounds, mode);
214 }
215 else {
216 d->end = moveBackward_(d->end, bounds, mode);
217 }
218 }
219}
220
167/*----------------------------------------------------------------------------------------------*/ 221/*----------------------------------------------------------------------------------------------*/
168 222
169iBool isFinished_Anim(const iAnim *d) { 223iBool isFinished_Anim(const iAnim *d) {