| Summary: | [iOS] range.toString() ignores newlines | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Morgan Redding <morganfredding> |
| Component: | HTML Editing | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW --- | ||
| Severity: | Normal | CC: | karlcow, megan_gardner, rniwa, webkit-bug-importer, wenson_hsieh |
| Priority: | P2 | Keywords: | BrowserCompat, GoodFirstBug, InRadar |
| Version: | Other | ||
| Hardware: | iPhone / iPad | ||
| OS: | iOS 17 | ||
|
Description
Morgan Redding
2023-10-17 22:03:08 PDT
Probably something like this should work (I cannot seem to run the tests on my machine):
1) add `#include "../editing/TextIterator.h"` to "Source/WebCore/dom/Range.cpp"
2) change "Range::toString() const" to
```
String Range::toString() const
{
auto range = makeSimpleRange(*this);
return plainText(range, options);
}
```
For your convenience, here is the output of `git diff`:
```
diff --git a/Source/WebCore/dom/Range.cpp b/Source/WebCore/dom/Range.cpp
index 5ea2924c3ad3..890888b9022b 100644
--- a/Source/WebCore/dom/Range.cpp
+++ b/Source/WebCore/dom/Range.cpp
@@ -25,6 +25,7 @@
#include "config.h"
#include "Range.h"
+#include "../editing/TextIterator.h"
#include "Comment.h"
#include "CustomElementReactionQueue.h"
#include "DOMRect.h"
@@ -720,14 +721,7 @@ ExceptionOr<void> Range::insertNode(Ref<Node>&& node)
String Range::toString() const
{
auto range = makeSimpleRange(*this);
- StringBuilder builder;
- for (auto& node : intersectingNodes(range)) {
- if (is<Text>(node)) {
- auto offsetRange = characterDataOffsetRange(range, node);
- builder.appendSubstring(downcast<Text>(node).data(), offsetRange.start, offsetRange.end - offsetRange.start);
- }
- }
- return builder.toString();
+ return plainText(range, options);
}
```
Oops, forgot to add ``` OptionSet<TextIteratorBehavior> options; ``` in the diff Morgan, do you intend to send a PR? Or would you like someone else to do it? Oh, sorry for the ambiguity. I’ve never submitted a PR for WebKit and can’t seem to get the tests running so I’d really appreciate if someone else could submit a PR! |