Changeset View
Changeset View
Standalone View
Standalone View
tools/selection/text/kpToolText_CursorCalc.cpp
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
63 | { | 63 | { | ||
64 | return (cursorRow == 0 && cursorCol == 0); | 64 | return (cursorRow == 0 && cursorCol == 0); | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | // protected static | 67 | // protected static | ||
68 | bool kpToolText::CursorIsAtEnd (const QList <QString> &textLines, | 68 | bool kpToolText::CursorIsAtEnd (const QList <QString> &textLines, | ||
69 | int cursorRow, int cursorCol) | 69 | int cursorRow, int cursorCol) | ||
70 | { | 70 | { | ||
71 | if (textLines.isEmpty ()) | 71 | if (textLines.isEmpty ()) { | ||
72 | return (cursorRow == 0 && cursorCol == 0); | 72 | return (cursorRow == 0 && cursorCol == 0); | ||
73 | } | ||||
73 | 74 | | |||
74 | return (cursorRow == textLines.size () - 1 && | 75 | return (cursorRow == textLines.size () - 1 && | ||
75 | cursorCol == textLines [cursorRow].length ()); | 76 | cursorCol == textLines [cursorRow].length ()); | ||
76 | } | 77 | } | ||
77 | 78 | | |||
78 | 79 | | |||
79 | // protected static | 80 | // protected static | ||
80 | void kpToolText::MoveCursorLeft (const QList <QString> &textLines, | 81 | void kpToolText::MoveCursorLeft (const QList <QString> &textLines, | ||
81 | int *cursorRow, int *cursorCol) | 82 | int *cursorRow, int *cursorCol) | ||
82 | { | 83 | { | ||
83 | if (textLines.isEmpty ()) | 84 | if (textLines.isEmpty ()) { | ||
84 | return; | 85 | return; | ||
86 | } | ||||
85 | 87 | | |||
86 | (*cursorCol)--; | 88 | (*cursorCol)--; | ||
87 | 89 | | |||
88 | if (*cursorCol < 0) | 90 | if (*cursorCol < 0) | ||
89 | { | 91 | { | ||
90 | (*cursorRow)--; | 92 | (*cursorRow)--; | ||
91 | if (*cursorRow < 0) | 93 | if (*cursorRow < 0) | ||
92 | { | 94 | { | ||
93 | *cursorRow = 0; | 95 | *cursorRow = 0; | ||
94 | *cursorCol = 0; | 96 | *cursorCol = 0; | ||
95 | } | 97 | } | ||
96 | else | 98 | else { | ||
97 | *cursorCol = textLines [*cursorRow].length (); | 99 | *cursorCol = textLines [*cursorRow].length (); | ||
98 | } | 100 | } | ||
99 | } | 101 | } | ||
102 | } | ||||
100 | 103 | | |||
101 | // protected static | 104 | // protected static | ||
102 | void kpToolText::MoveCursorRight (const QList <QString> &textLines, | 105 | void kpToolText::MoveCursorRight (const QList <QString> &textLines, | ||
103 | int *cursorRow, int *cursorCol) | 106 | int *cursorRow, int *cursorCol) | ||
104 | { | 107 | { | ||
105 | if (textLines.isEmpty ()) | 108 | if (textLines.isEmpty ()) { | ||
106 | return; | 109 | return; | ||
110 | } | ||||
107 | 111 | | |||
108 | (*cursorCol)++; | 112 | (*cursorCol)++; | ||
109 | 113 | | |||
110 | if (*cursorCol > textLines [*cursorRow].length ()) | 114 | if (*cursorCol > textLines [*cursorRow].length ()) | ||
111 | { | 115 | { | ||
112 | (*cursorRow)++; | 116 | (*cursorRow)++; | ||
113 | if (*cursorRow > textLines.size () - 1) | 117 | if (*cursorRow > textLines.size () - 1) | ||
114 | { | 118 | { | ||
115 | *cursorRow = textLines.size () - 1; | 119 | *cursorRow = textLines.size () - 1; | ||
116 | *cursorCol = textLines [*cursorRow].length (); | 120 | *cursorCol = textLines [*cursorRow].length (); | ||
117 | } | 121 | } | ||
118 | else | 122 | else { | ||
119 | *cursorCol = 0; | 123 | *cursorCol = 0; | ||
120 | } | 124 | } | ||
121 | } | 125 | } | ||
126 | } | ||||
122 | 127 | | |||
123 | 128 | | |||
124 | #define IS_ON_SPACE_OR_EOL() !CursorIsOnWordChar (textLines, *cursorRow, *cursorCol) | 129 | #define IS_ON_SPACE_OR_EOL() !CursorIsOnWordChar (textLines, *cursorRow, *cursorCol) | ||
125 | 130 | | |||
126 | // protected static | 131 | // protected static | ||
127 | int kpToolText::MoveCursorToWordStart (const QList <QString> &textLines, | 132 | int kpToolText::MoveCursorToWordStart (const QList <QString> &textLines, | ||
128 | int *cursorRow, int *cursorCol) | 133 | int *cursorRow, int *cursorCol) | ||
129 | { | 134 | { | ||
130 | if (textLines.isEmpty ()) | 135 | if (textLines.isEmpty ()) { | ||
131 | return 0; | 136 | return 0; | ||
137 | } | ||||
132 | 138 | | |||
133 | int numMoves = 0; | 139 | int numMoves = 0; | ||
134 | 140 | | |||
135 | #define IS_ON_ANCHOR() \ | 141 | #define IS_ON_ANCHOR() \ | ||
136 | (CursorIsOnWordChar (textLines, *cursorRow, *cursorCol) && \ | 142 | (CursorIsOnWordChar (textLines, *cursorRow, *cursorCol) && \ | ||
137 | (cursorCol == 0 || \ | 143 | (cursorCol == 0 || \ | ||
138 | !CursorIsOnWordChar (textLines, *cursorRow, *cursorCol - 1))) | 144 | !CursorIsOnWordChar (textLines, *cursorRow, *cursorCol - 1))) | ||
139 | #define MOVE_CURSOR_LEFT() \ | 145 | #define MOVE_CURSOR_LEFT() \ | ||
140 | (MoveCursorLeft (textLines, cursorRow, cursorCol), ++numMoves) | 146 | (MoveCursorLeft (textLines, cursorRow, cursorCol), ++numMoves) | ||
141 | 147 | | |||
142 | 148 | | |||
143 | // (these comments will exclude the row=0,col=0 boundary case) | 149 | // (these comments will exclude the row=0,col=0 boundary case) | ||
144 | 150 | | |||
145 | if (IS_ON_ANCHOR ()) | 151 | if (IS_ON_ANCHOR ()) { | ||
146 | MOVE_CURSOR_LEFT (); | 152 | MOVE_CURSOR_LEFT (); | ||
153 | } | ||||
147 | 154 | | |||
148 | // --- now we're not on an anchor point (start of word) --- | 155 | // --- now we're not on an anchor point (start of word) --- | ||
149 | 156 | | |||
150 | // End up on a letter... | 157 | // End up on a letter... | ||
151 | while (!(*cursorRow == 0 && *cursorCol == 0) && | 158 | while (!(*cursorRow == 0 && *cursorCol == 0) && | ||
152 | (IS_ON_SPACE_OR_EOL ())) | 159 | (IS_ON_SPACE_OR_EOL ())) | ||
153 | { | 160 | { | ||
154 | MOVE_CURSOR_LEFT (); | 161 | MOVE_CURSOR_LEFT (); | ||
Show All 13 Lines | 174 | #undef MOVE_CURSOR_LEFT | |||
168 | 175 | | |||
169 | return numMoves; | 176 | return numMoves; | ||
170 | } | 177 | } | ||
171 | 178 | | |||
172 | // protected static | 179 | // protected static | ||
173 | int kpToolText::MoveCursorToNextWordStart (const QList <QString> &textLines, | 180 | int kpToolText::MoveCursorToNextWordStart (const QList <QString> &textLines, | ||
174 | int *cursorRow, int *cursorCol) | 181 | int *cursorRow, int *cursorCol) | ||
175 | { | 182 | { | ||
176 | if (textLines.isEmpty ()) | 183 | if (textLines.isEmpty ()) { | ||
177 | return 0; | 184 | return 0; | ||
185 | } | ||||
178 | 186 | | |||
179 | int numMoves = 0; | 187 | int numMoves = 0; | ||
180 | 188 | | |||
181 | #define IS_AT_END() CursorIsAtEnd (textLines, *cursorRow, *cursorCol) | 189 | #define IS_AT_END() CursorIsAtEnd (textLines, *cursorRow, *cursorCol) | ||
182 | #define MOVE_CURSOR_RIGHT() \ | 190 | #define MOVE_CURSOR_RIGHT() \ | ||
183 | (MoveCursorRight (textLines, cursorRow, cursorCol), ++numMoves) | 191 | (MoveCursorRight (textLines, cursorRow, cursorCol), ++numMoves) | ||
184 | 192 | | |||
185 | 193 | | |||
Show All 27 Lines |