102 skipped lines |
|
104 | | 104 | | int Document::AddMark(int line, int markerNum) { |
|
105 | | 105 | | int prev = cb.AddMark(line, markerNum); |
|
106 | | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0); | | 106 | | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line); |
| | 107 | | mh.line = line; |
107 | | 108 | | NotifyModified(mh); |
|
|
|
|
| | 112 | | void Document::AddMarkSet(int line, int valueSet) { |
| | 113 | | unsigned int m = valueSet; |
| | 114 | | for (int i = 0; m; i++, m >>= 1) |
| | 115 | | if (m & 1) |
| | 116 | | cb.AddMark(line, i); |
| | 117 | | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line); |
| | 118 | | mh.line = line; |
| | 119 | | NotifyModified(mh); |
| | 120 | | } |
| | 121 | | |
111 | | 122 | | void Document::DeleteMark(int line, int markerNum) { |
|
112 | | 123 | | cb.DeleteMark(line, markerNum); |
|
113 | | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0); | | 124 | | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line); |
| | 125 | | mh.line = line; |
114 | | 126 | | NotifyModified(mh); |
|
|
|
117 | | 129 | | void Document::DeleteMarkFromHandle(int markerHandle) { |
|
118 | | 130 | | cb.DeleteMarkFromHandle(markerHandle); |
|
119 | | 131 | | DocModification mh(SC_MOD_CHANGEMARKER, 0, 0, 0, 0); |
|
| | 132 | | mh.line = -1; |
120 | | 133 | | NotifyModified(mh); |
|
|
|
123 | | 136 | | void Document::DeleteAllMarks(int markerNum) { |
|
124 | | 137 | | cb.DeleteAllMarks(markerNum); |
|
125 | | 138 | | DocModification mh(SC_MOD_CHANGEMARKER, 0, 0, 0, 0); |
|
| | 139 | | mh.line = -1; |
126 | | 140 | | NotifyModified(mh); |
|
|
|
137 skipped lines |
|
|
|
269 | | #include <assert.h> | | 283 | | |
270 | | 284 | | // Normalise a position so that it is not halfway through a two byte character. |
|
271 | | 285 | | // This can occur in two situations - |
|
272 | | 286 | | // When lines are terminated with \r\n pairs which should be treated as one character. |
|
7 skipped lines |
280 | | 294 | | if (pos >= Length()) |
|
|
|
283 | | // assert pos > 0 && pos < Length() | | 297 | | // PLATFORM_ASSERT(pos > 0 && pos < Length()); |
284 | | 298 | | if (checkLineEnd && IsCrLf(pos - 1)) { |
|
|
|
49 skipped lines |
|
|
|
| | 353 | | void Document::CheckReadOnly() { |
| | 354 | | if (cb.IsReadOnly() && enteredReadOnlyCount == 0) { |
| | 355 | | enteredReadOnlyCount++; |
| | 356 | | NotifyModifyAttempt(); |
| | 357 | | enteredReadOnlyCount--; |
| | 358 | | } |
| | 359 | | } |
| | 360 | | |
339 | | 361 | | // Document only modified by gateways DeleteChars, InsertStyledString, Undo, Redo, and SetStyleAt. |
|
340 | | 362 | | // SetStyleAt does not change the persistent state of a document |
|
|
3 skipped lines |
|
346 | | 368 | | if ((pos + len) > Length()) |
|
|
348 | | if (cb.IsReadOnly() && enteredReadOnlyCount == 0) { | | 370 | | CheckReadOnly(); |
349 | | enteredReadOnlyCount++; | | |
350 | | NotifyModifyAttempt(); | | |
351 | | enteredReadOnlyCount--; | | |
352 | | } | | |
353 | | 371 | | if (enteredCount != 0) { |
|
|
|
28 skipped lines |
384 | | 402 | | * Insert a styled string (char/style pairs) with a length. |
|
|
386 | | 404 | | bool Document::InsertStyledString(int position, char *s, int insertLength) { |
|
387 | | if (cb.IsReadOnly() && enteredReadOnlyCount == 0) { | | 405 | | CheckReadOnly(); |
388 | | enteredReadOnlyCount++; | | |
389 | | NotifyModifyAttempt(); | | |
390 | | enteredReadOnlyCount--; | | |
391 | | } | | |
392 | | 406 | | if (enteredCount != 0) { |
|
|
|
22 skipped lines |
|
|
419 | | 433 | | int Document::Undo() { |
|
420 | | int newPos = 0; | | 434 | | int newPos = -1; |
| | 435 | | CheckReadOnly(); |
421 | | 436 | | if (enteredCount == 0) { |
|
|
| | 438 | | if (!cb.IsReadOnly()) { |
423 | | bool startSavePoint = cb.IsSavePoint(); | | 439 | | bool startSavePoint = cb.IsSavePoint(); |
| | 440 | | bool multiLine = false; |
424 | | int steps = cb.StartUndo(); | | 441 | | int steps = cb.StartUndo(); |
425 | | //Platform::DebugPrintf("Steps=%d\n", steps); | | 442 | | //Platform::DebugPrintf("Steps=%d\n", steps); |
426 | | for (int step = 0; step < steps; step++) { | | 443 | | for (int step = 0; step < steps; step++) { |
427 | | int prevLinesTotal = LinesTotal(); | | 444 | | const int prevLinesTotal = LinesTotal(); |
428 | | const Action &action = cb.GetUndoStep(); | | 445 | | const Action &action = cb.GetUndoStep(); |
429 | | if (action.at == removeAction) { | | 446 | | if (action.at == removeAction) { |
430 | | NotifyModified(DocModification( | | 447 | | NotifyModified(DocModification( |
431 | | SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); | | 448 | | SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); |
432 | | } else { | | 449 | | } else { |
433 | | NotifyModified(DocModification( | | 450 | | NotifyModified(DocModification( |
434 | | SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action)); | | 451 | | SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action)); |
435 | | } | | 452 | | } |
436 | | cb.PerformUndoStep(); | | 453 | | cb.PerformUndoStep(); |
437 | | int cellPosition = action.position / 2; | | 454 | | int cellPosition = action.position; |
438 | | ModifiedAt(cellPosition); | | 455 | | ModifiedAt(cellPosition); |
439 | | newPos = cellPosition; | | 456 | | newPos = cellPosition; |
|
441 | | int modFlags = SC_PERFORMED_UNDO; | | 458 | | int modFlags = SC_PERFORMED_UNDO; |
442 | | // With undo, an insertion action becomes a deletion notification | | 459 | | // With undo, an insertion action becomes a deletion notification |
443 | | if (action.at == removeAction) { | | 460 | | if (action.at == removeAction) { |
444 | | newPos += action.lenData; | | 461 | | newPos += action.lenData; |
445 | | modFlags |= SC_MOD_INSERTTEXT; | | 462 | | modFlags |= SC_MOD_INSERTTEXT; |
446 | | } else { | | 463 | | } else { |
447 | | modFlags |= SC_MOD_DELETETEXT; | | 464 | | modFlags |= SC_MOD_DELETETEXT; |
| | 465 | | } |
| | 466 | | if (steps > 1) |
| | 467 | | modFlags |= SC_MULTISTEPUNDOREDO; |
| | 468 | | const int linesAdded = LinesTotal() - prevLinesTotal; |
| | 469 | | if (linesAdded != 0) |
| | 470 | | multiLine = true; |
| | 471 | | if (step == steps - 1) { |
| | 472 | | modFlags |= SC_LASTSTEPINUNDOREDO; |
| | 473 | | if (multiLine) |
| | 474 | | modFlags |= SC_MULTILINEUNDOREDO; |
| | 475 | | } |
| | 476 | | NotifyModified(DocModification(modFlags, cellPosition, action.lenData, |
| | 477 | | linesAdded, action.data)); |
|
449 | | if (step == steps - 1) | | |
450 | | modFlags |= SC_LASTSTEPINUNDOREDO; | | |
451 | | NotifyModified(DocModification(modFlags, cellPosition, action.lenData, | | |
452 | | LinesTotal() - prevLinesTotal, action.data)); | | |
453 | | } | | |
|
455 | | bool endSavePoint = cb.IsSavePoint(); | | 480 | | bool endSavePoint = cb.IsSavePoint(); |
456 | | if (startSavePoint != endSavePoint) | | 481 | | if (startSavePoint != endSavePoint) |
457 | | NotifySavePoint(endSavePoint); | | 482 | | NotifySavePoint(endSavePoint); |
| | 483 | | } |
|
|
|
|
|
463 | | 489 | | int Document::Redo() { |
|
464 | | int newPos = 0; | | 490 | | int newPos = -1; |
| | 491 | | CheckReadOnly(); |
465 | | 492 | | if (enteredCount == 0) { |
|
|
| | 494 | | if (!cb.IsReadOnly()) { |
467 | | bool startSavePoint = cb.IsSavePoint(); | | 495 | | bool startSavePoint = cb.IsSavePoint(); |
| | 496 | | bool multiLine = false; |
468 | | int steps = cb.StartRedo(); | | 497 | | int steps = cb.StartRedo(); |
469 | | for (int step = 0; step < steps; step++) { | | 498 | | for (int step = 0; step < steps; step++) { |
470 | | int prevLinesTotal = LinesTotal(); | | 499 | | const int prevLinesTotal = LinesTotal(); |
471 | | const Action &action = cb.GetRedoStep(); | | 500 | | const Action &action = cb.GetRedoStep(); |
472 | | if (action.at == insertAction) { | | 501 | | if (action.at == insertAction) { |
473 | | NotifyModified(DocModification( | | 502 | | NotifyModified(DocModification( |
474 | | SC_MOD_BEFOREINSERT | SC_PERFORMED_REDO, action)); | | 503 | | SC_MOD_BEFOREINSERT | SC_PERFORMED_REDO, action)); |
475 | | } else { | | 504 | | } else { |
476 | | NotifyModified(DocModification( | | 505 | | NotifyModified(DocModification( |
477 | | SC_MOD_BEFOREDELETE | SC_PERFORMED_REDO, action)); | | 506 | | SC_MOD_BEFOREDELETE | SC_PERFORMED_REDO, action)); |
478 | | } | | 507 | | } |
479 | | cb.PerformRedoStep(); | | 508 | | cb.PerformRedoStep(); |
480 | | ModifiedAt(action.position / 2); | | 509 | | ModifiedAt(action.position); |
481 | | newPos = action.position / 2; | | 510 | | newPos = action.position; |
|
483 | | int modFlags = SC_PERFORMED_REDO; | | 512 | | int modFlags = SC_PERFORMED_REDO; |
484 | | if (action.at == insertAction) { | | 513 | | if (action.at == insertAction) { |
485 | | newPos += action.lenData; | | 514 | | newPos += action.lenData; |
486 | | modFlags |= SC_MOD_INSERTTEXT; | | 515 | | modFlags |= SC_MOD_INSERTTEXT; |
487 | | } else { | | 516 | | } else { |
488 | | modFlags |= SC_MOD_DELETETEXT; | | 517 | | modFlags |= SC_MOD_DELETETEXT; |
| | 518 | | } |
| | 519 | | if (steps > 1) |
| | 520 | | modFlags |= SC_MULTISTEPUNDOREDO; |
| | 521 | | const int linesAdded = LinesTotal() - prevLinesTotal; |
| | 522 | | if (linesAdded != 0) |
| | 523 | | multiLine = true; |
| | 524 | | if (step == steps - 1) { |
| | 525 | | modFlags |= SC_LASTSTEPINUNDOREDO; |
| | 526 | | if (multiLine) |
| | 527 | | modFlags |= SC_MULTILINEUNDOREDO; |
| | 528 | | } |
| | 529 | | NotifyModified( |
| | 530 | | DocModification(modFlags, action.position, action.lenData, |
| | 531 | | linesAdded, action.data)); |
|
490 | | if (step == steps - 1) | | |
491 | | modFlags |= SC_LASTSTEPINUNDOREDO; | | |
492 | | NotifyModified( | | |
493 | | DocModification(modFlags, action.position / 2, action.lenData, | | |
494 | | LinesTotal() - prevLinesTotal, action.data)); | | |
495 | | } | | |
|
497 | | bool endSavePoint = cb.IsSavePoint(); | | 534 | | bool endSavePoint = cb.IsSavePoint(); |
498 | | if (startSavePoint != endSavePoint) | | 535 | | if (startSavePoint != endSavePoint) |
499 | | NotifySavePoint(endSavePoint); | | 536 | | NotifySavePoint(endSavePoint); |
| | 537 | | } |
|
|
|
21 skipped lines |
|
525 | | 563 | | bool Document::InsertString(int position, const char *s, size_t insertLength) { |
|
526 | | 564 | | bool changed = false; |
|
| | 565 | | if (insertLength > 0) { |
527 | | char *sWithStyle = new char[insertLength * 2]; | | 566 | | char *sWithStyle = new char[insertLength * 2]; |
528 | | if (sWithStyle) { | | 567 | | if (sWithStyle) { |
529 | | for (size_t i = 0; i < insertLength; i++) { | | 568 | | for (size_t i = 0; i < insertLength; i++) { |
530 | | sWithStyle[i*2] = s[i]; | | 569 | | sWithStyle[i*2] = s[i]; |
531 | | sWithStyle[i*2 + 1] = 0; | | 570 | | sWithStyle[i*2 + 1] = 0; |
| | 571 | | } |
| | 572 | | changed = InsertStyledString(position*2, sWithStyle, |
| | 573 | | static_cast<int>(insertLength*2)); |
| | 574 | | delete []sWithStyle; |
|
533 | | changed = InsertStyledString(position*2, sWithStyle, | | |
534 | | static_cast<int>(insertLength*2)); | | |
535 | | delete []sWithStyle; | | |
|
|
|
72 skipped lines |
611 | | 651 | | CreateIndentation(linebuf, sizeof(linebuf), indent, tabInChars, !useTabs); |
|
612 | | 652 | | int thisLineStart = LineStart(line); |
|
613 | | 653 | | int indentPos = GetLineIndentPosition(line); |
|
| | 654 | | BeginUndoAction(); |
614 | | 655 | | DeleteChars(thisLineStart, indentPos - thisLineStart); |
|
615 | | 656 | | InsertString(thisLineStart, linebuf); |
|
| | 657 | | EndUndoAction(); |
|
|
|
56 skipped lines |
675 | | 717 | | // Dedent - suck white space off the front of the line to dedent by equivalent of a tab |
|
676 | | 718 | | for (int line = lineBottom; line >= lineTop; line--) { |
|
677 | | 719 | | int indentOfLine = GetLineIndentation(line); |
|
678 | | if (forwards) | | 720 | | if (forwards) { |
| | 721 | | if (LineStart(line) < LineEnd(line)) { |
679 | | SetLineIndentation(line, indentOfLine + IndentSize()); | | 722 | | SetLineIndentation(line, indentOfLine + IndentSize()); |
| | 723 | | } |
680 | | else | | 724 | | } else { |
681 | | 725 | | SetLineIndentation(line, indentOfLine - IndentSize()); |
|
| | 726 | | } |
|
|
|
33 skipped lines |
|
719 | | 764 | | for (int pos = 0; pos < Length(); pos++) { |
|
720 | | 765 | | if (cb.CharAt(pos) == '\r') { |
|
721 | | if (cb.CharAt(pos + 1) == '\n') { | | 766 | | if (cb.CharAt(pos + 1) == '\n') { |
|
723 | | 768 | | if (eolModeSet == SC_EOL_CR) { |
|
724 | | 769 | | DeleteChars(pos + 1, 1); // Delete the LF |
|
2 skipped lines |
|
|
|
730 | | } else { | | 775 | | } else { |
|
732 | | 777 | | if (eolModeSet == SC_EOL_CRLF) { |
|
733 | | 778 | | InsertString(pos + 1, "\n", 1); // Insert LF |
|
18 skipped lines |
|
|
|
755 | | int Document::ParaDown(int pos) { | | 800 | | bool Document::IsWhiteLine(int line) { |
756 | | int line = LineFromPosition(pos); | | 801 | | int currentChar = LineStart(line); |
757 | | while (line < LinesTotal() && LineStart(line) != LineEnd(line)) { // skip non-empty lines | | 802 | | int endLine = LineEnd(line); |
758 | | line++; | | |
759 | | } | | |
760 | | while (line < LinesTotal() && LineStart(line) == LineEnd(line)) { // skip empty lines | | 803 | | while (currentChar < endLine) { |
| | 804 | | if (cb.CharAt(currentChar) != ' ' && cb.CharAt(currentChar) != '\t') { |
| | 805 | | return false; |
| | 806 | | } |
761 | | line++; | | 807 | | ++currentChar; |
|
763 | | if (line < LinesTotal()) | | |
764 | | return LineStart(line); | | |
765 | | else // end of a document | | |
766 | | return LineEnd(line-1); | | 809 | | return true; |
|
|
769 | | 812 | | int Document::ParaUp(int pos) { |
|
770 | | 813 | | int line = LineFromPosition(pos); |
|
|
772 | | while (line >= 0 && LineStart(line) == LineEnd(line)) { // skip empty lines | | 815 | | while (line >= 0 && IsWhiteLine(line)) { // skip empty lines |
|
|
775 | | while (line >= 0 && LineStart(line) != LineEnd(line)) { // skip non-empty lines | | 818 | | while (line >= 0 && !IsWhiteLine(line)) { // skip non-empty lines |
|
|
|
779 | | 822 | | return LineStart(line); |
|
|
|
| | 825 | | int Document::ParaDown(int pos) { |
| | 826 | | int line = LineFromPosition(pos); |
| | 827 | | while (line < LinesTotal() && !IsWhiteLine(line)) { // skip non-empty lines |
| | 828 | | line++; |
| | 829 | | } |
4 skipped lines |
| | 834 | | return LineStart(line); |
| | 835 | | else // end of a document |
| | 836 | | return LineEnd(line-1); |
| | 837 | | } |
| | 838 | | |
782 | | 839 | | Document::charClassification Document::WordCharClass(unsigned char ch) { |
|
783 | | 840 | | if ((SC_CP_UTF8 == dbcsCodePage) && (ch >= 0x80)) |
|
|
141 skipped lines |
926 | | 983 | | pdoc(pdoc_), end(end_) { |
|
|
|
| | 986 | | virtual ~DocumentIndexer() { |
| | 987 | | } |
| | 988 | | |
929 | | 989 | | virtual char CharAt(int index) { |
|
930 | | 990 | | if (index < 0 || index >= end) |
|
|
69 skipped lines |
1001 | | 1061 | | if (line == lineRangeStart) { |
|
1002 | | 1062 | | if ((startPos != endOfLine) && (searchEnd == '$')) |
|
1003 | | 1063 | | continue; // Can't match end of line if start position before end of line |
|
1004 | | endOfLine = startPos+1; | | 1064 | | endOfLine = startPos; |
|
|
|
5 skipped lines |
1013 | | 1073 | | if (increment == -1) { |
|
1014 | | 1074 | | // Check for the last match on this line. |
|
1015 | | 1075 | | int repetitions = 1000; // Break out of infinite loop |
|
1016 | | while (success && (pre->eopat[0] <= (endOfLine+1)) && (repetitions--)) { | | 1076 | | while (success && (pre->eopat[0] <= endOfLine) && (repetitions--)) { |
1017 | | success = pre->Execute(di, pos+1, endOfLine+1); | | 1077 | | success = pre->Execute(di, pos+1, endOfLine); |
|
1019 | | if (pre->eopat[0] <= (minPos+1)) { | | 1079 | | if (pre->eopat[0] <= minPos) { |
1020 | | 1080 | | pos = pre->bopat[0]; |
|
1021 | | 1081 | | lenRet = pre->eopat[0] - pre->bopat[0]; |
|
|
29 skipped lines |
1052 | | 1112 | | char firstChar = s[0]; |
|
1053 | | 1113 | | if (!caseSensitive) |
|
1054 | | 1114 | | firstChar = static_cast<char>(MakeUpperCase(firstChar)); |
|
1055 | | int pos = startPos; | | 1115 | | int pos = forward ? startPos : (startPos - 1); |
1056 | | 1116 | | while (forward ? (pos < endSearch) : (pos >= endSearch)) { |
|
1057 | | 1117 | | char ch = CharAt(pos); |
|
1058 | | 1118 | | if (caseSensitive) { |
|
1059 | | 1119 | | if (ch == firstChar) { |
|
1060 | | 1120 | | bool found = true; |
|
| | 1121 | | if (pos + lengthFind > Platform::Maximum(startPos, endPos)) found = false; |
1061 | | 1122 | | for (int posMatch = 1; posMatch < lengthFind && found; posMatch++) { |
|
1062 | | 1123 | | ch = CharAt(pos + posMatch); |
|
1063 | | 1124 | | if (ch != s[posMatch]) |
|
9 skipped lines |
|
1074 | | 1135 | | if (MakeUpperCase(ch) == firstChar) { |
|
1075 | | 1136 | | bool found = true; |
|
| | 1137 | | if (pos + lengthFind > Platform::Maximum(startPos, endPos)) found = false; |
1076 | | 1138 | | for (int posMatch = 1; posMatch < lengthFind && found; posMatch++) { |
|
1077 | | 1139 | | ch = CharAt(pos + posMatch); |
|
1078 | | 1140 | | if (MakeUpperCase(ch) != MakeUpperCase(s[posMatch])) |
|
106 skipped lines |
|
|
1187 | | 1249 | | void Document::ChangeCase(Range r, bool makeUpperCase) { |
|
1188 | | for (int pos = r.start; pos < r.end; pos++) { | | 1250 | | for (int pos = r.start; pos < r.end;) { |
1189 | | 1251 | | int len = LenChar(pos); |
|
1190 | | if (dbcsCodePage && (len > 1)) { | | 1252 | | if (len == 1) { |
1191 | | pos += len; | | |
1192 | | } else { | | |
1193 | | 1253 | | char ch = CharAt(pos); |
|
1194 | | 1254 | | if (makeUpperCase) { |
|
1195 | | 1255 | | if (IsLowerCase(ch)) { |
|
5 skipped lines |
|
|
|
| | 1264 | | pos += len; |
|
|
|
58 skipped lines |
|
|
1267 | | 1328 | | enteredCount++; |
|
1268 | | int prevEndStyled = endStyled; | | |
1269 | | 1329 | | bool didChange = false; |
|
| | 1330 | | int startMod = 0; |
1270 | | int lastChange = 0; | | 1331 | | int endMod = 0; |
1271 | | 1332 | | for (int iPos = 0; iPos < length; iPos++, endStyled++) { |
|
1272 | | 1333 | | PLATFORM_ASSERT(endStyled < Length()); |
|
1273 | | 1334 | | if (cb.SetStyleAt(endStyled, styles[iPos], stylingMask)) { |
|
| | 1335 | | if (!didChange) { |
| | 1336 | | startMod = endStyled; |
| | 1337 | | } |
1274 | | 1338 | | didChange = true; |
|
1275 | | lastChange = iPos; | | 1339 | | endMod = endStyled; |
|
|
1278 | | 1342 | | if (didChange) { |
|
1279 | | 1343 | | DocModification mh(SC_MOD_CHANGESTYLE | SC_PERFORMED_USER, |
|
1280 | | prevEndStyled, lastChange); | | 1344 | | startMod, endMod - startMod + 1); |
1281 | | 1345 | | NotifyModified(mh); |
|
|
1283 | | 1347 | | enteredCount--; |
|
191 skipped lines |
|
|
|
| | 1542 | | |
| | 1543 | | static char BraceOpposite(char ch) { |
| | 1544 | | switch (ch) { |
| | 1545 | | case '(': |
| | 1546 | | return ')'; |
42 skipped lines |
| | 1589 | | } |
| | 1590 | | position = position + direction; |
| | 1591 | | } |
| | 1592 | | return - 1; |
| | 1593 | | } |
|