Index: third_party/WebKit/Source/core/editing/Editor.cpp |
diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp |
index 79d38cb36fe377f0d516a531a5b4fb95d4f2a6f6..66ef6becc75e74660ceb48fa3497963f00e30c4b 100644 |
--- a/third_party/WebKit/Source/core/editing/Editor.cpp |
+++ b/third_party/WebKit/Source/core/editing/Editor.cpp |
@@ -201,6 +201,16 @@ EditorClient& Editor::client() const { |
return emptyEditorClient(); |
} |
+static bool isCaretAtStartOfWrappedLine(const FrameSelection& selection) { |
+ if (!selection.isCaret()) |
+ return false; |
+ if (selection.affinity() != TextAffinity::Downstream) |
+ return false; |
+ const Position& position = selection.start(); |
+ return !inSameLine(PositionWithAffinity(position, TextAffinity::Upstream), |
+ PositionWithAffinity(position, TextAffinity::Downstream)); |
+} |
+ |
bool Editor::handleTextEvent(TextEvent* event) { |
// Default event handling for Drag and Drop will be handled by DragController |
// so we leave the event for it. |
@@ -237,6 +247,17 @@ bool Editor::handleTextEvent(TextEvent* event) { |
return insertParagraphSeparator(); |
} |
+ // Typing spaces at the beginning of wrapped line is confusing, because |
+ // inserted spaces would appear in the previous line. |
+ // Insert a line break automatically so that the spaces appear at the caret. |
+ // TODO(kojii): rich editing has the same issue, but has more options and |
+ // needs coordination with JS. Enable for plaintext only for now and collect |
+ // feedback. |
+ if (data == " " && !canEditRichly() && |
+ isCaretAtStartOfWrappedLine(frame().selection())) { |
+ insertLineBreak(); |
+ } |
+ |
return insertTextWithoutSendingTextEvent(EditCommandSource::kMenuOrKeyBinding, |
data, false, event); |
} |