| 102 skipped lines |
|
| 104 | U | 104 | U | int Document::AddMark(int line, int markerNum) { |
|
| 105 | U | 105 | U | int prev = cb.AddMark(line, markerNum); |
|
| 106 | C | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0); | | 106 | C | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line); |
| | | 107 | C | mh.line = line; |
| 107 | U | 108 | U | NotifyModified(mh); |
|
|
|
|
| | | 112 | A | void Document::AddMarkSet(int line, int valueSet) { |
| | | 113 | A | unsigned int m = valueSet; |
| | | 114 | A | for (int i = 0; m; i++, m >>= 1) |
| | | 115 | A | if (m & 1) |
| | | 116 | A | cb.AddMark(line, i); |
| | | 117 | A | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line); |
| | | 118 | A | mh.line = line; |
| | | 119 | A | NotifyModified(mh); |
| | | 120 | A | } |
| | | 121 | A | |
| 111 | U | 122 | U | void Document::DeleteMark(int line, int markerNum) { |
|
| 112 | U | 123 | U | cb.DeleteMark(line, markerNum); |
|
| 113 | C | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0); | | 124 | C | DocModification mh(SC_MOD_CHANGEMARKER, LineStart(line), 0, 0, 0, line); |
| | | 125 | C | mh.line = line; |
| 114 | U | 126 | U | NotifyModified(mh); |
|
|
|
| 117 | U | 129 | U | void Document::DeleteMarkFromHandle(int markerHandle) { |
|
| 118 | U | 130 | U | cb.DeleteMarkFromHandle(markerHandle); |
|
| 119 | U | 131 | U | DocModification mh(SC_MOD_CHANGEMARKER, 0, 0, 0, 0); |
|
| | | 132 | A | mh.line = -1; |
| 120 | U | 133 | U | NotifyModified(mh); |
|
|
|
| 123 | U | 136 | U | void Document::DeleteAllMarks(int markerNum) { |
|
| 124 | U | 137 | U | cb.DeleteAllMarks(markerNum); |
|
| 125 | U | 138 | U | DocModification mh(SC_MOD_CHANGEMARKER, 0, 0, 0, 0); |
|
| | | 139 | A | mh.line = -1; |
| 126 | U | 140 | U | NotifyModified(mh); |
|
|
|
| 137 skipped lines |
|
|
|
| 269 | C | #include <assert.h> | | 283 | C | |
| 270 | U | 284 | U | // Normalise a position so that it is not halfway through a two byte character. |
|
| 271 | U | 285 | U | // This can occur in two situations - |
|
| 272 | U | 286 | U | // When lines are terminated with \r\n pairs which should be treated as one character. |
|
| 7 skipped lines |
| 280 | U | 294 | U | if (pos >= Length()) |
|
| 281 | U | 295 | U | return Length(); |
|
|
| 283 | C | // assert pos > 0 && pos < Length() | | 297 | C | // PLATFORM_ASSERT(pos > 0 && pos < Length()); |
| 284 | U | 298 | U | if (checkLineEnd && IsCrLf(pos - 1)) { |
|
| 285 | U | 299 | U | if (moveDir > 0) |
|
|
| 49 skipped lines |
| 336 | U | 350 | U | endStyled = pos; |
|
|
|
| | | 353 | A | void Document::CheckReadOnly() { |
| | | 354 | A | if (cb.IsReadOnly() && enteredReadOnlyCount == 0) { |
| | | 355 | A | enteredReadOnlyCount++; |
| | | 356 | A | NotifyModifyAttempt(); |
| | | 357 | A | enteredReadOnlyCount--; |
| | | 358 | A | } |
| | | 359 | A | } |
| | | 360 | A | |
| 339 | U | 361 | U | // Document only modified by gateways DeleteChars, InsertStyledString, Undo, Redo, and SetStyleAt. |
|
| 340 | U | 362 | U | // SetStyleAt does not change the persistent state of a document |
|
|
| 3 skipped lines |
|
| 346 | U | 368 | U | if ((pos + len) > Length()) |
|
|
| 348 | C | if (cb.IsReadOnly() && enteredReadOnlyCount == 0) { | | 370 | C | CheckReadOnly(); |
| 349 | C | enteredReadOnlyCount++; | | |
| 350 | C | NotifyModifyAttempt(); | | |
| 351 | C | enteredReadOnlyCount--; | | |
| 352 | C | } | | |
| 353 | U | 371 | U | if (enteredCount != 0) { |
|
|
|
| 28 skipped lines |
| 384 | U | 402 | U | * Insert a styled string (char/style pairs) with a length. |
|
|
| 386 | U | 404 | U | bool Document::InsertStyledString(int position, char *s, int insertLength) { |
|
| 387 | C | if (cb.IsReadOnly() && enteredReadOnlyCount == 0) { | | 405 | C | CheckReadOnly(); |
| 388 | C | enteredReadOnlyCount++; | | |
| 389 | C | NotifyModifyAttempt(); | | |
| 390 | C | enteredReadOnlyCount--; | | |
| 391 | C | } | | |
| 392 | U | 406 | U | if (enteredCount != 0) { |
|
|
|
| 22 skipped lines |
|
|
| 419 | U | 433 | U | int Document::Undo() { |
|
| 420 | C | int newPos = 0; | | 434 | C | int newPos = -1; |
| | | 435 | C | CheckReadOnly(); |
| 421 | U | 436 | U | if (enteredCount == 0) { |
|
|
| | | 438 | C | if (!cb.IsReadOnly()) { |
| 423 | C | bool startSavePoint = cb.IsSavePoint(); | | 439 | C | bool startSavePoint = cb.IsSavePoint(); |
| | | 440 | C | bool multiLine = false; |
| 424 | C | int steps = cb.StartUndo(); | | 441 | C | int steps = cb.StartUndo(); |
| 425 | C | //Platform::DebugPrintf("Steps=%d\n", steps); | | 442 | C | //Platform::DebugPrintf("Steps=%d\n", steps); |
| 426 | C | for (int step = 0; step < steps; step++) { | | 443 | C | for (int step = 0; step < steps; step++) { |
| 427 | C | int prevLinesTotal = LinesTotal(); | | 444 | C | const int prevLinesTotal = LinesTotal(); |
| 428 | C | const Action &action = cb.GetUndoStep(); | | 445 | C | const Action &action = cb.GetUndoStep(); |
| 429 | C | if (action.at == removeAction) { | | 446 | C | if (action.at == removeAction) { |
| 430 | C | NotifyModified(DocModification( | | 447 | C | NotifyModified(DocModification( |
| 431 | C | SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); | | 448 | C | SC_MOD_BEFOREINSERT | SC_PERFORMED_UNDO, action)); |
| 432 | C | } else { | | 449 | C | } else { |
| 433 | C | NotifyModified(DocModification( | | 450 | C | NotifyModified(DocModification( |
| 434 | C | SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action)); | | 451 | C | SC_MOD_BEFOREDELETE | SC_PERFORMED_UNDO, action)); |
| 435 | C | } | | 452 | C | } |
| 436 | C | cb.PerformUndoStep(); | | 453 | C | cb.PerformUndoStep(); |
| 437 | C | int cellPosition = action.position / 2; | | 454 | C | int cellPosition = action.position; |
| 438 | C | ModifiedAt(cellPosition); | | 455 | C | ModifiedAt(cellPosition); |
| 439 | C | newPos = cellPosition; | | 456 | C | newPos = cellPosition; |
|
| 441 | C | int modFlags = SC_PERFORMED_UNDO; | | 458 | C | int modFlags = SC_PERFORMED_UNDO; |
| 442 | C | // With undo, an insertion action becomes a deletion notification | | 459 | C | // With undo, an insertion action becomes a deletion notification |
| 443 | C | if (action.at == removeAction) { | | 460 | C | if (action.at == removeAction) { |
| 444 | C | newPos += action.lenData; | | 461 | C | newPos += action.lenData; |
| 445 | C | modFlags |= SC_MOD_INSERTTEXT; | | 462 | C | modFlags |= SC_MOD_INSERTTEXT; |
| 446 | C | } else { | | 463 | C | } else { |
| 447 | C | modFlags |= SC_MOD_DELETETEXT; | | 464 | C | modFlags |= SC_MOD_DELETETEXT; |
| | | 465 | C | } |
| | | 466 | C | if (steps > 1) |
| | | 467 | C | modFlags |= SC_MULTISTEPUNDOREDO; |
| | | 468 | C | const int linesAdded = LinesTotal() - prevLinesTotal; |
| | | 469 | C | if (linesAdded != 0) |
| | | 470 | C | multiLine = true; |
| | | 471 | C | if (step == steps - 1) { |
| | | 472 | C | modFlags |= SC_LASTSTEPINUNDOREDO; |
| | | 473 | C | if (multiLine) |
| | | 474 | C | modFlags |= SC_MULTILINEUNDOREDO; |
| | | 475 | C | } |
| | | 476 | C | NotifyModified(DocModification(modFlags, cellPosition, action.lenData, |
| | | 477 | C | linesAdded, action.data)); |
|
| 449 | R | if (step == steps - 1) | | |
| 450 | R | modFlags |= SC_LASTSTEPINUNDOREDO; | | |
| 451 | R | NotifyModified(DocModification(modFlags, cellPosition, action.lenData, | | |
| 452 | R | LinesTotal() - prevLinesTotal, action.data)); | | |
| 453 | R | } | | |
|
| 455 | C | bool endSavePoint = cb.IsSavePoint(); | | 480 | C | bool endSavePoint = cb.IsSavePoint(); |
| 456 | C | if (startSavePoint != endSavePoint) | | 481 | C | if (startSavePoint != endSavePoint) |
| 457 | C | NotifySavePoint(endSavePoint); | | 482 | C | NotifySavePoint(endSavePoint); |
| | | 483 | C | } |
|
|
|
|
|
| 463 | U | 489 | U | int Document::Redo() { |
|
| 464 | C | int newPos = 0; | | 490 | C | int newPos = -1; |
| | | 491 | C | CheckReadOnly(); |
| 465 | U | 492 | U | if (enteredCount == 0) { |
|
|
| | | 494 | C | if (!cb.IsReadOnly()) { |
| 467 | C | bool startSavePoint = cb.IsSavePoint(); | | 495 | C | bool startSavePoint = cb.IsSavePoint(); |
| | | 496 | C | bool multiLine = false; |
| 468 | C | int steps = cb.StartRedo(); | | 497 | C | int steps = cb.StartRedo(); |
| 469 | C | for (int step = 0; step < steps; step++) { | | 498 | C | for (int step = 0; step < steps; step++) { |
| 470 | C | int prevLinesTotal = LinesTotal(); | | 499 | C | const int prevLinesTotal = LinesTotal(); |
| 471 | C | const Action &action = cb.GetRedoStep(); | | 500 | C | const Action &action = cb.GetRedoStep(); |
| 472 | C | if (action.at == insertAction) { | | 501 | C | if (action.at == insertAction) { |
| 473 | C | NotifyModified(DocModification( | | 502 | C | NotifyModified(DocModification( |
| 474 | C | SC_MOD_BEFOREINSERT | SC_PERFORMED_REDO, action)); | | 503 | C | SC_MOD_BEFOREINSERT | SC_PERFORMED_REDO, action)); |
| 475 | C | } else { | | 504 | C | } else { |
| 476 | C | NotifyModified(DocModification( | | 505 | C | NotifyModified(DocModification( |
| 477 | C | SC_MOD_BEFOREDELETE | SC_PERFORMED_REDO, action)); | | 506 | C | SC_MOD_BEFOREDELETE | SC_PERFORMED_REDO, action)); |
| 478 | C | } | | 507 | C | } |
| 479 | C | cb.PerformRedoStep(); | | 508 | C | cb.PerformRedoStep(); |
| 480 | C | ModifiedAt(action.position / 2); | | 509 | C | ModifiedAt(action.position); |
| 481 | C | newPos = action.position / 2; | | 510 | C | newPos = action.position; |
|
| 483 | C | int modFlags = SC_PERFORMED_REDO; | | 512 | C | int modFlags = SC_PERFORMED_REDO; |
| 484 | C | if (action.at == insertAction) { | | 513 | C | if (action.at == insertAction) { |
| 485 | C | newPos += action.lenData; | | 514 | C | newPos += action.lenData; |
| 486 | C | modFlags |= SC_MOD_INSERTTEXT; | | 515 | C | modFlags |= SC_MOD_INSERTTEXT; |
| 487 | C | } else { | | 516 | C | } else { |
| 488 | C | modFlags |= SC_MOD_DELETETEXT; | | 517 | C | modFlags |= SC_MOD_DELETETEXT; |
| | | 518 | C | } |
| | | 519 | C | if (steps > 1) |
| | | 520 | C | modFlags |= SC_MULTISTEPUNDOREDO; |
| | | 521 | C | const int linesAdded = LinesTotal() - prevLinesTotal; |
| | | 522 | C | if (linesAdded != 0) |
| | | 523 | C | multiLine = true; |
| | | 524 | C | if (step == steps - 1) { |
| | | 525 | C | modFlags |= SC_LASTSTEPINUNDOREDO; |
| | | 526 | C | if (multiLine) |
| | | 527 | C | modFlags |= SC_MULTILINEUNDOREDO; |
| | | 528 | C | } |
| | | 529 | C | NotifyModified( |
| | | 530 | C | DocModification(modFlags, action.position, action.lenData, |
| | | 531 | C | linesAdded, action.data)); |
|
| 490 | R | if (step == steps - 1) | | |
| 491 | R | modFlags |= SC_LASTSTEPINUNDOREDO; | | |
| 492 | R | NotifyModified( | | |
| 493 | R | DocModification(modFlags, action.position / 2, action.lenData, | | |
| 494 | R | LinesTotal() - prevLinesTotal, action.data)); | | |
| 495 | R | } | | |
|
| 497 | C | bool endSavePoint = cb.IsSavePoint(); | | 534 | C | bool endSavePoint = cb.IsSavePoint(); |
| 498 | C | if (startSavePoint != endSavePoint) | | 535 | C | if (startSavePoint != endSavePoint) |
| 499 | C | NotifySavePoint(endSavePoint); | | 536 | C | NotifySavePoint(endSavePoint); |
| | | 537 | C | } |
|
|
|
| 21 skipped lines |
|
| 525 | U | 563 | U | bool Document::InsertString(int position, const char *s, size_t insertLength) { |
|
| 526 | U | 564 | U | bool changed = false; |
|
| | | 565 | C | if (insertLength > 0) { |
| 527 | C | char *sWithStyle = new char[insertLength * 2]; | | 566 | C | char *sWithStyle = new char[insertLength * 2]; |
| 528 | C | if (sWithStyle) { | | 567 | C | if (sWithStyle) { |
| 529 | C | for (size_t i = 0; i < insertLength; i++) { | | 568 | C | for (size_t i = 0; i < insertLength; i++) { |
| 530 | C | sWithStyle[i*2] = s[i]; | | 569 | C | sWithStyle[i*2] = s[i]; |
| 531 | C | sWithStyle[i*2 + 1] = 0; | | 570 | C | sWithStyle[i*2 + 1] = 0; |
| | | 571 | C | } |
| | | 572 | C | changed = InsertStyledString(position*2, sWithStyle, |
| | | 573 | C | static_cast<int>(insertLength*2)); |
| | | 574 | C | delete []sWithStyle; |
|
| 533 | R | changed = InsertStyledString(position*2, sWithStyle, | | |
| 534 | R | static_cast<int>(insertLength*2)); | | |
| 535 | R | delete []sWithStyle; | | |
|
|
|
| 72 skipped lines |
| 611 | U | 651 | U | CreateIndentation(linebuf, sizeof(linebuf), indent, tabInChars, !useTabs); |
|
| 612 | U | 652 | U | int thisLineStart = LineStart(line); |
|
| 613 | U | 653 | U | int indentPos = GetLineIndentPosition(line); |
|
| | | 654 | A | BeginUndoAction(); |
| 614 | U | 655 | U | DeleteChars(thisLineStart, indentPos - thisLineStart); |
|
| 615 | U | 656 | U | InsertString(thisLineStart, linebuf); |
|
| | | 657 | A | EndUndoAction(); |
|
|
|
| 56 skipped lines |
| 675 | U | 717 | U | // Dedent - suck white space off the front of the line to dedent by equivalent of a tab |
|
| 676 | U | 718 | U | for (int line = lineBottom; line >= lineTop; line--) { |
|
| 677 | U | 719 | U | int indentOfLine = GetLineIndentation(line); |
|
| 678 | C | if (forwards) | | 720 | C | if (forwards) { |
| | | 721 | C | if (LineStart(line) < LineEnd(line)) { |
| 679 | C | SetLineIndentation(line, indentOfLine + IndentSize()); | | 722 | C | SetLineIndentation(line, indentOfLine + IndentSize()); |
| | | 723 | C | } |
| 680 | C | else | | 724 | C | } else { |
| 681 | U | 725 | U | SetLineIndentation(line, indentOfLine - IndentSize()); |
|
| | | 726 | A | } |
|
|
|
| 33 skipped lines |
|
| 719 | U | 764 | U | for (int pos = 0; pos < Length(); pos++) { |
|
| 720 | U | 765 | U | if (cb.CharAt(pos) == '\r') { |
|
| 721 | C | if (cb.CharAt(pos + 1) == '\n') { | | 766 | C | if (cb.CharAt(pos + 1) == '\n') { |
|
| 723 | U | 768 | U | if (eolModeSet == SC_EOL_CR) { |
|
| 724 | U | 769 | U | DeleteChars(pos + 1, 1); // Delete the LF |
|
| 2 skipped lines |
|
|
|
| 730 | C | } else { | | 775 | C | } else { |
|
| 732 | U | 777 | U | if (eolModeSet == SC_EOL_CRLF) { |
|
| 733 | U | 778 | U | InsertString(pos + 1, "\n", 1); // Insert LF |
|
| 18 skipped lines |
| 752 | U | 797 | U | EndUndoAction(); |
|
|
|
| 755 | C | int Document::ParaDown(int pos) { | | 800 | C | bool Document::IsWhiteLine(int line) { |
| 756 | C | int line = LineFromPosition(pos); | | 801 | C | int currentChar = LineStart(line); |
| 757 | C | while (line < LinesTotal() && LineStart(line) != LineEnd(line)) { // skip non-empty lines | | 802 | C | int endLine = LineEnd(line); |
| 758 | C | line++; | | |
| 759 | C | } | | |
| 760 | C | while (line < LinesTotal() && LineStart(line) == LineEnd(line)) { // skip empty lines | | 803 | C | while (currentChar < endLine) { |
| | | 804 | C | if (cb.CharAt(currentChar) != ' ' && cb.CharAt(currentChar) != '\t') { |
| | | 805 | C | return false; |
| | | 806 | C | } |
| 761 | C | line++; | | 807 | C | ++currentChar; |
|
| 763 | C | if (line < LinesTotal()) | | |
| 764 | C | return LineStart(line); | | |
| 765 | C | else // end of a document | | |
| 766 | C | return LineEnd(line-1); | | 809 | C | return true; |
|
|
| 769 | U | 812 | U | int Document::ParaUp(int pos) { |
|
| 770 | U | 813 | U | int line = LineFromPosition(pos); |
|
|
| 772 | C | while (line >= 0 && LineStart(line) == LineEnd(line)) { // skip empty lines | | 815 | C | while (line >= 0 && IsWhiteLine(line)) { // skip empty lines |
|
|
| 775 | C | while (line >= 0 && LineStart(line) != LineEnd(line)) { // skip non-empty lines | | 818 | C | while (line >= 0 && !IsWhiteLine(line)) { // skip non-empty lines |
|
|
|
| 779 | U | 822 | U | return LineStart(line); |
|
|
|
| | | 825 | A | int Document::ParaDown(int pos) { |
| | | 826 | A | int line = LineFromPosition(pos); |
| | | 827 | A | while (line < LinesTotal() && !IsWhiteLine(line)) { // skip non-empty lines |
| | | 828 | A | line++; |
| | | 829 | A | } |
| 4 skipped lines |
| | | 834 | A | return LineStart(line); |
| | | 835 | A | else // end of a document |
| | | 836 | A | return LineEnd(line-1); |
| | | 837 | A | } |
| | | 838 | A | |
| 782 | U | 839 | U | Document::charClassification Document::WordCharClass(unsigned char ch) { |
|
| 783 | U | 840 | U | if ((SC_CP_UTF8 == dbcsCodePage) && (ch >= 0x80)) |
|
|
| 141 skipped lines |
| 926 | U | 983 | U | pdoc(pdoc_), end(end_) { |
|
|
|
| | | 986 | A | virtual ~DocumentIndexer() { |
| | | 987 | A | } |
| | | 988 | A | |
| 929 | U | 989 | U | virtual char CharAt(int index) { |
|
| 930 | U | 990 | U | if (index < 0 || index >= end) |
|
|
| 69 skipped lines |
| 1001 | U | 1061 | U | if (line == lineRangeStart) { |
|
| 1002 | U | 1062 | U | if ((startPos != endOfLine) && (searchEnd == '$')) |
|
| 1003 | U | 1063 | U | continue; // Can't match end of line if start position before end of line |
|
| 1004 | C | endOfLine = startPos+1; | | 1064 | C | endOfLine = startPos; |