Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Unified Diff: third_party/WebKit/Source/core/editing/Editor.cpp

Issue 2618613004: Insert a line break when space is inserted at the top of wrapped lines (Closed)
Patch Set: Fix test on Mac Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
}

Powered by Google App Engine
This is Rietveld 408576698