TextMate is a graphical text editor for OS X 10.7+
Revision | 1477288795fd9d0cf5f7afcad162ed2118cd1567 (tree) |
---|---|
Zeit | 2012-08-19 04:52:08 |
Autor | Allan Odgaard <git@abet...> |
Commiter | Allan Odgaard |
Redefine definition of paragraph
When we need to work on a paragraph (reflow, unwrap, select, etc.) we now extend upward until we see a blank line, and likewise move downward until there is a blank line.
This is related to issue #154.
@@ -379,7 +379,7 @@ namespace ng | ||
379 | 379 | case kSelectionMoveToBeginOfDocument: return 0; |
380 | 380 | case kSelectionMoveToEndOfDocument: return buffer.size(); |
381 | 381 | case kSelectionMoveToBeginOfParagraph: return buffer.begin(line); |
382 | - case kSelectionMoveToEndOfParagraph: return buffer.eol(line); // TODO Better definition of kSelectionMoveToEndOfParagraph. | |
382 | + case kSelectionMoveToEndOfParagraph: return buffer.eol(line); | |
383 | 383 | case kSelectionMoveToBeginOfLine: return buffer.begin(line); |
384 | 384 | case kSelectionMoveToEndOfLine: return buffer.eol(line); |
385 | 385 | case kSelectionMoveToBeginOfSoftLine: return layout ? layout->index_at_bol_for(caret) : buffer.begin(line); |
@@ -393,6 +393,33 @@ namespace ng | ||
393 | 393 | case kSelectionMovePageUp: return layout ? layout->page_up_for(index) : index; |
394 | 394 | case kSelectionMovePageDown: return layout ? layout->page_down_for(index) : index; |
395 | 395 | |
396 | + case kSelectionMoveToBeginOfHardParagraph: | |
397 | + { | |
398 | + if(line == 0) | |
399 | + return 0; | |
400 | + | |
401 | + for(size_t n = line-1; n > 0; --n) | |
402 | + { | |
403 | + std::string const& line = buffer.substr(buffer.begin(n), buffer.end(n)); | |
404 | + if(text::is_blank(line.data(), line.data() + line.size())) | |
405 | + return buffer.begin(n+1); | |
406 | + } | |
407 | + return 0; | |
408 | + } | |
409 | + break; | |
410 | + | |
411 | + case kSelectionMoveToEndOfHardParagraph: | |
412 | + { | |
413 | + for(size_t n = line+1; n < buffer.lines(); ++n) | |
414 | + { | |
415 | + std::string const& line = buffer.substr(buffer.begin(n), buffer.end(n)); | |
416 | + if(text::is_blank(line.data(), line.data() + line.size())) | |
417 | + return buffer.begin(n); | |
418 | + } | |
419 | + return buffer.size(); | |
420 | + } | |
421 | + break; | |
422 | + | |
396 | 423 | case kSelectionMoveFreehandedLeft: |
397 | 424 | { |
398 | 425 | if(index.carry != 0) |
@@ -692,7 +719,7 @@ namespace ng | ||
692 | 719 | case kSelectionExtendToSoftLine: return range_t(move(buffer, min, kSelectionMoveToBeginOfSoftLine, layout), min.index != max.index && max.index == move(buffer, max, kSelectionMoveToBeginOfSoftLine, layout).index ? max : move(buffer, move(buffer, max, kSelectionMoveToEndOfSoftLine, layout), kSelectionMoveRight, layout), false, false, true); |
693 | 720 | case kSelectionExtendToLine: return range_t(move(buffer, min, kSelectionMoveToBeginOfLine, layout), min.index != max.index && buffer.convert(max.index).column == 0 ? max : move(buffer, move(buffer, max, kSelectionMoveToEndOfLine, layout), kSelectionMoveRight, layout), false, false, true); |
694 | 721 | case kSelectionExtendToLineExclLF: return range_t(move(buffer, min, kSelectionMoveToBeginOfLine, layout), min.index != max.index && buffer.convert(max.index).column == 0 ? max : move(buffer, max, kSelectionMoveToEndOfLine, layout), false, false, true); |
695 | - case kSelectionExtendToParagraph: return range_t(move(buffer, min, kSelectionMoveToBeginOfParagraph, layout), move(buffer, max, kSelectionMoveToEndOfParagraph, layout), false, false, true); | |
722 | + case kSelectionExtendToParagraph: return range_t(move(buffer, min, kSelectionMoveToBeginOfHardParagraph, layout), move(buffer, max, kSelectionMoveToEndOfHardParagraph, layout), false, false, true); | |
696 | 723 | case kSelectionExtendToAll: return range_t(move(buffer, min, kSelectionMoveToBeginOfDocument, layout), move(buffer, max, kSelectionMoveToEndOfDocument, layout), false, false, true); |
697 | 724 | |
698 | 725 | case kSelectionExtendToWord: |
@@ -6,7 +6,7 @@ | ||
6 | 6 | #include <text/types.h> |
7 | 7 | #include <oak/misc.h> |
8 | 8 | |
9 | -enum move_unit_type { kSelectionMoveLeft, kSelectionMoveRight, kSelectionMoveFreehandedLeft, kSelectionMoveFreehandedRight, kSelectionMoveUp, kSelectionMoveDown, kSelectionMoveToBeginOfSelection, kSelectionMoveToEndOfSelection, kSelectionMoveToBeginOfSubWord, kSelectionMoveToEndOfSubWord, kSelectionMoveToBeginOfWord, kSelectionMoveToEndOfWord, kSelectionMoveToBeginOfSoftLine, kSelectionMoveToEndOfSoftLine, kSelectionMoveToBeginOfLine, kSelectionMoveToEndOfLine, kSelectionMoveToBeginOfParagraph, kSelectionMoveToEndOfParagraph, kSelectionMoveToBeginOfTypingPair, kSelectionMoveToEndOfTypingPair, kSelectionMoveToBeginOfColumn, kSelectionMoveToEndOfColumn, kSelectionMovePageUp, kSelectionMovePageDown, kSelectionMoveToBeginOfDocument, kSelectionMoveToEndOfDocument, kSelectionMoveNowhere }; | |
9 | +enum move_unit_type { kSelectionMoveLeft, kSelectionMoveRight, kSelectionMoveFreehandedLeft, kSelectionMoveFreehandedRight, kSelectionMoveUp, kSelectionMoveDown, kSelectionMoveToBeginOfSelection, kSelectionMoveToEndOfSelection, kSelectionMoveToBeginOfSubWord, kSelectionMoveToEndOfSubWord, kSelectionMoveToBeginOfWord, kSelectionMoveToEndOfWord, kSelectionMoveToBeginOfSoftLine, kSelectionMoveToEndOfSoftLine, kSelectionMoveToBeginOfLine, kSelectionMoveToEndOfLine, kSelectionMoveToBeginOfParagraph, kSelectionMoveToEndOfParagraph, kSelectionMoveToBeginOfHardParagraph, kSelectionMoveToEndOfHardParagraph, kSelectionMoveToBeginOfTypingPair, kSelectionMoveToEndOfTypingPair, kSelectionMoveToBeginOfColumn, kSelectionMoveToEndOfColumn, kSelectionMovePageUp, kSelectionMovePageDown, kSelectionMoveToBeginOfDocument, kSelectionMoveToEndOfDocument, kSelectionMoveNowhere }; | |
10 | 10 | enum select_unit_type { kSelectionExtendLeft, kSelectionExtendRight, kSelectionExtendFreehandedLeft, kSelectionExtendFreehandedRight, kSelectionExtendUp, kSelectionExtendDown, kSelectionExtendToBeginOfSubWord, kSelectionExtendToEndOfSubWord, kSelectionExtendToBeginOfWord, kSelectionExtendToEndOfWord, kSelectionExtendToBeginOfSoftLine, kSelectionExtendToEndOfSoftLine, kSelectionExtendToBeginOfLine, kSelectionExtendToEndOfLine, kSelectionExtendToBeginOfParagraph, kSelectionExtendToEndOfParagraph, kSelectionExtendToBeginOfTypingPair, kSelectionExtendToEndOfTypingPair, kSelectionExtendToBeginOfColumn, kSelectionExtendToEndOfColumn, kSelectionExtendPageUp, kSelectionExtendPageDown, kSelectionExtendToBeginOfDocument, kSelectionExtendToEndOfDocument, kSelectionExtendToWord, kSelectionExtendToScope, kSelectionExtendToSoftLine, kSelectionExtendToLineExclLF, kSelectionExtendToLine, kSelectionExtendToParagraph, kSelectionExtendToTypingPair, kSelectionExtendToAll }; |
11 | 11 | |
12 | 12 | namespace scope { struct context_t; struct selector_t; } |