Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 DeleteFromTextNodeCommand::create(node, offset, count), | 637 DeleteFromTextNodeCommand::create(node, offset, count), |
| 638 ASSERT_NO_EDITING_ABORT); | 638 ASSERT_NO_EDITING_ABORT); |
| 639 } | 639 } |
| 640 | 640 |
| 641 void CompositeEditCommand::replaceTextInNode(Text* node, | 641 void CompositeEditCommand::replaceTextInNode(Text* node, |
| 642 unsigned offset, | 642 unsigned offset, |
| 643 unsigned count, | 643 unsigned count, |
| 644 const String& replacementText) { | 644 const String& replacementText) { |
| 645 // DeleteFromTextNodeCommand and InsertIntoTextNodeCommand are never | 645 // DeleteFromTextNodeCommand and InsertIntoTextNodeCommand are never |
| 646 // aborted. | 646 // aborted. |
| 647 applyCommandToComposite( | 647 |
| 648 DeleteFromTextNodeCommand::create(node, offset, count), | 648 // Insert must happen before delete to preserve markers correctly |
|
rlanday
2017/01/03 21:07:03
This is something that came up when I added a test
| |
| 649 ASSERT_NO_EDITING_ABORT); | 649 // See algorithm in https://dom.spec.whatwg.org/#concept-cd-replace |
| 650 if (!replacementText.isEmpty()) | 650 if (!replacementText.isEmpty()) |
| 651 applyCommandToComposite( | 651 applyCommandToComposite( |
| 652 InsertIntoTextNodeCommand::create(node, offset, replacementText), | 652 InsertIntoTextNodeCommand::create(node, offset, replacementText), |
| 653 ASSERT_NO_EDITING_ABORT); | 653 ASSERT_NO_EDITING_ABORT); |
| 654 applyCommandToComposite(DeleteFromTextNodeCommand::create( | |
| 655 node, offset + replacementText.length(), count), | |
| 656 ASSERT_NO_EDITING_ABORT); | |
| 654 } | 657 } |
| 655 | 658 |
| 656 Position CompositeEditCommand::replaceSelectedTextInNode(const String& text) { | 659 Position CompositeEditCommand::replaceSelectedTextInNode(const String& text) { |
| 657 Position start = endingSelection().start(); | 660 Position start = endingSelection().start(); |
| 658 Position end = endingSelection().end(); | 661 Position end = endingSelection().end(); |
| 659 if (start.computeContainerNode() != end.computeContainerNode() || | 662 if (start.computeContainerNode() != end.computeContainerNode() || |
| 660 !start.computeContainerNode()->isTextNode() || | 663 !start.computeContainerNode()->isTextNode() || |
| 661 isTabHTMLSpanElementTextNode(start.computeContainerNode())) | 664 isTabHTMLSpanElementTextNode(start.computeContainerNode())) |
| 662 return Position(); | 665 return Position(); |
| 663 | 666 |
| (...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2047 return node; | 2050 return node; |
| 2048 } | 2051 } |
| 2049 | 2052 |
| 2050 DEFINE_TRACE(CompositeEditCommand) { | 2053 DEFINE_TRACE(CompositeEditCommand) { |
| 2051 visitor->trace(m_commands); | 2054 visitor->trace(m_commands); |
| 2052 visitor->trace(m_composition); | 2055 visitor->trace(m_composition); |
| 2053 EditCommand::trace(visitor); | 2056 EditCommand::trace(visitor); |
| 2054 } | 2057 } |
| 2055 | 2058 |
| 2056 } // namespace blink | 2059 } // namespace blink |
| OLD | NEW |