]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | True = 1 |
2 | False = 0 | |
3 | ||
4 | def RestOfLine(sx, width, data, bool): | |
5 | if len(data) == 0 and sx == 0: | |
6 | return [('', bool)] | |
7 | if sx >= len(data): | |
8 | return [] | |
9 | return [(data[sx:sx+width], bool)] | |
10 | ||
11 | def Selection(SelectBegin,SelectEnd, sx, width, line, data): | |
12 | if SelectEnd is None or SelectBegin is None: | |
13 | return RestOfLine(sx, width, data, False) | |
14 | (bRow, bCol) = SelectBegin | |
15 | (eRow, eCol) = SelectEnd | |
16 | if (eRow < bRow): | |
17 | (bRow, bCol) = SelectEnd | |
18 | (eRow, eCol) = SelectBegin | |
19 | if (line < bRow or eRow < line): | |
20 | return RestOfLine(sx, width, data, False) | |
21 | if (bRow < line and line < eRow): | |
22 | return RestOfLine(sx, width, data, True) | |
23 | if (bRow == eRow) and (eCol < bCol): | |
24 | (bCol, eCol) = (eCol, bCol) | |
25 | # selection either starts or ends on this line | |
26 | end = min(sx+width, len(data)) | |
27 | if (bRow < line): | |
28 | bCol = 0 | |
29 | if (line < eRow): | |
30 | eCol = end | |
31 | pieces = [] | |
32 | if (sx < bCol): | |
33 | if bCol <= end: | |
34 | pieces += [(data[sx:bCol], False)] | |
35 | else: | |
36 | return [(data[sx:end], False)] | |
37 | pieces += [(data[max(bCol,sx):min(eCol,end)], True)] | |
38 | if (eCol < end): | |
39 | pieces += [(data[eCol:end], False)] | |
40 | return pieces | |
1fded56b | 41 | |
1fded56b | 42 |