This repository was archived by the owner on Nov 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathSelection.vala
More file actions
100 lines (90 loc) · 2.71 KB
/
Copy pathSelection.vala
File metadata and controls
100 lines (90 loc) · 2.71 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright © 2013–2014 Philipp Emanuel Weidmann <pew@worldwidemann.com>
*
* Nemo vir est qui mundum non reddat meliorem.
*
*
* This file is part of Final Term.
*
* Final Term is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Final Term is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Final Term. If not, see <http://www.gnu.org/licenses/>.
*/
public class Selection {
private TerminalOutput.CursorPosition start;
private TerminalOutput.CursorPosition finish;
public enum SelectionMode {
NORMAL,
WORD,
LINE,
COLUMN // Does not work
}
public SelectionMode mode {get; set;}
public Selection(TerminalOutput.CursorPosition position, SelectionMode mode) {
start = position;
this.mode = mode;
if(this.mode == SelectionMode.LINE) {
start.column = 0;
finish = start;
finish.column = 1;
}
}
public void update(TerminalOutput.CursorPosition position) {
finish = position;
}
public void get_line_range(int line, out int from, out int to) {
TerminalOutput.CursorPosition beginning = TerminalOutput.CursorPosition();
TerminalOutput.CursorPosition end = TerminalOutput.CursorPosition();
get_range(out beginning, out end);
from = to = 0;
if (mode == SelectionMode.COLUMN) {
if (line >= beginning.line && line <= end.line) {
from = int.min(beginning.column, end.column);
to = int.max(beginning.column, end.column);
}
} else if (mode == SelectionMode.WORD) {
if (line == beginning.line) {
from = beginning.column;
}
if (line >= beginning.line && line < end.line) {
to = -1;
} else if (line == end.line) {
to = end.column;
}
} else if (mode == SelectionMode.LINE) {
if (line >= beginning.line && line <= end.line) {
from = 0;
to = -1;
}
} else {
if (line == beginning.line) {
from = beginning.column;
}
if (line >= beginning.line && line < end.line) {
to = -1;
} else if (line == end.line) {
to = end.column;
}
}
}
// end position can be before or after start position
// this function returns them in correct order
public void get_range(out TerminalOutput.CursorPosition beginning, out TerminalOutput.CursorPosition end) {
if (start.compare(finish) > 0) {
beginning = finish;
end = start;
} else {
beginning = start;
end = finish;
}
}
}