Changeset 192641 in webkit
- Timestamp:
- Nov 19, 2015 11:29:59 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r192639 r192641 1 2015-11-19 Brian Burg <bburg@apple.com> 2 3 REGRESSION(r8780): Backwards delete by word incorrectly appends deleted text to kill ring, should be prepend 4 https://bugs.webkit.org/show_bug.cgi?id=151300 5 6 Reviewed by Darin Adler. 7 8 * editing/pasteboard/emacs-killring-alternating-append-prepend-expected.txt: Added. 9 * editing/pasteboard/emacs-killring-alternating-append-prepend.html: Added. 10 * editing/pasteboard/emacs-killring-backward-delete-prepend-expected.txt: Added. 11 * editing/pasteboard/emacs-killring-backward-delete-prepend.html: Added. 12 1 13 2015-11-19 Myles C. Maxfield <mmaxfield@apple.com> 2 14 -
trunk/Source/WebCore/ChangeLog
r192639 r192641 1 2015-11-19 Brian Burg <bburg@apple.com> 2 3 REGRESSION(r8780): Backwards delete by word incorrectly appends deleted text to kill ring, should be prepend 4 https://bugs.webkit.org/show_bug.cgi?id=151300 5 6 Reviewed by Darin Adler. 7 8 Over 11 years ago, someone was in a big hurry to fix a bunch 9 of emacs keybindings bugs, and accidentally regressed the kill ring 10 behavior for backwards-delete-word. It should prepend to the beginning. 11 12 This patch fixes the regression and cleans up the kill ring-related 13 code in Editor and commands. It also adds some tests to cover the 14 regressed code a bit better. 15 16 Tests: editing/pasteboard/emacs-killring-alternating-append-prepend.html 17 editing/pasteboard/emacs-killring-backward-delete-prepend.html 18 19 * editing/Editor.cpp: 20 21 Use more explicit names for insertion mode parameters and member variables. 22 23 (WebCore::Editor::deleteWithDirection): 24 (WebCore::Editor::performDelete): 25 (WebCore::Editor::addRangeToKillRing): 26 (WebCore::Editor::addTextToKillRing): 27 28 Only one call site for now, but another will be added in a dependent fix. 29 30 (WebCore::Editor::addToKillRing): Deleted. 31 * editing/Editor.h: 32 * editing/TypingCommand.cpp: 33 (WebCore::TypingCommand::TypingCommand): 34 (WebCore::TypingCommand::deleteKeyPressed): 35 (WebCore::TypingCommand::forwardDeleteKeyPressed): 36 (WebCore::TypingCommand::doApply): 37 * editing/TypingCommand.h: 38 * platform/mac/KillRingMac.mm: 39 (WebCore::KillRing::append): 40 (WebCore::KillRing::prepend): 41 42 It turns out that the native API implicitly clears the kill sequence when 43 alternating between prepend and append operations. Its behavior does not match 44 what Sublime Text or Emacs do in this case. Clear the previous operation flag 45 to prevent this behavior from happening. 46 1 47 2015-11-19 Myles C. Maxfield <mmaxfield@apple.com> 2 48 -
trunk/Source/WebCore/editing/Editor.cpp
r192354 r192641 331 331 } 332 332 333 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity granularity, bool killRing, bool isTypingAction)333 bool Editor::deleteWithDirection(SelectionDirection direction, TextGranularity granularity, bool shouldAddToKillRing, bool isTypingAction) 334 334 { 335 335 if (!canEdit()) … … 341 341 revealSelectionAfterEditingOperation(); 342 342 } else { 343 if ( killRing)344 add ToKillRing(selectedRange().get(), false);343 if (shouldAddToKillRing) 344 addRangeToKillRing(*selectedRange().get(), KillRingInsertionMode::AppendText); 345 345 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); 346 346 // Implicitly calls revealSelectionAfterEditingOperation(). … … 350 350 if (canSmartCopyOrDelete()) 351 351 options |= TypingCommand::SmartDelete; 352 if ( killRing)353 options |= TypingCommand:: KillRing;352 if (shouldAddToKillRing) 353 options |= TypingCommand::AddsToKillRing; 354 354 switch (direction) { 355 355 case DirectionForward: … … 368 368 // clear the "start new kill ring sequence" setting, because it was set to true 369 369 // when the selection was updated by deleting the range 370 if ( killRing)370 if (shouldAddToKillRing) 371 371 setStartNewKillRingSequence(false); 372 372 … … 1096 1096 : m_frame(frame) 1097 1097 , m_ignoreCompositionSelectionChange(false) 1098 , m_shouldStartNewKillRingSequence(false)1099 1098 // This is off by default, since most editors want this behavior (this matches IE but not FF). 1100 1099 , m_shouldStyleWithCSS(false) … … 1335 1334 } 1336 1335 1337 add ToKillRing(selectedRange().get(), false);1336 addRangeToKillRing(*selectedRange().get(), KillRingInsertionMode::AppendText); 1338 1337 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); 1339 1338 … … 2848 2847 } 2849 2848 2850 void Editor::addToKillRing(Range* range, bool prepend) 2849 void Editor::addRangeToKillRing(const Range& range, KillRingInsertionMode mode) 2850 { 2851 addTextToKillRing(plainText(&range), mode); 2852 } 2853 2854 void Editor::addTextToKillRing(const String& text, KillRingInsertionMode mode) 2851 2855 { 2852 2856 if (m_shouldStartNewKillRingSequence) 2853 2857 killRing().startNewSequence(); 2854 2858 2855 String text = plainText(range); 2856 if (prepend) 2859 m_shouldStartNewKillRingSequence = false; 2860 2861 // If the kill was from a backwards motion, prepend to the kill ring. 2862 // This will ensure that alternating forward and backward kills will 2863 // build up the original string in the kill ring without permuting it. 2864 switch (mode) { 2865 case KillRingInsertionMode::PrependText: 2857 2866 killRing().prepend(text); 2858 else 2867 break; 2868 case KillRingInsertionMode::AppendText: 2859 2869 killRing().append(text); 2860 m_shouldStartNewKillRingSequence = false; 2870 break; 2871 } 2861 2872 } 2862 2873 -
trunk/Source/WebCore/editing/Editor.h
r191671 r192641 316 316 bool ignoreCompositionSelectionChange() const { return m_ignoreCompositionSelectionChange; } 317 317 318 void setStartNewKillRingSequence(bool);319 320 318 WEBCORE_EXPORT PassRefPtr<Range> rangeForPoint(const IntPoint& windowPoint); 321 319 … … 339 337 #endif 340 338 341 void addToKillRing(Range*, bool prepend); 339 enum class KillRingInsertionMode { PrependText, AppendText }; 340 void addRangeToKillRing(const Range&, KillRingInsertionMode); 341 void addTextToKillRing(const String&, KillRingInsertionMode); 342 void setStartNewKillRingSequence(bool); 342 343 343 344 void startAlternativeTextUITimer(); … … 502 503 Vector<CompositionUnderline> m_customCompositionUnderlines; 503 504 bool m_ignoreCompositionSelectionChange; 504 bool m_shouldStartNewKillRingSequence ;505 bool m_shouldStartNewKillRingSequence {false}; 505 506 bool m_shouldStyleWithCSS; 506 507 const std::unique_ptr<KillRing> m_killRing; -
trunk/Source/WebCore/editing/TypingCommand.cpp
r183368 r192641 84 84 , m_granularity(granularity) 85 85 , m_compositionType(compositionType) 86 , m_ killRing(options &KillRing)86 , m_shouldAddToKillRing(options & AddsToKillRing) 87 87 , m_openedByBackwardDelete(false) 88 88 , m_shouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator) … … 115 115 updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), document.frame()); 116 116 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking); 117 lastTypingCommand->deleteKeyPressed(granularity, options & KillRing);117 lastTypingCommand->deleteKeyPressed(granularity, options & AddsToKillRing); 118 118 return; 119 119 } … … 131 131 updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand.get(), frame); 132 132 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking); 133 lastTypingCommand->forwardDeleteKeyPressed(granularity, options & KillRing);133 lastTypingCommand->forwardDeleteKeyPressed(granularity, options & AddsToKillRing); 134 134 return; 135 135 } … … 264 264 return; 265 265 case DeleteKey: 266 deleteKeyPressed(m_granularity, m_ killRing);266 deleteKeyPressed(m_granularity, m_shouldAddToKillRing); 267 267 return; 268 268 case ForwardDeleteKey: 269 forwardDeleteKeyPressed(m_granularity, m_ killRing);269 forwardDeleteKeyPressed(m_granularity, m_shouldAddToKillRing); 270 270 return; 271 271 case InsertLineBreak: … … 434 434 } 435 435 436 void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool killRing)436 void TypingCommand::deleteKeyPressed(TextGranularity granularity, bool shouldAddToKillRing) 437 437 { 438 438 Frame& frame = this->frame(); … … 459 459 selection.setSelection(endingSelection()); 460 460 selection.modify(FrameSelection::AlterationExtend, DirectionBackward, granularity); 461 if ( killRing && selection.isCaret() && granularity != CharacterGranularity)461 if (shouldAddToKillRing && selection.isCaret() && granularity != CharacterGranularity) 462 462 selection.modify(FrameSelection::AlterationExtend, DirectionBackward, CharacterGranularity); 463 463 … … 531 531 return; 532 532 533 if ( killRing)534 frame.editor().add ToKillRing(selectionToDelete.toNormalizedRange().get(), false);533 if (shouldAddToKillRing) 534 frame.editor().addRangeToKillRing(*selectionToDelete.toNormalizedRange().get(), Editor::KillRingInsertionMode::PrependText); 535 535 // Make undo select everything that has been deleted, unless an undo will undo more than just this deletion. 536 536 // FIXME: This behaves like TextEdit except for the case where you open with text insertion and then delete … … 543 543 } 544 544 545 void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool killRing)545 void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool shouldAddToKillRing) 546 546 { 547 547 Frame& frame = this->frame(); … … 566 566 selection.setSelection(endingSelection()); 567 567 selection.modify(FrameSelection::AlterationExtend, DirectionForward, granularity); 568 if ( killRing && selection.isCaret() && granularity != CharacterGranularity)568 if (shouldAddToKillRing && selection.isCaret() && granularity != CharacterGranularity) 569 569 selection.modify(FrameSelection::AlterationExtend, DirectionForward, CharacterGranularity); 570 570 … … 629 629 return; 630 630 631 if ( killRing)632 frame.editor().add ToKillRing(selectionToDelete.toNormalizedRange().get(), false);631 if (shouldAddToKillRing) 632 frame.editor().addRangeToKillRing(*selectionToDelete.toNormalizedRange().get(), Editor::KillRingInsertionMode::AppendText); 633 633 // make undo select what was deleted 634 634 setStartingSelection(selectionAfterUndo); -
trunk/Source/WebCore/editing/TypingCommand.h
r177733 r192641 51 51 enum Option { 52 52 SelectInsertedText = 1 << 0, 53 KillRing = 1 << 1,53 AddsToKillRing = 1 << 1, 54 54 RetainAutocorrectionIndicator = 1 << 2, 55 55 PreventSpellChecking = 1 << 3, … … 76 76 void insertParagraphSeparatorInQuotedContent(); 77 77 void insertParagraphSeparator(); 78 void deleteKeyPressed(TextGranularity, bool killRing);79 void forwardDeleteKeyPressed(TextGranularity, bool killRing);78 void deleteKeyPressed(TextGranularity, bool shouldAddToKillRing); 79 void forwardDeleteKeyPressed(TextGranularity, bool shouldAddToKillRing); 80 80 void deleteSelection(bool smartDelete); 81 81 void setCompositionType(TextCompositionType type) { m_compositionType = type; } … … 132 132 TextGranularity m_granularity; 133 133 TextCompositionType m_compositionType; 134 bool m_ killRing;134 bool m_shouldAddToKillRing; 135 135 bool m_preservesTypingStyle; 136 136 -
trunk/Source/WebCore/platform/mac/KillRingMac.mm
r161589 r192641 39 39 void _NSNewKillRingSequence(); 40 40 void _NSSetKillRingToYankedState(); 41 void _NSResetKillRingOperationFlag(); 41 42 42 43 } … … 54 55 { 55 56 initializeKillRingIfNeeded(); 57 // Necessary to prevent an implicit new sequence if the previous command was NSPrependToKillRing. 58 _NSResetKillRingOperationFlag(); 56 59 _NSAppendToKillRing(string); 57 60 } … … 60 63 { 61 64 initializeKillRingIfNeeded(); 65 // Necessary to prevent an implicit new sequence if the previous command was NSAppendToKillRing. 66 _NSResetKillRingOperationFlag(); 62 67 _NSPrependToKillRing(string); 63 68 }
Note: See TracChangeset
for help on using the changeset viewer.