Changeset View
Changeset View
Standalone View
Standalone View
src/document/katedocument.cpp
Show First 20 Lines • Show All 1208 Lines • ▼ Show 20 Line(s) | 1116 | for (int line = startLine; (line <= endLine) && (line < lines()); line++) { | |||
---|---|---|---|---|---|
1209 | } | 1209 | } | ||
1210 | } | 1210 | } | ||
1211 | 1211 | | |||
1212 | editEnd(); | 1212 | editEnd(); | ||
1213 | 1213 | | |||
1214 | return true; | 1214 | return true; | ||
1215 | } | 1215 | } | ||
1216 | 1216 | | |||
1217 | bool KTextEditor::DocumentPrivate::wrapParagraph(int first, int last) | ||||
1218 | { | ||||
1219 | if (first == last) { | ||||
1220 | return wrapText(first, last); | ||||
1221 | } | ||||
1222 | | ||||
1223 | if (first < 0 || last < first) { | ||||
1224 | return false; | ||||
1225 | } | ||||
1226 | | ||||
1227 | if (last >= lines() || first > last) { | ||||
1228 | return false; | ||||
1229 | } | ||||
1230 | | ||||
1231 | if (!isReadWrite()) { | ||||
1232 | return false; | ||||
1233 | } | ||||
1234 | | ||||
1235 | editStart(); | ||||
1236 | | ||||
1237 | // Because we shrink and expand lines, we need to track the working set by powerful "MovingStuff" | ||||
1238 | std::unique_ptr<KTextEditor::MovingRange> range(newMovingRange(KTextEditor::Range(first, 0, last, 0))); | ||||
1239 | std::unique_ptr<KTextEditor::MovingCursor> curr(newMovingCursor(KTextEditor::Cursor(range->start()))); | ||||
1240 | | ||||
1241 | // Scan the selected range for paragraphs, whereas each empty line trigger a new paragraph | ||||
1242 | for (int line = first; line <= range->end().line(); ++line) { | ||||
1243 | // Is our first line a somehow filled line? | ||||
1244 | if(plainKateTextLine(first)->firstChar() < 0) { | ||||
1245 | // Fast forward to first non empty line | ||||
1246 | ++first; | ||||
1247 | curr->setPosition(curr->line() + 1, 0); | ||||
1248 | continue; | ||||
1249 | } | ||||
1250 | | ||||
1251 | // Is our current line a somehow filled line? If not, wrap the paragraph | ||||
1252 | if (plainKateTextLine(line)->firstChar() < 0) { | ||||
1253 | curr->setPosition(line, 0); // Set on empty line | ||||
1254 | joinLines(first, line - 1); | ||||
1255 | // Don't wrap twice! That may cause a bad result | ||||
1256 | if (!wordWrap()) { | ||||
1257 | wrapText(first, first); | ||||
1258 | } | ||||
1259 | first = curr->line() + 1; | ||||
1260 | line = first; | ||||
1261 | } | ||||
1262 | } | ||||
1263 | | ||||
1264 | // If there was no paragraph, we need to wrap now | ||||
1265 | bool needWrap = (curr->line() != range->end().line()); | ||||
1266 | if (needWrap && plainKateTextLine(first)->firstChar() != -1) { | ||||
1267 | joinLines(first, range->end().line()); | ||||
1268 | // Don't wrap twice! That may cause a bad result | ||||
1269 | if (!wordWrap()) { | ||||
1270 | wrapText(first, first); | ||||
1271 | } | ||||
1272 | } | ||||
1273 | | ||||
1274 | editEnd(); | ||||
1275 | return true; | ||||
1276 | } | ||||
1277 | | ||||
1217 | bool KTextEditor::DocumentPrivate::editInsertText(int line, int col, const QString &s) | 1278 | bool KTextEditor::DocumentPrivate::editInsertText(int line, int col, const QString &s) | ||
1218 | { | 1279 | { | ||
1219 | // verbose debug | 1280 | // verbose debug | ||
1220 | EDIT_DEBUG << "editInsertText" << line << col << s; | 1281 | EDIT_DEBUG << "editInsertText" << line << col << s; | ||
1221 | 1282 | | |||
1222 | if (line < 0 || col < 0) { | 1283 | if (line < 0 || col < 0) { | ||
1223 | return false; | 1284 | return false; | ||
1224 | } | 1285 | } | ||
▲ Show 20 Lines • Show All 4773 Lines • Show Last 20 Lines |