Changeset View
Changeset View
Standalone View
Standalone View
src/view/kateview.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | 1243 | { | |||
---|---|---|---|---|---|
1260 | } | 1260 | } | ||
1261 | 1261 | | |||
1262 | return foldingRange; | 1262 | return foldingRange; | ||
1263 | } | 1263 | } | ||
1264 | 1264 | | |||
1265 | bool KTextEditor::ViewPrivate::unfoldLine(int line) | 1265 | bool KTextEditor::ViewPrivate::unfoldLine(int line) | ||
1266 | { | 1266 | { | ||
1267 | bool actionDone = false; | 1267 | bool actionDone = false; | ||
1268 | const KTextEditor::Cursor currentCursor = cursorPosition(); | ||||
1268 | 1269 | | |||
1269 | // ask the folding info for this line, if any folds are around! | 1270 | // ask the folding info for this line, if any folds are around! | ||
1270 | // auto = QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags>> | 1271 | // auto = QVector<QPair<qint64, Kate::TextFolding::FoldingRangeFlags>> | ||
1271 | auto startingRanges = textFolding().foldingRangesStartingOnLine(line); | 1272 | auto startingRanges = textFolding().foldingRangesStartingOnLine(line); | ||
1272 | for (int i = 0; i < startingRanges.size(); ++i) { | 1273 | for (int i = 0; i < startingRanges.size() && !actionDone; ++i) { | ||
1274 | // Avoid jumping view in case of a big unfold and ensure nice highlight of folding marker | ||||
1275 | setCursorPosition(textFolding().foldingRange(startingRanges[i].first).start()); | ||||
1276 | | ||||
1273 | actionDone |= textFolding().unfoldRange(startingRanges[i].first); | 1277 | actionDone |= textFolding().unfoldRange(startingRanges[i].first); | ||
1274 | } | 1278 | } | ||
1275 | 1279 | | |||
1280 | if (!actionDone) { | ||||
1281 | // Nothing unfolded? Restore old cursor position! | ||||
1282 | setCursorPosition(currentCursor); | ||||
1283 | } | ||||
1284 | | ||||
1276 | return actionDone; | 1285 | return actionDone; | ||
1277 | } | 1286 | } | ||
1278 | 1287 | | |||
1279 | bool KTextEditor::ViewPrivate::toggleFoldingOfLine(int line) | 1288 | bool KTextEditor::ViewPrivate::toggleFoldingOfLine(int line) | ||
1280 | { | 1289 | { | ||
1281 | bool actionDone = unfoldLine(line); | 1290 | bool actionDone = unfoldLine(line); | ||
1282 | if (!actionDone) { | 1291 | if (!actionDone) { | ||
1283 | actionDone = foldLine(line).isValid(); | 1292 | actionDone = foldLine(line).isValid(); | ||
1284 | } | 1293 | } | ||
1285 | 1294 | | |||
1286 | return actionDone; | 1295 | return actionDone; | ||
1287 | } | 1296 | } | ||
1288 | 1297 | | |||
1289 | bool KTextEditor::ViewPrivate::toggleFoldingsInRange(int line) | 1298 | bool KTextEditor::ViewPrivate::toggleFoldingsInRange(int line) | ||
1290 | { | 1299 | { | ||
1291 | KTextEditor::Range foldingRange = doc()->buffer().computeFoldingRangeForStartLine(line); | 1300 | KTextEditor::Range foldingRange = doc()->buffer().computeFoldingRangeForStartLine(line); | ||
1292 | if (!foldingRange.isValid()) { | 1301 | if (!foldingRange.isValid()) { | ||
1293 | // Either line is not valid or there is no start range | 1302 | // Either line is not valid or there is no start range | ||
1294 | return false; | 1303 | return false; | ||
1295 | } | 1304 | } | ||
1296 | 1305 | | |||
1297 | bool actionDone = false; // Track success | 1306 | bool actionDone = false; // Track success | ||
1307 | const KTextEditor::Cursor currentCursor = cursorPosition(); | ||||
1298 | 1308 | | |||
1299 | // Don't be too eager but obliging! Only toggle containing ranges which are | 1309 | // Don't be too eager but obliging! Only toggle containing ranges which are | ||
1300 | // visible -> Be done when the range is folded | 1310 | // visible -> Be done when the range is folded | ||
1301 | actionDone |= unfoldLine(line); | 1311 | actionDone |= unfoldLine(line); | ||
1302 | 1312 | | |||
1303 | if (!actionDone) { | 1313 | if (!actionDone) { | ||
1304 | // Unfold all in range, but not the range itself | 1314 | // Unfold all in range, but not the range itself | ||
1305 | for (int ln = foldingRange.start().line() + 1; ln < foldingRange.end().line(); ++ln) { | 1315 | for (int ln = foldingRange.start().line() + 1; ln < foldingRange.end().line(); ++ln) { | ||
1306 | actionDone |= unfoldLine(ln); | 1316 | actionDone |= unfoldLine(ln); | ||
1307 | } | 1317 | } | ||
1318 | | ||||
1319 | if (actionDone) { | ||||
1320 | // In most cases we want now a not moved cursor | ||||
1321 | setCursorPosition(currentCursor); | ||||
1322 | } | ||||
1308 | } | 1323 | } | ||
1309 | 1324 | | |||
1310 | if (!actionDone) { | 1325 | if (!actionDone) { | ||
1311 | // Fold all in range, but not the range itself | 1326 | // Fold all in range, but not the range itself | ||
1312 | for (int ln = foldingRange.start().line() + 1; ln < foldingRange.end().line(); ++ln) { | 1327 | for (int ln = foldingRange.start().line() + 1; ln < foldingRange.end().line(); ++ln) { | ||
1313 | KTextEditor::Range fr = foldLine(ln); | 1328 | KTextEditor::Range fr = foldLine(ln); | ||
1314 | if (fr.isValid()) { | 1329 | if (fr.isValid()) { | ||
1315 | ln = fr.end().line() - 1; | 1330 | ln = fr.end().line() - 1; | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |